set_worktree_head_symref(): fix error message
Emit an informative error when failed to hold lock of HEAD. 2233066e (refs: add a new function set_worktree_head_symref, 2016-03-27) added set_worktree_head_symref(), but this is missing a call to unable_to_lock_message() after hold_lock_file_for_update() fails, so it emits an empty error message: % git branch -m oldname newname error: error: HEAD of working tree /path/to/wt is not updated fatal: Branch renamed to newname, but HEAD is not updated! Thanks to Eric Sunshine for pointing this out. Signed-off-by: Kazuki Yamaguchi <k@rhe.jp> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Kazuki Yamaguchi committed
Apr 8, 2016 at 17:03 UTC
18eb3a9ce7c544e74d424b942c5a5c9720c20112
1 file changed
+2
-1
refs/files-backend.c
+2
-1
@@ -2898,7 +2898,6 @@ int set_worktree_head_symref(const char *gitdir, const char *target)
2898
{
2899
static struct lock_file head_lock;
2900
struct ref_lock *lock;
2901
- struct strbuf err = STRBUF_INIT;
2901
struct strbuf head_path = STRBUF_INIT;
2902
const char *head_rel;
2903
int ret;
@@ -2906,6 +2905,8 @@ int set_worktree_head_symref(const char *gitdir, const char *target)
2905
strbuf_addf(&head_path, "%s/HEAD", absolute_path(gitdir));
2906
if (hold_lock_file_for_update(&head_lock, head_path.buf,
2907
LOCK_NO_DEREF) < 0) {
2908
+ struct strbuf err = STRBUF_INIT;
2909
+ unable_to_lock_message(head_path.buf, errno, &err);
2910
error("%s", err.buf);
2911
strbuf_release(&err);
2912
strbuf_release(&head_path);