diff options
author | Junio C Hamano <gitster@pobox.com> | 2015-10-30 13:06:53 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-10-30 13:06:53 -0700 |
commit | 908700c0082487f9c859b951370148ff7e8acb97 (patch) | |
tree | 1dea0f29594b1d3d10c470947eb40912b272e29f | |
parent | Merge git://ozlabs.org/~paulus/gitk (diff) | |
parent | clone: allow "--dissociate" without reference (diff) | |
download | tgif-908700c0082487f9c859b951370148ff7e8acb97.tar.xz |
Merge branch 'ar/clone-dissociate'
"git clone --dissociate" used to require that "--reference" was
used at the same time, but you can create a new repository that
borrows objects from another without using "--reference", namely
with "clone --local" from a repository that borrows objects from
other repositories.
* ar/clone-dissociate:
clone: allow "--dissociate" without reference
-rw-r--r-- | Documentation/git-clone.txt | 9 | ||||
-rw-r--r-- | builtin/clone.c | 16 | ||||
-rwxr-xr-x | t/t5700-clone-reference.sh | 11 |
3 files changed, 26 insertions, 10 deletions
diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt index f1f2a3f7ea..6bf000dac3 100644 --- a/Documentation/git-clone.txt +++ b/Documentation/git-clone.txt @@ -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:: diff --git a/builtin/clone.c b/builtin/clone.c index 9eaecd9a7c..caae43e7a3 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -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) @@ -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); diff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh index 2250ef4fe2..dfa1bf79c5 100755 --- a/t/t5700-clone-reference.sh +++ b/t/t5700-clone-reference.sh @@ -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 |