clone: allow "--dissociate" without reference
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>
Alex Riesen committed
Oct 22, 2015 at 18:41 UTC
0181681e921fa4e001a51886749ee0584233db51
3 files changed
+26
-10
Documentation/git-clone.txt
+7
-2
@@ -104,8 +104,13 @@ objects from the source repository into a pack in the cloned repository.
104
--dissociate::
105
Borrow the objects from reference repositories specified
106
with the `--reference` options only to reduce network
107
- transfer and stop borrowing from them after a clone is made
108
- by making necessary local copies of borrowed objects.
107
+ transfer, and stop borrowing from them after a clone is made
108
+ by making necessary local copies of borrowed objects. This
109
+ option can also be used when cloning locally from a
110
+ repository that already borrows objects from another
111
+ repository--the new repository will borrow objects from the
112
+ same repository, and this option can be used to stop the
113
+ borrowing.
114
115
--quiet::
116
-q::
builtin/clone.c
+8
-8
@@ -801,11 +801,15 @@ static void write_refspec_config(const char *src_ref_prefix,
801
static void dissociate_from_references(void)
802
{
803
static const char* argv[] = { "repack", "-a", "-d", NULL };
804
+ char *alternates = git_pathdup("objects/info/alternates");
805
805
- if (run_command_v_opt(argv, RUN_GIT_CMD|RUN_COMMAND_NO_STDIN))
806
- die(_("cannot repack to clean up"));
807
- if (unlink(git_path("objects/info/alternates")) && errno != ENOENT)
808
- die_errno(_("cannot unlink temporary alternates file"));
806
+ if (!access(alternates, F_OK)) {
807
+ if (run_command_v_opt(argv, RUN_GIT_CMD|RUN_COMMAND_NO_STDIN))
808
+ die(_("cannot repack to clean up"));
809
+ if (unlink(alternates) && errno != ENOENT)
810
+ die_errno(_("cannot unlink temporary alternates file"));
811
+ }
812
+ free(alternates);
813
}
814
815
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)
958
959
if (option_reference.nr)
960
setup_reference();
957
- else if (option_dissociate) {
958
- warning(_("--dissociate given, but there is no --reference"));
959
- option_dissociate = 0;
960
- }
961
962
fetch_pattern = value.buf;
963
refspec = parse_fetch_refspec(1, &fetch_pattern);
t/t5700-clone-reference.sh
+11
@@ -210,4 +210,15 @@ test_expect_success 'clone, dissociate from partial reference and repack' '
210
test_line_count = 1 packs.txt
211
'
212
213
+test_expect_success 'clone, dissociate from alternates' '
214
+ rm -fr A B C &&
215
+ test_create_repo A &&
216
+ commit_in A file1 &&
217
+ git clone --reference=A A B &&
218
+ test_line_count = 1 B/.git/objects/info/alternates &&
219
+ git clone --local --dissociate B C &&
220
+ ! test -f C/.git/objects/info/alternates &&
221
+ ( cd C && git fsck )
222
+'
223
+
224
test_done