Skip to content

Commit a933c23

Browse files
mhaggergitster
authored andcommitted
commit: avoid race when creating orphan commits
If HEAD doesn't point at anything during the initial check, then we should make sure that it *still* doesn't point at anything when we are ready to update the reference. Otherwise, another process might commit while we are working (e.g., while we are waiting for the user to edit the commit message) and we will silently overwrite it. This fixes a failing test in t7516. Signed-off-by: Michael Haggerty <[email protected]> Reviewed-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a908a31 commit a933c23

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
17661766
if (!transaction ||
17671767
ref_transaction_update(transaction, "HEAD", sha1,
17681768
current_head
1769-
? current_head->object.sha1 : NULL,
1769+
? current_head->object.sha1 : null_sha1,
17701770
0, sb.buf, &err) ||
17711771
ref_transaction_commit(transaction, &err)) {
17721772
rollback_index_files();

t/t7516-commit-races.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
test_description='git commit races'
44
. ./test-lib.sh
55

6-
test_expect_failure 'race to create orphan commit' '
6+
test_expect_success 'race to create orphan commit' '
77
write_script hare-editor <<-\EOF &&
88
git commit --allow-empty -m hare
99
EOF

0 commit comments

Comments
 (0)