Skip to content

Commit 2e4b5de

Browse files
committed
Merge branch 'rs/ref-update-check-errors-early'
* rs/ref-update-check-errors-early: commit.c: check for lock error and return early sequencer.c: check for lock failure and bail early in fast_forward_to
2 parents 53f52cd + 55a5c8d commit 2e4b5de

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

builtin/commit.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,6 +1672,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
16721672
? NULL
16731673
: current_head->object.sha1,
16741674
0, NULL);
1675+
if (!ref_lock) {
1676+
rollback_index_files();
1677+
die(_("cannot lock HEAD ref"));
1678+
}
16751679

16761680
nl = strchr(sb.buf, '\n');
16771681
if (nl)
@@ -1681,10 +1685,6 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
16811685
strbuf_insert(&sb, 0, reflog_msg, strlen(reflog_msg));
16821686
strbuf_insert(&sb, strlen(reflog_msg), ": ", 2);
16831687

1684-
if (!ref_lock) {
1685-
rollback_index_files();
1686-
die(_("cannot lock HEAD ref"));
1687-
}
16881688
if (write_ref_sha1(ref_lock, sha1, sb.buf) < 0) {
16891689
rollback_index_files();
16901690
die(_("cannot update HEAD ref"));

sequencer.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,12 @@ static int fast_forward_to(const unsigned char *to, const unsigned char *from,
281281
exit(1); /* the callee should have complained already */
282282
ref_lock = lock_any_ref_for_update("HEAD", unborn ? null_sha1 : from,
283283
0, NULL);
284+
if (!ref_lock)
285+
return error(_("Failed to lock HEAD during fast_forward_to"));
286+
284287
strbuf_addf(&sb, "%s: fast-forward", action_name(opts));
285288
ret = write_ref_sha1(ref_lock, to, sb.buf);
289+
286290
strbuf_release(&sb);
287291
return ret;
288292
}

0 commit comments

Comments
 (0)