Skip to content

Commit 908700c

Browse files
committed
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
2 parents 482456a + 0181681 commit 908700c

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

Documentation/git-clone.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,13 @@ objects from the source repository into a pack in the cloned repository.
104104
--dissociate::
105105
Borrow the objects from reference repositories specified
106106
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.
109114

110115
--quiet::
111116
-q::

builtin/clone.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -801,11 +801,15 @@ static void write_refspec_config(const char *src_ref_prefix,
801801
static void dissociate_from_references(void)
802802
{
803803
static const char* argv[] = { "repack", "-a", "-d", NULL };
804+
char *alternates = git_pathdup("objects/info/alternates");
804805

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);
809813
}
810814

811815
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)
954958

955959
if (option_reference.nr)
956960
setup_reference();
957-
else if (option_dissociate) {
958-
warning(_("--dissociate given, but there is no --reference"));
959-
option_dissociate = 0;
960-
}
961961

962962
fetch_pattern = value.buf;
963963
refspec = parse_fetch_refspec(1, &fetch_pattern);

t/t5700-clone-reference.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,15 @@ test_expect_success 'clone, dissociate from partial reference and repack' '
210210
test_line_count = 1 packs.txt
211211
'
212212

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+
213224
test_done

0 commit comments

Comments
 (0)