Skip to content

Commit

Permalink
Merge branch 'as/clone-reference-with-gitfile'
Browse files Browse the repository at this point in the history
"git clone" did not work if a repository pointed at by the
"--reference" option is a gitfile that points at another place.

* as/clone-reference-with-gitfile:
  clone: Allow repo using gitfile as a reference
  clone: Fix error message for reference repository
  • Loading branch information
Junio C Hamano committed Apr 22, 2013
2 parents 561954b + b552b56 commit fd6d822
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
16 changes: 13 additions & 3 deletions builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,26 @@ static void strip_trailing_slashes(char *dir)
static int add_one_reference(struct string_list_item *item, void *cb_data)
{
char *ref_git;
const char *repo;
struct strbuf alternate = STRBUF_INIT;

/* Beware: real_path() and mkpath() return static buffer */
/* Beware: read_gitfile(), real_path() and mkpath() return static buffer */
ref_git = xstrdup(real_path(item->string));
if (is_directory(mkpath("%s/.git/objects", ref_git))) {

repo = read_gitfile(ref_git);
if (!repo)
repo = read_gitfile(mkpath("%s/.git", ref_git));
if (repo) {
free(ref_git);
ref_git = xstrdup(repo);
}

if (!repo && is_directory(mkpath("%s/.git/objects", ref_git))) {
char *ref_git_git = mkpathdup("%s/.git", ref_git);
free(ref_git);
ref_git = ref_git_git;
} else if (!is_directory(mkpath("%s/objects", ref_git)))
die(_("reference repository '%s' is not a local directory."),
die(_("reference repository '%s' is not a local repository."),
item->string);

strbuf_addf(&alternate, "%s/objects", ref_git);
Expand Down
13 changes: 13 additions & 0 deletions t/t5700-clone-reference.sh
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,17 @@ test_expect_success 'fetch with incomplete alternates' '
! grep " want $tag_object" "$U.K"
'

test_expect_success 'clone using repo with gitfile as a reference' '
git clone --separate-git-dir=L A M &&
git clone --reference=M A N &&
echo "$base_dir/L/objects" >expected &&
test_cmp expected "$base_dir/N/.git/objects/info/alternates"
'

test_expect_success 'clone using repo pointed at by gitfile as reference' '
git clone --reference=M/.git A O &&
echo "$base_dir/L/objects" >expected &&
test_cmp expected "$base_dir/O/.git/objects/info/alternates"
'

test_done

0 comments on commit fd6d822

Please sign in to comment.