clone --dissociate: avoid locking pack files

When `git clone` is asked to dissociate the repository from the reference repository whose objects were used, it is quite possible that the pack files need to be repacked. In that case, the pack files need to be deleted that were originally hard-links to the reference repository's pack files. On platforms where a file cannot be deleted if another process still holds a handle on it, we therefore need to take pains to release all pack files and indexes before dissociating. This fixes https://github.com/git-for-windows/git/issues/446 The test case to demonstrate the breakage technically does not need to be run on Linux or MacOSX. It won't hurt, either, though. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Oct 6, 2015 at 15:18 UTC 786b150c8d0960cb7c36fb1cbbf70dbd76b586de
2 files changed +4 -2
builtin/clone.c
+3 -1
@@ -995,8 +995,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
995 transport_unlock_pack(transport);
996 transport_disconnect(transport);
997
998 - if (option_dissociate)
998 + if (option_dissociate) {
999 + close_all_packs();
1000 dissociate_from_references();
1001 + }
1002
1003 junk_mode = JUNK_LEAVE_REPO;
1004 err = checkout();
t/t5700-clone-reference.sh
+1 -1
@@ -214,7 +214,7 @@ test_expect_success 'clone and dissociate from reference' '
214 test_must_fail git -C R fsck &&
215 git -C S fsck
216 '
217 -test_expect_failure MINGW 'clone, dissociate from partial reference and repack' '
217 +test_expect_success 'clone, dissociate from partial reference and repack' '
218 rm -fr P Q R &&
219 git init P &&
220 (