@@ -68,42 +68,23 @@ static void append_ceiling_dir(git_buf *ceiling_dirs, const char *path)
6868 cl_assert (git_buf_oom (ceiling_dirs ) == 0 );
6969}
7070
71- void test_repo_discover__0 (void )
71+ void test_repo_discover__initialize (void )
7272{
73- // test discover
7473 git_repository * repo ;
75- git_buf ceiling_dirs_buf = GIT_BUF_INIT , repository_path = GIT_BUF_INIT ,
76- sub_repository_path = GIT_BUF_INIT , found_path = GIT_BUF_INIT ;
77- const char * ceiling_dirs ;
7874 const mode_t mode = 0777 ;
79-
8075 git_futils_mkdir_r (DISCOVER_FOLDER , mode );
81- append_ceiling_dir (& ceiling_dirs_buf , TEMP_REPO_FOLDER );
82- ceiling_dirs = git_buf_cstr (& ceiling_dirs_buf );
83-
84- cl_assert_equal_i (GIT_ENOTFOUND , git_repository_discover (& repository_path , DISCOVER_FOLDER , 0 , ceiling_dirs ));
8576
8677 cl_git_pass (git_repository_init (& repo , DISCOVER_FOLDER , 1 ));
87- cl_git_pass (git_repository_discover (& repository_path , DISCOVER_FOLDER , 0 , ceiling_dirs ));
8878 git_repository_free (repo );
8979
9080 cl_git_pass (git_repository_init (& repo , SUB_REPOSITORY_FOLDER , 0 ));
9181 cl_git_pass (git_futils_mkdir_r (SUB_REPOSITORY_FOLDER_SUB_SUB_SUB , mode ));
92- cl_git_pass (git_repository_discover (& sub_repository_path , SUB_REPOSITORY_FOLDER , 0 , ceiling_dirs ));
93-
9482 cl_git_pass (git_futils_mkdir_r (SUB_REPOSITORY_FOLDER_SUB_SUB_SUB , mode ));
95- ensure_repository_discover (SUB_REPOSITORY_FOLDER_SUB , ceiling_dirs , & sub_repository_path );
96- ensure_repository_discover (SUB_REPOSITORY_FOLDER_SUB_SUB , ceiling_dirs , & sub_repository_path );
97- ensure_repository_discover (SUB_REPOSITORY_FOLDER_SUB_SUB_SUB , ceiling_dirs , & sub_repository_path );
9883
9984 cl_git_pass (git_futils_mkdir_r (REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB , mode ));
10085 write_file (REPOSITORY_ALTERNATE_FOLDER "/" DOT_GIT , "gitdir: ../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT );
10186 write_file (REPOSITORY_ALTERNATE_FOLDER_SUB_SUB "/" DOT_GIT , "gitdir: ../../../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT );
10287 write_file (REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB "/" DOT_GIT , "gitdir: ../../../../" );
103- ensure_repository_discover (REPOSITORY_ALTERNATE_FOLDER , ceiling_dirs , & sub_repository_path );
104- ensure_repository_discover (REPOSITORY_ALTERNATE_FOLDER_SUB , ceiling_dirs , & sub_repository_path );
105- ensure_repository_discover (REPOSITORY_ALTERNATE_FOLDER_SUB_SUB , ceiling_dirs , & sub_repository_path );
106- ensure_repository_discover (REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB , ceiling_dirs , & repository_path );
10788
10889 cl_git_pass (git_futils_mkdir_r (ALTERNATE_MALFORMED_FOLDER1 , mode ));
10990 write_file (ALTERNATE_MALFORMED_FOLDER1 "/" DOT_GIT , "Anything but not gitdir:" );
@@ -113,6 +94,40 @@ void test_repo_discover__0(void)
11394 write_file (ALTERNATE_MALFORMED_FOLDER3 "/" DOT_GIT , "gitdir: \n\n\n" );
11495 cl_git_pass (git_futils_mkdir_r (ALTERNATE_NOT_FOUND_FOLDER , mode ));
11596 write_file (ALTERNATE_NOT_FOUND_FOLDER "/" DOT_GIT , "gitdir: a_repository_that_surely_does_not_exist" );
97+
98+ git_repository_free (repo );
99+ }
100+
101+ void test_repo_discover__cleanup (void )
102+ {
103+ cl_git_pass (git_futils_rmdir_r (TEMP_REPO_FOLDER , NULL , GIT_RMDIR_REMOVE_FILES ));
104+ }
105+
106+ void test_repo_discover__0 (void )
107+ {
108+ // test discover
109+ git_buf ceiling_dirs_buf = GIT_BUF_INIT , repository_path = GIT_BUF_INIT ,
110+ sub_repository_path = GIT_BUF_INIT , found_path = GIT_BUF_INIT ;
111+ const char * ceiling_dirs ;
112+
113+ append_ceiling_dir (& ceiling_dirs_buf , TEMP_REPO_FOLDER );
114+ ceiling_dirs = git_buf_cstr (& ceiling_dirs_buf );
115+
116+ /* Nonexistent */
117+ cl_assert_equal_i (GIT_ENOTFOUND , git_repository_discover (& repository_path , DISCOVER_FOLDER "-nonexistent" , 0 , ceiling_dirs ));
118+
119+ cl_git_pass (git_repository_discover (& repository_path , DISCOVER_FOLDER , 0 , ceiling_dirs ));
120+ cl_git_pass (git_repository_discover (& sub_repository_path , SUB_REPOSITORY_FOLDER , 0 , ceiling_dirs ));
121+
122+ ensure_repository_discover (SUB_REPOSITORY_FOLDER_SUB , ceiling_dirs , & sub_repository_path );
123+ ensure_repository_discover (SUB_REPOSITORY_FOLDER_SUB_SUB , ceiling_dirs , & sub_repository_path );
124+ ensure_repository_discover (SUB_REPOSITORY_FOLDER_SUB_SUB_SUB , ceiling_dirs , & sub_repository_path );
125+
126+ ensure_repository_discover (REPOSITORY_ALTERNATE_FOLDER , ceiling_dirs , & sub_repository_path );
127+ ensure_repository_discover (REPOSITORY_ALTERNATE_FOLDER_SUB , ceiling_dirs , & sub_repository_path );
128+ ensure_repository_discover (REPOSITORY_ALTERNATE_FOLDER_SUB_SUB , ceiling_dirs , & sub_repository_path );
129+ ensure_repository_discover (REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB , ceiling_dirs , & repository_path );
130+
116131 cl_git_fail (git_repository_discover (& found_path , ALTERNATE_MALFORMED_FOLDER1 , 0 , ceiling_dirs ));
117132 cl_git_fail (git_repository_discover (& found_path , ALTERNATE_MALFORMED_FOLDER2 , 0 , ceiling_dirs ));
118133 cl_git_fail (git_repository_discover (& found_path , ALTERNATE_MALFORMED_FOLDER3 , 0 , ceiling_dirs ));
@@ -144,8 +159,6 @@ void test_repo_discover__0(void)
144159 ensure_repository_discover (REPOSITORY_ALTERNATE_FOLDER_SUB_SUB , ceiling_dirs , & sub_repository_path );
145160 ensure_repository_discover (REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB , ceiling_dirs , & repository_path );
146161
147- cl_git_pass (git_futils_rmdir_r (TEMP_REPO_FOLDER , NULL , GIT_RMDIR_REMOVE_FILES ));
148- git_repository_free (repo );
149162 git_buf_free (& ceiling_dirs_buf );
150163 git_buf_free (& repository_path );
151164 git_buf_free (& sub_repository_path );
0 commit comments