diff mbox series

[RFC,2/9] t3429: demonstrate that rebase exec does not check for dropped commits

Message ID 20190717143918.7406-3-alban.gruin@gmail.com (mailing list archive)
State New, archived
Headers show
Series rebase -i: extend rebase.missingCommitsCheck to `--edit-todo' and co. | expand

Commit Message

Alban Gruin July 17, 2019, 2:39 p.m. UTC
After executing a command, rebase reloads the todo list from the disk,
in case the script has modified it, but does not honour
rebase.missingCommitsCheck.

This adds three tests to t3429 to demonstrate this.  The first one is
not broken, as when `rebase.missingCommitsCheck' is not set, nothing
should be done for dropped commits.  The last two are, demonstrating the
problem.

Signed-off-by: Alban Gruin <alban.gruin@gmail.com>
---
 t/t3429-rebase-edit-todo.sh | 44 +++++++++++++++++++++++++++++++++++--
 1 file changed, 42 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/t/t3429-rebase-edit-todo.sh b/t/t3429-rebase-edit-todo.sh
index 76f6d306ea..2bb9fb65fa 100755
--- a/t/t3429-rebase-edit-todo.sh
+++ b/t/t3429-rebase-edit-todo.sh
@@ -4,15 +4,16 @@  test_description='rebase should reread the todo file if an exec modifies it'
 
 . ./test-lib.sh
 
+todo=.git/rebase-merge/git-rebase-todo
+
 test_expect_success 'rebase exec modifies rebase-todo' '
 	test_commit initial &&
-	todo=.git/rebase-merge/git-rebase-todo &&
 	git rebase HEAD -x "echo exec touch F >>$todo" &&
 	test -e F
 '
 
 test_expect_success SHA1 'loose object cache vs re-reading todo list' '
-	GIT_REBASE_TODO=.git/rebase-merge/git-rebase-todo &&
+	GIT_REBASE_TODO=$todo &&
 	export GIT_REBASE_TODO &&
 	write_script append-todo.sh <<-\EOS &&
 	# For values 5 and 6, this yields SHA-1s with the same first two digits
@@ -33,4 +34,43 @@  test_expect_success SHA1 'loose object cache vs re-reading todo list' '
 	git rebase HEAD -x "./append-todo.sh 5 6"
 '
 
+test_expect_success 'rebase exec respects rebase.missingCommitsCheck = ignore' '
+	test_config rebase.missingCommitsCheck ignore &&
+	git rebase HEAD~2 --keep-empty -x "echo >$todo" &&
+	test 5 = $(git cat-file commit HEAD | sed -ne \$p)
+'
+
+cat >expect <<EOF
+Warning: some commits may have been dropped accidentally.
+Dropped commits (newer to older):
+ - $(git rev-list --pretty=oneline --abbrev-commit -1 HEAD@{2})
+To avoid this message, use "drop" to explicitly remove a commit.
+
+Use 'git config rebase.missingCommitsCheck' to change the level of warnings.
+The possible behaviours are: ignore, warn, error.
+EOF
+
+test_expect_failure 'rebase exec respects rebase.missingCommitsCheck = warn' '
+	test_config rebase.missingCommitsCheck warn &&
+	git reset --hard HEAD@{2} &&
+	git rebase HEAD~2 --keep-empty -x "echo >$todo" 2>actual.2 &&
+	head -n8 actual.2 | tail -n7 >actual &&
+	test_i18ncmp expect actual &&
+	test 5 = $(git cat-file commit HEAD | sed -ne \$p)
+'
+
+test_expect_failure 'rebase exec respects rebase.missingCommitsCheck = error' '
+	test_config rebase.missingCommitsCheck error &&
+	git reset --hard HEAD@{2} &&
+	test_must_fail git rebase HEAD~2 --keep-empty -x "echo >$todo" 2>actual.2 &&
+	head -n8 actual.2 | tail -n7 >actual &&
+	test_i18ncmp expect actual &&
+	echo drop $(git rev-list --pretty=oneline -1 HEAD@{1}) >$todo &&
+	git rebase --continue 2>actual &&
+	test 5 = $(git cat-file commit HEAD | sed -ne \$p) &&
+	test_i18ngrep \
+		"Successfully rebased and updated refs/heads/master" \
+		actual
+'
+
 test_done