From 0ef742a1a92ae53188189238adbd16086fabf80a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Lhez?= Date: Wed, 22 Jun 2016 23:30:18 +0200 Subject: [PATCH] `git bundle create ` leaks handle the revlist is empty. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 ` and when 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 `.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 --- bundle.c | 7 ++++--- t/tgfw790-git-bundle.sh | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 t/tgfw790-git-bundle.sh diff --git a/bundle.c b/bundle.c index bbf4efa0a0a38a..da45536224abf9 100644 --- a/bundle.c +++ b/bundle.c @@ -447,10 +447,11 @@ int create_bundle(struct bundle_header *header, const char *path, object_array_remove_duplicates(&revs.pending); ref_count = write_bundle_refs(bundle_fd, &revs); - if (!ref_count) - die(_("Refusing to create empty bundle.")); - else if (ref_count < 0) + if (ref_count <= 0) { + if (!ref_count) + error(_("Refusing to create empty bundle.")); goto err; + } /* write pack */ if (write_pack_data(bundle_fd, &revs)) { diff --git a/t/tgfw790-git-bundle.sh b/t/tgfw790-git-bundle.sh new file mode 100644 index 00000000000000..6bfa23c1419bba --- /dev/null +++ b/t/tgfw790-git-bundle.sh @@ -0,0 +1,15 @@ +#!/bin/sh +test_description=' + test git-bundle under git for Windows + + When we select an empty set of commit (like git bundle create foobar.bundle master..master), + we should not have problem with the foobar.bundle.lock being locked (especially on Windows). +' + +. ./test-lib.sh + +test_expect_failure 'try to create a bundle with empty ref count' ' + git bundle create foobar.bundle master..master +' + +test_done