summaryrefslogtreecommitdiff
path: root/git-rebase--interactive.sh
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 /git-rebase--interactive.sh
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 'git-rebase--interactive.sh')
-rw-r--r--git-rebase--interactive.sh72
1 files changed, 72 insertions, 0 deletions
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index c26a200a6c..dcc3401b5a 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -846,6 +846,71 @@ add_exec_commands () {
mv "$1.new" "$1"
}
+# Check if the SHA-1 passed as an argument is a
+# correct one, if not then print $2 in "$todo".badsha
+# $1: the SHA-1 to test
+# $2: the line to display if incorrect SHA-1
+check_commit_sha () {
+ badsha=0
+ if test -z $1
+ then
+ badsha=1
+ else
+ sha1_verif="$(git rev-parse --verify --quiet $1^{commit})"
+ if test -z $sha1_verif
+ then
+ badsha=1
+ fi
+ fi
+
+ if test $badsha -ne 0
+ then
+ warn "Warning: the SHA-1 is missing or isn't" \
+ "a commit in the following line:"
+ warn " - $2"
+ warn
+ fi
+
+ return $badsha
+}
+
+# prints the bad commits and bad commands
+# from the todolist in stdin
+check_bad_cmd_and_sha () {
+ retval=0
+ git stripspace --strip-comments |
+ (
+ while read -r line
+ do
+ IFS=' '
+ set -- $line
+ command=$1
+ sha1=$2
+
+ case $command in
+ ''|noop|x|"exec")
+ # Doesn't expect a SHA-1
+ ;;
+ pick|p|drop|d|reword|r|edit|e|squash|s|fixup|f)
+ if ! check_commit_sha $sha1 "$line"
+ then
+ retval=1
+ fi
+ ;;
+ *)
+ warn "Warning: the command isn't recognized" \
+ "in the following line:"
+ warn " - $line"
+ warn
+ retval=1
+ ;;
+ esac
+ done
+
+ return $retval
+ )
+}
+
# Print the list of the SHA-1 of the commits
# from stdin to stdout
todo_list_to_sha_list () {
@@ -887,6 +952,8 @@ get_missing_commit_check_level () {
# Check if the user dropped some commits by mistake
# Behaviour determined by rebase.missingCommitsCheck.
+# Check if there is an unrecognized command or a
+# bad SHA-1 in a command.
check_todo_list () {
raise_error=f
@@ -935,6 +1002,11 @@ check_todo_list () {
;;
esac
+ if ! check_bad_cmd_and_sha <"$todo"
+ then
+ raise_error=t
+ fi
+
if test $raise_error = t
then
# Checkout before the first commit of the