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>
This commit is contained in:
parent
6bbfd1fa98
commit
1b018fd9be
1
cache.h
1
cache.h
@ -489,6 +489,7 @@ struct lock_file {
|
|||||||
};
|
};
|
||||||
#define LOCK_DIE_ON_ERROR 1
|
#define LOCK_DIE_ON_ERROR 1
|
||||||
#define LOCK_NODEREF 2
|
#define LOCK_NODEREF 2
|
||||||
|
extern int unable_to_lock_error(const char *path, int err);
|
||||||
extern NORETURN void unable_to_lock_index_die(const char *path, int err);
|
extern NORETURN void unable_to_lock_index_die(const char *path, int err);
|
||||||
extern int hold_lock_file_for_update(struct lock_file *, const char *path, int);
|
extern int hold_lock_file_for_update(struct lock_file *, const char *path, int);
|
||||||
extern int hold_lock_file_for_append(struct lock_file *, const char *path, int);
|
extern int hold_lock_file_for_append(struct lock_file *, const char *path, int);
|
||||||
|
26
lockfile.c
26
lockfile.c
@ -155,18 +155,32 @@ static int lock_file(struct lock_file *lk, const char *path, int flags)
|
|||||||
return lk->fd;
|
return lk->fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *unable_to_lock_message(const char *path, int err)
|
||||||
NORETURN void unable_to_lock_index_die(const char *path, int err)
|
|
||||||
{
|
{
|
||||||
|
struct strbuf buf = STRBUF_INIT;
|
||||||
|
|
||||||
if (err == EEXIST) {
|
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"
|
"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"
|
"git process crashed in this repository earlier. Make sure no other git\n"
|
||||||
"process is running and remove the file manually to continue.",
|
"process is running and remove the file manually to continue.",
|
||||||
path, strerror(err));
|
path, strerror(err));
|
||||||
} else {
|
} else
|
||||||
die("Unable to create '%s.lock': %s", path, strerror(err));
|
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)
|
int hold_lock_file_for_update(struct lock_file *lk, const char *path, int flags)
|
||||||
|
4
refs.c
4
refs.c
@ -972,8 +972,10 @@ static int repack_without_ref(const char *refname)
|
|||||||
if (!found)
|
if (!found)
|
||||||
return 0;
|
return 0;
|
||||||
fd = hold_lock_file_for_update(&packlock, git_path("packed-refs"), 0);
|
fd = hold_lock_file_for_update(&packlock, git_path("packed-refs"), 0);
|
||||||
if (fd < 0)
|
if (fd < 0) {
|
||||||
|
unable_to_lock_error(git_path("packed-refs"), errno);
|
||||||
return error("cannot delete '%s' from packed refs", refname);
|
return error("cannot delete '%s' from packed refs", refname);
|
||||||
|
}
|
||||||
|
|
||||||
for (list = packed_ref_list; list; list = list->next) {
|
for (list = packed_ref_list; list; list = list->next) {
|
||||||
char line[PATH_MAX + 100];
|
char line[PATH_MAX + 100];
|
||||||
|
Loading…
Reference in New Issue
Block a user