git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Gaël Lhez via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Stefan Beller" <sbeller@google.com>,
	"Junio C Hamano" <gitster@pobox.com>,
	"Gaël Lhez" <gael.lhez@gmail.com>
Subject: [PATCH v2 1/1] bundle: cleanup lock files on error
Date: Wed, 14 Nov 2018 07:25:15 -0800 (PST)	[thread overview]
Message-ID: <c88887f05a145709be9e86d56f4c1e620eb5ea89.1542209112.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.79.v2.git.gitgitgadget@gmail.com>

From: =?UTF-8?q?Ga=C3=ABl=20Lhez?= <gael.lhez@gmail.com>

When an user tries to create an empty bundle via `git bundle create
<bundle> <revlist>` where `<revlist>` resolves to an empty list (for
example, like `master..master`), the command fails and warns the user
about how it does not want to create empty bundle.

However, the `.lock` file was still open and on Windows that means
that it could not be deleted properly. This patch fixes that issue.

This closes https://github.com/git-for-windows/git/issues/790

Signed-off-by: Gaël Lhez <gael.lhez@gmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 bundle.c                | 7 ++++---
 t/t5607-clone-bundle.sh | 4 ++++
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/bundle.c b/bundle.c
index 1ef584b93b..4e349feff9 100644
--- a/bundle.c
+++ b/bundle.c
@@ -457,10 +457,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/t5607-clone-bundle.sh b/t/t5607-clone-bundle.sh
index 348d9b3bc7..f84b875950 100755
--- a/t/t5607-clone-bundle.sh
+++ b/t/t5607-clone-bundle.sh
@@ -71,4 +71,8 @@ test_expect_success 'prerequisites with an empty commit message' '
 	git bundle verify bundle
 '
 
+test_expect_success 'try to create a bundle with empty ref count' '
+	test_expect_code 1 git bundle create foobar.bundle master..master
+'
+
 test_done
-- 
gitgitgadget

  reply	other threads:[~2018-11-14 15:25 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-13 15:09 [PATCH 0/1] bundle: fix issue when bundles would be empty Johannes Schindelin via GitGitGadget
2018-11-13 15:09 ` [PATCH 1/1] bundle: refuse to create empty bundle Gaël Lhez via GitGitGadget
2018-11-13 19:28   ` Stefan Beller
2018-11-13 20:37     ` Gaël Lhez
     [not found]     ` <CAK8L4uiMHrsdwJz9+rD1tSCywL2kHosx-hKZdS=UtZDHLy464A@mail.gmail.com>
2018-11-13 21:11       ` Stefan Beller
2018-11-14 15:23         ` Johannes Schindelin
2018-11-14 15:25 ` [PATCH v2 0/1] bundle: fix issue when bundles would be empty Johannes Schindelin via GitGitGadget
2018-11-14 15:25   ` Gaël Lhez via GitGitGadget [this message]
2018-11-14 21:43     ` [PATCH v2 1/1] bundle: cleanup lock files on error Martin Ågren
2018-11-14 22:08       ` Stefan Beller
2018-11-15  4:34         ` Jeff King
2018-11-15 12:57           ` Johannes Schindelin
2018-11-15 13:37             ` Jeff King
2018-11-15 16:32               ` Johannes Schindelin
2018-11-15 16:43                 ` Jeff King
2018-11-15 20:01                   ` Johannes Schindelin
2018-11-16  9:43                     ` [PATCH] bundle: dup() output descriptor closer to point-of-use Jeff King
2018-11-16 15:06                       ` Johannes Schindelin
2018-11-17  7:05                       ` Junio C Hamano
2018-11-15 16:49             ` [PATCH v2 1/1] bundle: cleanup lock files on error Duy Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c88887f05a145709be9e86d56f4c1e620eb5ea89.1542209112.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=gael.lhez@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=sbeller@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).