aboutsummaryrefslogtreecommitdiffstats
path: root/lockfile.c
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@frugalware.org>2009-09-27 01:15:09 +0200
committerShawn O. Pearce <spearce@spearce.org>2009-09-29 08:14:47 -0700
commit1b018fd9be290fd6a70ce3093ab1dc1abce74e00 (patch)
tree4961e8dec3da9cd76e3d79b57c24c3cdf97d2c35 /lockfile.c
parent6bbfd1fa98b0c1fa1684bd35e64404799f0cc2b3 (diff)
downloadgit-1b018fd9be290fd6a70ce3093ab1dc1abce74e00.tar.gz
git branch -D: give a better error message when lockfile creation fails
Previously the old error message just told the user that it was not possible to delete the ref from the packed-refs file. Give instructions on how to resolve the problem. Signed-off-by: Miklos Vajna <vmiklos@frugalware.org> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'lockfile.c')
-rw-r--r--lockfile.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/lockfile.c b/lockfile.c
index eb931eded5..6851fa55a5 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -155,18 +155,32 @@ static int lock_file(struct lock_file *lk, const char *path, int flags)
return lk->fd;
}
-
-NORETURN void unable_to_lock_index_die(const char *path, int err)
+static char *unable_to_lock_message(const char *path, int err)
{
+ struct strbuf buf = STRBUF_INIT;
+
if (err == EEXIST) {
- die("Unable to create '%s.lock': %s.\n\n"
+ strbuf_addf(&buf, "Unable to create '%s.lock': %s.\n\n"
"If no other git process is currently running, this probably means a\n"
"git process crashed in this repository earlier. Make sure no other git\n"
"process is running and remove the file manually to continue.",
path, strerror(err));
- } else {
- die("Unable to create '%s.lock': %s", path, strerror(err));
- }
+ } else
+ strbuf_addf(&buf, "Unable to create '%s.lock': %s", path, strerror(err));
+ return strbuf_detach(&buf, NULL);
+}
+
+int unable_to_lock_error(const char *path, int err)
+{
+ char *msg = unable_to_lock_message(path, err);
+ error("%s", msg);
+ free(msg);
+ return -1;
+}
+
+NORETURN void unable_to_lock_index_die(const char *path, int err)
+{
+ die("%s", unable_to_lock_message(path, err));
}
int hold_lock_file_for_update(struct lock_file *lk, const char *path, int flags)