File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -232,16 +232,26 @@ static void strip_trailing_slashes(char *dir)
232232static int add_one_reference (struct string_list_item * item , void * cb_data )
233233{
234234 char * ref_git ;
235+ const char * repo ;
235236 struct strbuf alternate = STRBUF_INIT ;
236237
237- /* Beware: real_path() and mkpath() return static buffer */
238+ /* Beware: read_gitfile(), real_path() and mkpath() return static buffer */
238239 ref_git = xstrdup (real_path (item -> string ));
239- if (is_directory (mkpath ("%s/.git/objects" , ref_git ))) {
240+
241+ repo = read_gitfile (ref_git );
242+ if (!repo )
243+ repo = read_gitfile (mkpath ("%s/.git" , ref_git ));
244+ if (repo ) {
245+ free (ref_git );
246+ ref_git = xstrdup (repo );
247+ }
248+
249+ if (!repo && is_directory (mkpath ("%s/.git/objects" , ref_git ))) {
240250 char * ref_git_git = mkpathdup ("%s/.git" , ref_git );
241251 free (ref_git );
242252 ref_git = ref_git_git ;
243253 } else if (!is_directory (mkpath ("%s/objects" , ref_git )))
244- die (_ ("reference repository '%s' is not a local directory ." ),
254+ die (_ ("reference repository '%s' is not a local repository ." ),
245255 item -> string );
246256
247257 strbuf_addf (& alternate , "%s/objects" , ref_git );
Original file line number Diff line number Diff line change @@ -185,4 +185,17 @@ test_expect_success 'fetch with incomplete alternates' '
185185 ! grep " want $tag_object" "$U.K"
186186'
187187
188+ test_expect_success ' clone using repo with gitfile as a reference' '
189+ git clone --separate-git-dir=L A M &&
190+ git clone --reference=M A N &&
191+ echo "$base_dir/L/objects" >expected &&
192+ test_cmp expected "$base_dir/N/.git/objects/info/alternates"
193+ '
194+
195+ test_expect_success ' clone using repo pointed at by gitfile as reference' '
196+ git clone --reference=M/.git A O &&
197+ echo "$base_dir/L/objects" >expected &&
198+ test_cmp expected "$base_dir/O/.git/objects/info/alternates"
199+ '
200+
188201test_done
You can’t perform that action at this time.
0 commit comments