Skip to content

Commit a4e4f06

Browse files
committed
Merge branch 'pw/sequencer-compare-with-right-parent-to-check-empty-commits' into next
The sequencer machinery compared the HEAD and the state it is attempting to commit to decide if the result would be a no-op commit, even when amending a commit, which was incorrect, and has been corrected. * pw/sequencer-compare-with-right-parent-to-check-empty-commits: sequencer: fix empty commit check when amending
2 parents cd97ae3 + 2d05ef2 commit a4e4f06

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

sequencer.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,11 +1350,27 @@ static int try_to_commit(struct repository *r,
13501350
goto out;
13511351
}
13521352

1353-
if (!(flags & ALLOW_EMPTY) && oideq(current_head ?
1354-
get_commit_tree_oid(current_head) :
1355-
the_hash_algo->empty_tree, &tree)) {
1356-
res = 1; /* run 'git commit' to display error message */
1357-
goto out;
1353+
if (!(flags & ALLOW_EMPTY)) {
1354+
struct commit *first_parent = current_head;
1355+
1356+
if (flags & AMEND_MSG) {
1357+
if (current_head->parents) {
1358+
first_parent = current_head->parents->item;
1359+
if (repo_parse_commit(r, first_parent)) {
1360+
res = error(_("could not parse HEAD commit"));
1361+
goto out;
1362+
}
1363+
} else {
1364+
first_parent = NULL;
1365+
}
1366+
}
1367+
if (oideq(first_parent
1368+
? get_commit_tree_oid(first_parent)
1369+
: the_hash_algo->empty_tree,
1370+
&tree)) {
1371+
res = 1; /* run 'git commit' to display error message */
1372+
goto out;
1373+
}
13581374
}
13591375

13601376
if (find_hook("prepare-commit-msg")) {

t/t3403-rebase-skip.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ test_description='git rebase --merge --skip tests'
77

88
. ./test-lib.sh
99

10+
. "$TEST_DIRECTORY"/lib-rebase.sh
11+
1012
# we assume the default git am -3 --skip strategy is tested independently
1113
# and always works :)
1214

@@ -20,6 +22,13 @@ test_expect_success setup '
2022
git commit -a -m "hello world" &&
2123
echo goodbye >> hello &&
2224
git commit -a -m "goodbye" &&
25+
git tag goodbye &&
26+
27+
git checkout --detach &&
28+
git checkout HEAD^ . &&
29+
test_tick &&
30+
git commit -m reverted-goodbye &&
31+
git tag reverted-goodbye &&
2332
2433
git checkout -f skip-reference &&
2534
echo moo > hello &&
@@ -76,4 +85,27 @@ test_expect_success 'moved back to branch correctly' '
7685

7786
test_debug 'gitk --all & sleep 1'
7887

88+
test_expect_success 'fixup that empties commit fails' '
89+
test_when_finished "git rebase --abort" &&
90+
(
91+
set_fake_editor &&
92+
test_must_fail env FAKE_LINES="1 fixup 2" git rebase -i \
93+
goodbye^ reverted-goodbye
94+
)
95+
'
96+
97+
test_expect_success 'squash that empties commit fails' '
98+
test_when_finished "git rebase --abort" &&
99+
(
100+
set_fake_editor &&
101+
test_must_fail env FAKE_LINES="1 squash 2" git rebase -i \
102+
goodbye^ reverted-goodbye
103+
)
104+
'
105+
106+
# Must be the last test in this file
107+
test_expect_success '$EDITOR and friends are unchanged' '
108+
test_editor_unchanged
109+
'
110+
79111
test_done

0 commit comments

Comments
 (0)