Skip to content

Commit 1ff7b49

Browse files
committed
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 #446 Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 2a7953e commit 1ff7b49

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

builtin/clone.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,8 +1066,15 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
10661066
transport_unlock_pack(transport);
10671067
transport_disconnect(transport);
10681068

1069-
if (option_dissociate)
1069+
if (option_dissociate) {
1070+
struct packed_git *p;
1071+
1072+
for (p = packed_git; p; p = p->next) {
1073+
close_pack_windows(p);
1074+
close_pack_index(p);
1075+
}
10701076
dissociate_from_references();
1077+
}
10711078

10721079
junk_mode = JUNK_LEAVE_REPO;
10731080
err = checkout();

t/t5700-clone-reference.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,5 +188,26 @@ test_expect_success 'clone and dissociate from reference' '
188188
test_must_fail git -C R fsck &&
189189
git -C S fsck
190190
'
191+
test_expect_success 'clone, dissociate from partial reference and repack' '
192+
rm -fr P Q R &&
193+
git init P &&
194+
(
195+
cd P &&
196+
test_commit one &&
197+
git repack &&
198+
test_commit two &&
199+
git repack
200+
) &&
201+
git clone --bare P Q &&
202+
(
203+
cd P &&
204+
git checkout -b second &&
205+
test_commit three &&
206+
git repack
207+
) &&
208+
git clone --bare --dissociate --reference=P Q R &&
209+
ls R/objects/pack/*.pack >packs.txt &&
210+
test_line_count = 1 packs.txt
211+
'
191212

192213
test_done

0 commit comments

Comments
 (0)