Skip to content

Commit 7e7d709

Browse files
glhezdscho
authored andcommitted
git bundle create <bundle> leaks handle the revlist is empty.
issue #790: git bundle create does not close handle to *.lock file This problem happens when an user tries to create an empty bundle, using the following command: `git bundle create <bundle> <revlist>` and when <revlist> resolve to an empty list (for example, like `master..master`), `git bundle` fails and warn the user about how it don't want to create empty bundle. In that case, git tries to delete the `<bundle>.lock` file, and since there's still an open file handle, fails to do so and ask the user if it should retry (which will fail again). The lock can still be deleted manually by the user (and it is required if the user want to create a bundle after revising his rev-list). Signed-off-by: Gaël Lhez <[email protected]>
1 parent a6098c7 commit 7e7d709

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

bundle.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,11 @@ int create_bundle(struct bundle_header *header, const char *path,
447447
object_array_remove_duplicates(&revs.pending);
448448

449449
ref_count = write_bundle_refs(bundle_fd, &revs);
450-
if (!ref_count)
451-
die(_("Refusing to create empty bundle."));
452-
else if (ref_count < 0)
450+
if (ref_count <= 0) {
451+
if (!ref_count)
452+
error(_("Refusing to create empty bundle."));
453453
goto err;
454+
}
454455

455456
/* write pack */
456457
if (write_pack_data(bundle_fd, &revs)) {

t/tgfw790-git-bundle.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
test_description='
3+
test git-bundle under git for Windows
4+
5+
When we select an empty set of commit (like git bundle create foobar.bundle master..master),
6+
we should not have problem with the foobar.bundle.lock being locked (especially on Windows).
7+
'
8+
9+
. ./test-lib.sh
10+
11+
test_expect_failure 'try to create a bundle with empty ref count' '
12+
git bundle create foobar.bundle master..master
13+
'
14+
15+
test_done

0 commit comments

Comments
 (0)