Skip to content

Commit

Permalink
clone: allow "--dissociate" without reference
Browse files Browse the repository at this point in the history
The "--reference" option is not the only way to provide a repository
to borrow objects from.  A repository that borrows from another
repository can be cloned with "clone --local" and the resulting
repository will borrow from the same repository, which the user
may want to "--dissociate" from.

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
raalkml authored and gitster committed Oct 22, 2015
1 parent 74301d6 commit 0181681
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
9 changes: 7 additions & 2 deletions Documentation/git-clone.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,13 @@ objects from the source repository into a pack in the cloned repository.
--dissociate::
Borrow the objects from reference repositories specified
with the `--reference` options only to reduce network
transfer and stop borrowing from them after a clone is made
by making necessary local copies of borrowed objects.
transfer, and stop borrowing from them after a clone is made
by making necessary local copies of borrowed objects. This
option can also be used when cloning locally from a
repository that already borrows objects from another
repository--the new repository will borrow objects from the
same repository, and this option can be used to stop the
borrowing.

--quiet::
-q::
Expand Down
16 changes: 8 additions & 8 deletions builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,11 +801,15 @@ static void write_refspec_config(const char *src_ref_prefix,
static void dissociate_from_references(void)
{
static const char* argv[] = { "repack", "-a", "-d", NULL };
char *alternates = git_pathdup("objects/info/alternates");

if (run_command_v_opt(argv, RUN_GIT_CMD|RUN_COMMAND_NO_STDIN))
die(_("cannot repack to clean up"));
if (unlink(git_path("objects/info/alternates")) && errno != ENOENT)
die_errno(_("cannot unlink temporary alternates file"));
if (!access(alternates, F_OK)) {
if (run_command_v_opt(argv, RUN_GIT_CMD|RUN_COMMAND_NO_STDIN))
die(_("cannot repack to clean up"));
if (unlink(alternates) && errno != ENOENT)
die_errno(_("cannot unlink temporary alternates file"));
}
free(alternates);
}

int cmd_clone(int argc, const char **argv, const char *prefix)
Expand Down Expand Up @@ -954,10 +958,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)

if (option_reference.nr)
setup_reference();
else if (option_dissociate) {
warning(_("--dissociate given, but there is no --reference"));
option_dissociate = 0;
}

fetch_pattern = value.buf;
refspec = parse_fetch_refspec(1, &fetch_pattern);
Expand Down
11 changes: 11 additions & 0 deletions t/t5700-clone-reference.sh
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,15 @@ test_expect_success 'clone, dissociate from partial reference and repack' '
test_line_count = 1 packs.txt
'

test_expect_success 'clone, dissociate from alternates' '
rm -fr A B C &&
test_create_repo A &&
commit_in A file1 &&
git clone --reference=A A B &&
test_line_count = 1 B/.git/objects/info/alternates &&
git clone --local --dissociate B C &&
! test -f C/.git/objects/info/alternates &&
( cd C && git fsck )
'

test_done

0 comments on commit 0181681

Please sign in to comment.