summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorGalan Rémi <remi.galan-alfonso@ensimag.grenoble-inp.fr>2015-06-29 22:20:32 +0200
committerJunio C Hamano <gitster@pobox.com>2015-06-30 12:14:25 -0700
commit804098bb30a5339cccb0be981a3e876245aa0ae5 (patch)
treef8d9133bc7c589fd94d0c504a825567fd25b61e9 /t
parent370799596081e1d1f862e42305ba8119183bde94 (diff)
downloadgit-804098bb30a5339cccb0be981a3e876245aa0ae5.tar.gz
git rebase -i: add static check for commands and SHA-1
Check before the start of the rebasing if the commands exists, and for the commands expecting a SHA-1, check if the SHA-1 is present and corresponds to a commit. In case of error, print the error, stop git rebase and prompt the user to fix with 'git rebase --edit-todo' or to abort. This allows to avoid doing half of a rebase before finding an error and giving back what's left of the todo list to the user and prompt him to fix when it might be too late for him to do so (he might have to abort and restart the rebase). Signed-off-by: Galan Rémi <remi.galan-alfonso@ensimag.grenoble-inp.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't')
-rw-r--r--t/lib-rebase.sh5
-rwxr-xr-xt/t3404-rebase-interactive.sh39
2 files changed, 44 insertions, 0 deletions
diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh
index fdbc9007d0..9a96e1566d 100644
--- a/t/lib-rebase.sh
+++ b/t/lib-rebase.sh
@@ -54,6 +54,11 @@ set_fake_editor () {
echo '# comment' >> "$1";;
">")
echo >> "$1";;
+ bad)
+ action="badcmd";;
+ fakesha)
+ echo "$action XXXXXXX False commit" >> "$1"
+ action=pick;;
*)
sed -n "${line}s/^pick/$action/p" < "$1".tmp >> "$1"
action=pick;;
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index cfa741018d..ebdab4b95d 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -1186,4 +1186,43 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
test B = $(git cat-file commit HEAD^ | sed -ne \$p)
'
+cat >expect <<EOF
+Warning: the command isn't recognized in the following line:
+ - badcmd $(git rev-list --oneline -1 master~1)
+
+You can fix this with 'git rebase --edit-todo'.
+Or you can abort the rebase with 'git rebase --abort'.
+EOF
+
+test_expect_success 'static check of bad command' '
+ rebase_setup_and_clean bad-cmd &&
+ set_fake_editor &&
+ test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
+ git rebase -i --root 2>actual &&
+ test_cmp expect actual &&
+ FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo &&
+ git rebase --continue &&
+ test E = $(git cat-file commit HEAD | sed -ne \$p) &&
+ test C = $(git cat-file commit HEAD^ | sed -ne \$p)
+'
+
+cat >expect <<EOF
+Warning: the SHA-1 is missing or isn't a commit in the following line:
+ - edit XXXXXXX False commit
+
+You can fix this with 'git rebase --edit-todo'.
+Or you can abort the rebase with 'git rebase --abort'.
+EOF
+
+test_expect_success 'static check of bad SHA-1' '
+ rebase_setup_and_clean bad-sha &&
+ set_fake_editor &&
+ test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \
+ git rebase -i --root 2>actual &&
+ test_cmp expect actual &&
+ FAKE_LINES="1 2 4 5 6" git rebase --edit-todo &&
+ git rebase --continue &&
+ test E = $(git cat-file commit HEAD | sed -ne \$p)
+'
+
test_done