travis-ci: check that all build artifacts are .gitignore-d
[gitweb.git] / git-rebase--interactive.sh
index 5ff0f1c81ac8e72ce6a2358ca2fced0650571030..90b1fbe9cf6e8dfb2f4331916809fa40bf9050d2 100644 (file)
@@ -5,7 +5,7 @@
 # Copyright (c) 2006 Johannes E. Schindelin
 #
 # The original idea comes from Eric W. Biederman, in
-# http://article.gmane.org/gmane.comp.version-control.git/22407
+# https://public-inbox.org/git/m1odwkyuf5.fsf_-_@ebiederm.dsl.xmission.com/
 #
 # The file containing rebase commands, comments, and empty lines.
 # This file is created by "git rebase -i" then edited by the user.  As
@@ -77,23 +77,33 @@ amend="$state_dir"/amend
 rewritten_list="$state_dir"/rewritten-list
 rewritten_pending="$state_dir"/rewritten-pending
 
-strategy_args=
-if test -n "$do_merge"
-then
-       strategy_args=${strategy:+--strategy=$strategy}
-       eval '
-               for strategy_opt in '"$strategy_opts"'
-               do
-                       strategy_args="$strategy_args -X$(git rev-parse --sq-quote "${strategy_opt#--}")"
-               done
-       '
-fi
+# Work around Git for Windows' Bash whose "read" does not strip CRLF
+# and leaves CR at the end instead.
+cr=$(printf "\015")
+
+strategy_args=${strategy:+--strategy=$strategy}
+test -n "$strategy_opts" &&
+eval '
+       for strategy_opt in '"$strategy_opts"'
+       do
+               strategy_args="$strategy_args -X$(git rev-parse --sq-quote "${strategy_opt#--}")"
+       done
+'
 
 GIT_CHERRY_PICK_HELP="$resolvemsg"
 export GIT_CHERRY_PICK_HELP
 
-comment_char=$(git config --get core.commentchar 2>/dev/null | cut -c1)
-: ${comment_char:=#}
+comment_char=$(git config --get core.commentchar 2>/dev/null)
+case "$comment_char" in
+'' | auto)
+       comment_char="#"
+       ;;
+?)
+       ;;
+*)
+       comment_char=$(echo "$comment_char" | cut -c1)
+       ;;
+esac
 
 warn () {
        printf '%s\n' "$*" >&2
@@ -120,14 +130,14 @@ mark_action_done () {
        sed -e 1q < "$todo" >> "$done"
        sed -e 1d < "$todo" >> "$todo".new
        mv -f "$todo".new "$todo"
-       new_count=$(git stripspace --strip-comments <"$done" | wc -l)
+       new_count=$(( $(git stripspace --strip-comments <"$done" | wc -l) ))
        echo $new_count >"$msgnum"
        total=$(($new_count + $(git stripspace --strip-comments <"$todo" | wc -l)))
        echo $total >"$end"
        if test "$last_count" != "$new_count"
        then
                last_count=$new_count
-               printf "Rebasing (%d/%d)\r" $new_count $total
+               eval_gettext "Rebasing (\$new_count/\$total)"; printf "\r"
                test -z "$verbose" || echo
        fi
 }
@@ -143,20 +153,29 @@ reschedule_last_action () {
 }
 
 append_todo_help () {
-       git stripspace --comment-lines >>"$todo" <<\EOF
-
+       gettext "
 Commands:
  p, pick = use commit
  r, reword = use commit, but edit the commit message
  e, edit = use commit, but stop for amending
  s, squash = use commit, but meld into previous commit
- f, fixup = like "squash", but discard this commit's log message
+ f, fixup = like \"squash\", but discard this commit's log message
  x, exec = run command (the rest of the line) using shell
+ d, drop = remove commit
 
 These lines can be re-ordered; they are executed from top to bottom.
+" | git stripspace --comment-lines >>"$todo"
 
+       if test $(get_missing_commit_check_level) = error
+       then
+               gettext "
+Do not remove any line. Use 'drop' explicitly to remove a commit.
+" | git stripspace --comment-lines >>"$todo"
+       else
+               gettext "
 If you remove a line here THAT COMMIT WILL BE LOST.
-EOF
+" | git stripspace --comment-lines >>"$todo"
+       fi
 }
 
 make_patch () {
@@ -181,7 +200,6 @@ make_patch () {
 die_with_patch () {
        echo "$1" > "$state_dir"/stopped-sha
        make_patch "$1"
-       git rerere
        die "$2"
 }
 
@@ -190,18 +208,20 @@ exit_with_patch () {
        make_patch $1
        git rev-parse --verify HEAD > "$amend"
        gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
-       warn "You can amend the commit now, with"
-       warn
-       warn "  git commit --amend $gpg_sign_opt_quoted"
-       warn
-       warn "Once you are satisfied with your changes, run"
-       warn
-       warn "  git rebase --continue"
+       warn "$(eval_gettext "\
+You can amend the commit now, with
+
+       git commit --amend \$gpg_sign_opt_quoted
+
+Once you are satisfied with your changes, run
+
+       git rebase --continue")"
        warn
        exit $2
 }
 
 die_abort () {
+       apply_autostash
        rm -rf "$state_dir"
        die "$1"
 }
@@ -211,10 +231,12 @@ has_action () {
 }
 
 is_empty_commit() {
-       tree=$(git rev-parse -q --verify "$1"^{tree} 2>/dev/null ||
-               die "$1: not a commit that can be picked")
-       ptree=$(git rev-parse -q --verify "$1"^^{tree} 2>/dev/null ||
-               ptree=4b825dc642cb6eb9a060e54bf8d69288fbee4904)
+       tree=$(git rev-parse -q --verify "$1"^{tree} 2>/dev/null) || {
+               sha1=$1
+               die "$(eval_gettext "\$sha1: not a commit that can be picked")"
+       }
+       ptree=$(git rev-parse -q --verify "$1"^^{tree} 2>/dev/null) ||
+               ptree=4b825dc642cb6eb9a060e54bf8d69288fbee4904
        test "$tree" = "$ptree"
 }
 
@@ -250,7 +272,7 @@ pick_one () {
 
        case "$1" in -n) sha1=$2; ff= ;; *) sha1=$1 ;; esac
        case "$force_rebase" in '') ;; ?*) ff= ;; esac
-       output git rev-parse --verify $sha1 || die "Invalid commit name: $sha1"
+       output git rev-parse --verify $sha1 || die "$(eval_gettext "Invalid commit name: \$sha1")"
 
        if is_empty_commit "$sha1"
        then
@@ -292,7 +314,7 @@ pick_one_preserving_merges () {
                                git rev-parse HEAD > "$rewritten"/$current_commit
                        done <"$state_dir"/current-commit
                        rm "$state_dir"/current-commit ||
-                       die "Cannot write current commit's replacement sha1"
+                               die "$(gettext "Cannot write current commit's replacement sha1")"
                fi
        fi
 
@@ -344,9 +366,9 @@ pick_one_preserving_merges () {
        done
        case $fast_forward in
        t)
-               output warn "Fast-forward to $sha1"
+               output warn "$(eval_gettext "Fast-forward to \$sha1")"
                output git reset --hard $sha1 ||
-                       die "Cannot fast-forward to $sha1"
+                       die "$(eval_gettext "Cannot fast-forward to \$sha1")"
                ;;
        f)
                first_parent=$(expr "$new_parents" : ' \([^ ]*\)')
@@ -355,12 +377,12 @@ pick_one_preserving_merges () {
                then
                        # detach HEAD to current parent
                        output git checkout $first_parent 2> /dev/null ||
-                               die "Cannot move HEAD to $first_parent"
+                               die "$(eval_gettext "Cannot move HEAD to \$first_parent")"
                fi
 
                case "$new_parents" in
                ' '*' '*)
-                       test "a$1" = a-n && die "Refusing to squash a merge: $sha1"
+                       test "a$1" = a-n && die "$(eval_gettext "Refusing to squash a merge: \$sha1")"
 
                        # redo merge
                        author_script_content=$(get_author_ident_from_commit $sha1)
@@ -374,7 +396,7 @@ pick_one_preserving_merges () {
                                $merge_args $strategy_args -m "$msg_content" $new_parents'
                        then
                                printf "%s\n" "$msg_content" > "$GIT_DIR"/MERGE_MSG
-                               die_with_patch $sha1 "Error redoing merge $sha1"
+                               die_with_patch $sha1 "$(eval_gettext "Error redoing merge \$sha1")"
                        fi
                        echo "$sha1 $(git rev-parse HEAD^0)" >> "$rewritten_list"
                        ;;
@@ -382,40 +404,45 @@ pick_one_preserving_merges () {
                        output eval git cherry-pick \
                                ${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \
                                "$strategy_args" "$@" ||
-                               die_with_patch $sha1 "Could not pick $sha1"
+                               die_with_patch $sha1 "$(eval_gettext "Could not pick \$sha1")"
                        ;;
                esac
                ;;
        esac
 }
 
-nth_string () {
-       case "$1" in
-       *1[0-9]|*[04-9]) echo "$1"th;;
-       *1) echo "$1"st;;
-       *2) echo "$1"nd;;
-       *3) echo "$1"rd;;
-       esac
+this_nth_commit_message () {
+       n=$1
+       eval_gettext "This is the commit message #\${n}:"
+}
+
+skip_nth_commit_message () {
+       n=$1
+       eval_gettext "The commit message #\${n} will be skipped:"
 }
 
 update_squash_messages () {
        if test -f "$squash_msg"; then
                mv "$squash_msg" "$squash_msg".bak || exit
                count=$(($(sed -n \
-                       -e "1s/^. This is a combination of \(.*\) commits\./\1/p" \
+                       -e "1s/^$comment_char[^0-9]*\([0-9][0-9]*\).*/\1/p" \
                        -e "q" < "$squash_msg".bak)+1))
                {
-                       printf '%s\n' "$comment_char This is a combination of $count commits."
+                       printf '%s\n' "$comment_char $(eval_ngettext \
+                               "This is a combination of \$count commit." \
+                               "This is a combination of \$count commits." \
+                               $count)"
                        sed -e 1d -e '2,/^./{
                                /^$/d
                        }' <"$squash_msg".bak
                } >"$squash_msg"
        else
-               commit_message HEAD > "$fixup_msg" || die "Cannot write $fixup_msg"
+               commit_message HEAD >"$fixup_msg" ||
+               die "$(eval_gettext "Cannot write \$fixup_msg")"
                count=2
                {
-                       printf '%s\n' "$comment_char This is a combination of 2 commits."
-                       printf '%s\n' "$comment_char The first commit's message is:"
+                       printf '%s\n' "$comment_char $(gettext "This is a combination of 2 commits.")"
+                       printf '%s\n' "$comment_char $(gettext "This is the 1st commit message:")"
                        echo
                        cat "$fixup_msg"
                } >"$squash_msg"
@@ -424,13 +451,13 @@ update_squash_messages () {
        squash)
                rm -f "$fixup_msg"
                echo
-               printf '%s\n' "$comment_char This is the $(nth_string $count) commit message:"
+               printf '%s\n' "$comment_char $(this_nth_commit_message $count)"
                echo
                commit_message $2
                ;;
        fixup)
                echo
-               printf '%s\n' "$comment_char The $(nth_string $count) commit message will be skipped:"
+               printf '%s\n' "$comment_char $(skip_nth_commit_message $count)"
                echo
                # Change the space after the comment character to TAB:
                commit_message $2 | git stripspace --comment-lines | sed -e 's/ /       /'
@@ -449,12 +476,14 @@ peek_next_command () {
 # messages, effectively causing the combined commit to be used as the
 # new basis for any further squash/fixups.  Args: sha1 rest
 die_failed_squash() {
+       sha1=$1
+       rest=$2
        mv "$squash_msg" "$msg" || exit
        rm -f "$fixup_msg"
        cp "$msg" "$GIT_DIR"/MERGE_MSG || exit
        warn
-       warn "Could not apply $1... $2"
-       die_with_patch $1 ""
+       warn "$(eval_gettext "Could not apply \$sha1... \$rest")"
+       die_with_patch $sha1 ""
 }
 
 flush_rewritten_pending() {
@@ -478,6 +507,8 @@ record_in_rewritten() {
 }
 
 do_pick () {
+       sha1=$1
+       rest=$2
        if test "$(git rev-parse HEAD)" = "$squash_onto"
        then
                # Set the correct commit message and author info on the
@@ -489,15 +520,15 @@ do_pick () {
                # resolve before manually running git commit --amend then git
                # rebase --continue.
                git commit --allow-empty --allow-empty-message --amend \
-                          --no-post-rewrite -n -q -C $1 &&
-                       pick_one -n $1 &&
+                          --no-post-rewrite -n -q -C $sha1 &&
+                       pick_one -n $sha1 &&
                        git commit --allow-empty --allow-empty-message \
-                                  --amend --no-post-rewrite -n -q -C $1 \
+                                  --amend --no-post-rewrite -n -q -C $sha1 \
                                   ${gpg_sign_opt:+"$gpg_sign_opt"} ||
-                       die_with_patch $1 "Could not apply $1... $2"
+                                  die_with_patch $sha1 "$(eval_gettext "Could not apply \$sha1... \$rest")"
        else
-               pick_one $1 ||
-                       die_with_patch $1 "Could not apply $1... $2"
+               pick_one $sha1 ||
+                       die_with_patch $sha1 "$(eval_gettext "Could not apply \$sha1... \$rest")"
        fi
 }
 
@@ -505,7 +536,11 @@ do_next () {
        rm -f "$msg" "$author_script" "$amend" "$state_dir"/stopped-sha || exit
        read -r command sha1 rest < "$todo"
        case "$command" in
-       "$comment_char"*|''|noop)
+       "$comment_char"*|''|noop|drop|d)
+               mark_action_done
+               ;;
+       "$cr")
+               # Work around CR left by "read" (e.g. with Git for Windows' Bash).
                mark_action_done
                ;;
        pick|p)
@@ -521,10 +556,11 @@ do_next () {
                mark_action_done
                do_pick $sha1 "$rest"
                git commit --amend --no-post-rewrite ${gpg_sign_opt:+"$gpg_sign_opt"} || {
-                       warn "Could not amend commit after successfully picking $sha1... $rest"
-                       warn "This is most likely due to an empty commit message, or the pre-commit hook"
-                       warn "failed. If the pre-commit hook failed, you may need to resolve the issue before"
-                       warn "you are able to reword the commit."
+                       warn "$(eval_gettext "\
+Could not amend commit after successfully picking \$sha1... \$rest
+This is most likely due to an empty commit message, or the pre-commit hook
+failed. If the pre-commit hook failed, you may need to resolve the issue before
+you are able to reword the commit.")"
                        exit_with_patch $sha1 1
                }
                record_in_rewritten $sha1
@@ -534,7 +570,8 @@ do_next () {
 
                mark_action_done
                do_pick $sha1 "$rest"
-               warn "Stopped at $sha1... $rest"
+               sha1_abbrev=$(git rev-parse --short $sha1)
+               warn "$(eval_gettext "Stopped at \$sha1_abbrev... \$rest")"
                exit_with_patch $sha1 0
                ;;
        squash|s|fixup|f)
@@ -549,7 +586,7 @@ do_next () {
                comment_for_reflog $squash_style
 
                test -f "$done" && has_action "$done" ||
-                       die "Cannot '$squash_style' without a previous commit"
+                       die "$(eval_gettext "Cannot '\$squash_style' without a previous commit")"
 
                mark_action_done
                update_squash_messages $squash_style $sha1
@@ -591,21 +628,22 @@ do_next () {
        x|"exec")
                read -r command rest < "$todo"
                mark_action_done
-               printf 'Executing: %s\n' "$rest"
-               ${SHELL:-@SHELL_PATH@} -c "$rest" # Actual execution
+               eval_gettextln "Executing: \$rest"
+               "${SHELL:-@SHELL_PATH@}" -c "$rest" # Actual execution
                status=$?
                # Run in subshell because require_clean_work_tree can die.
                dirty=f
                (require_clean_work_tree "rebase" 2>/dev/null) || dirty=t
                if test "$status" -ne 0
                then
-                       warn "Execution failed: $rest"
+                       warn "$(eval_gettext "Execution failed: \$rest")"
                        test "$dirty" = f ||
-                       warn "and made changes to the index and/or the working tree"
+                               warn "$(gettext "and made changes to the index and/or the working tree")"
 
-                       warn "You can fix the problem, and then run"
-                       warn
-                       warn "  git rebase --continue"
+                       warn "$(gettext "\
+You can fix the problem, and then run
+
+       git rebase --continue")"
                        warn
                        if test $status -eq 127         # command not found
                        then
@@ -614,18 +652,20 @@ do_next () {
                        exit "$status"
                elif test "$dirty" = t
                then
-                       warn "Execution succeeded: $rest"
-                       warn "but left changes to the index and/or the working tree"
-                       warn "Commit or stash your changes, and then run"
-                       warn
-                       warn "  git rebase --continue"
+                       # TRANSLATORS: after these lines is a command to be issued by the user
+                       warn "$(eval_gettext "\
+Execution succeeded: \$rest
+but left changes to the index and/or the working tree
+Commit or stash your changes, and then run
+
+       git rebase --continue")"
                        warn
                        exit 1
                fi
                ;;
        *)
-               warn "Unknown command: $command $sha1 $rest"
-               fixtodo="Please fix this using 'git rebase --edit-todo'."
+               warn "$(eval_gettext "Unknown command: \$command \$sha1 \$rest")"
+               fixtodo="$(gettext "Please fix this using 'git rebase --edit-todo'.")"
                if git rev-parse --verify -q "$sha1" >/dev/null
                then
                        die_with_patch $sha1 "$fixtodo"
@@ -660,7 +700,7 @@ do_next () {
                "$hook" rebase < "$rewritten_list"
                true # we don't care if this hook failed
        fi &&
-       warn "Successfully rebased and updated $head_name."
+               warn "$(eval_gettext "Successfully rebased and updated \$head_name.")"
 
        return 1 # not failure; just to break the do_rest loop
 }
@@ -707,7 +747,7 @@ skip_unnecessary_picks () {
                record_in_rewritten "$onto"
                ;;
        esac ||
-       die "Could not skip unnecessary pick commands"
+               die "$(gettext "Could not skip unnecessary pick commands")"
 }
 
 transform_todo_ids () {
@@ -719,8 +759,8 @@ transform_todo_ids () {
                        # that do not have a SHA-1 at the beginning of $rest.
                        ;;
                *)
-                       sha1=$(git rev-parse --verify --quiet "$@" ${rest%% *}) &&
-                       rest="$sha1 ${rest#* }"
+                       sha1=$(git rev-parse --verify --quiet "$@" ${rest%%[     ]*}) &&
+                       rest="$sha1 ${rest#*[    ]}"
                        ;;
                esac
                printf '%s\n' "$command${rest:+ }$rest"
@@ -740,10 +780,15 @@ collapse_todo_ids() {
 # "pick sha1 fixup!/squash! msg" appears in it so that the latter
 # comes immediately after the former, and change "pick" to
 # "fixup"/"squash".
+#
+# Note that if the config has specified a custom instruction format
+# each log message will be re-retrieved in order to normalize the
+# autosquash arrangement
 rearrange_squash () {
        # extract fixup!/squash! lines and resolve any referenced sha1's
        while read -r pick sha1 message
        do
+               test -z "${format}" || message=$(git log -n 1 --format="%s" ${sha1})
                case "$message" in
                "squash! "*|"fixup! "*)
                        action="${message%%!*}"
@@ -785,6 +830,7 @@ rearrange_squash () {
                *" $sha1 "*) continue ;;
                esac
                printf '%s\n' "$pick $sha1 $message"
+               test -z "${format}" || message=$(git log -n 1 --format="%s" ${sha1})
                used="$used$sha1 "
                while read -r squash action msg_prefix msg_content
                do
@@ -802,8 +848,13 @@ rearrange_squash () {
                                case "$message" in "$msg_content"*) emit=1;; esac ;;
                        esac
                        if test $emit = 1; then
-                               real_prefix=$(echo "$msg_prefix" | sed "s/,/! /g")
-                               printf '%s\n' "$action $squash ${real_prefix}$msg_content"
+                               if test -n "${format}"
+                               then
+                                       msg_content=$(git log -n 1 --format="${format}" ${squash})
+                               else
+                                       msg_content="$(echo "$msg_prefix" | sed "s/,/! /g")$msg_content"
+                               fi
+                               printf '%s\n' "$action $squash $msg_content"
                                used="$used$squash "
                        fi
                done <"$1.sq"
@@ -833,19 +884,195 @@ 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 number of the input
+# $3: the input filename
+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
+               line="$(sed -n -e "${2}p" "$3")"
+               warn "$(eval_gettext "\
+Warning: the SHA-1 is missing or isn't a commit in the following line:
+ - \$line")"
+               warn
+       fi
+
+       return $badsha
+}
+
+# prints the bad commits and bad commands
+# from the todolist in stdin
+check_bad_cmd_and_sha () {
+       retval=0
+       lineno=0
+       while read -r command rest
+       do
+               lineno=$(( $lineno + 1 ))
+               case $command in
+               "$comment_char"*|''|noop|x|exec)
+                       # Doesn't expect a SHA-1
+                       ;;
+               "$cr")
+                       # Work around CR left by "read" (e.g. with Git for
+                       # Windows' Bash).
+                       ;;
+               pick|p|drop|d|reword|r|edit|e|squash|s|fixup|f)
+                       if ! check_commit_sha "${rest%%[        ]*}" "$lineno" "$1"
+                       then
+                               retval=1
+                       fi
+                       ;;
+               *)
+                       line="$(sed -n -e "${lineno}p" "$1")"
+                       warn "$(eval_gettext "\
+Warning: the command isn't recognized in the following line:
+ - \$line")"
+                       warn
+                       retval=1
+                       ;;
+               esac
+       done <"$1"
+       return $retval
+}
+
+# Print the list of the SHA-1 of the commits
+# from stdin to stdout
+todo_list_to_sha_list () {
+       git stripspace --strip-comments |
+       while read -r command sha1 rest
+       do
+               case $command in
+               "$comment_char"*|''|noop|x|"exec")
+                       ;;
+               *)
+                       long_sha=$(git rev-list --no-walk "$sha1" 2>/dev/null)
+                       printf "%s\n" "$long_sha"
+                       ;;
+               esac
+       done
+}
+
+# Use warn for each line in stdin
+warn_lines () {
+       while read -r line
+       do
+               warn " - $line"
+       done
+}
+
+# Switch to the branch in $into and notify it in the reflog
+checkout_onto () {
+       GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name"
+       output git checkout $onto || die_abort "$(gettext "could not detach HEAD")"
+       git update-ref ORIG_HEAD $orig_head
+}
+
+get_missing_commit_check_level () {
+       check_level=$(git config --get rebase.missingCommitsCheck)
+       check_level=${check_level:-ignore}
+       # Don't be case sensitive
+       printf '%s' "$check_level" | tr 'A-Z' 'a-z'
+}
+
+# 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
+
+       check_level=$(get_missing_commit_check_level)
+
+       case "$check_level" in
+       warn|error)
+               # Get the SHA-1 of the commits
+               todo_list_to_sha_list <"$todo".backup >"$todo".oldsha1
+               todo_list_to_sha_list <"$todo" >"$todo".newsha1
+
+               # Sort the SHA-1 and compare them
+               sort -u "$todo".oldsha1 >"$todo".oldsha1+
+               mv "$todo".oldsha1+ "$todo".oldsha1
+               sort -u "$todo".newsha1 >"$todo".newsha1+
+               mv "$todo".newsha1+ "$todo".newsha1
+               comm -2 -3 "$todo".oldsha1 "$todo".newsha1 >"$todo".miss
+
+               # Warn about missing commits
+               if test -s "$todo".miss
+               then
+                       test "$check_level" = error && raise_error=t
+
+                       warn "$(gettext "\
+Warning: some commits may have been dropped accidentally.
+Dropped commits (newer to older):")"
+
+                       # Make the list user-friendly and display
+                       opt="--no-walk=sorted --format=oneline --abbrev-commit --stdin"
+                       git rev-list $opt <"$todo".miss | warn_lines
+
+                       warn "$(gettext "\
+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.")"
+                       warn
+               fi
+               ;;
+       ignore)
+               ;;
+       *)
+               warn "$(eval_gettext "Unrecognized setting \$check_level for option rebase.missingCommitsCheck. Ignoring.")"
+               ;;
+       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
+               # rebase: this way git rebase --continue
+               # will work correctly as it expects HEAD to be
+               # placed before the commit of the next action
+               checkout_onto
+
+               warn "$(gettext "You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'.")"
+               die "$(gettext "Or you can abort the rebase with 'git rebase --abort'.")"
+       fi
+}
+
 # The whole contents of this file is run by dot-sourcing it from
 # inside a shell function.  It used to be that "return"s we see
 # below were not inside any function, and expected to return
 # to the function that dot-sourced us.
 #
-# However, FreeBSD /bin/sh misbehaves on such a construct and
-# continues to run the statements that follow such a "return".
+# However, older (9.x) versions of FreeBSD /bin/sh misbehave on such a
+# construct and continue to run the statements that follow such a "return".
 # As a work-around, we introduce an extra layer of a function
 # here, and immediately call it after defining it.
 git_rebase__interactive () {
 
 case "$action" in
 continue)
+       if test ! -d "$rewritten"
+       then
+               exec git rebase--helper ${force_rebase:+--no-ff} --continue
+       fi
        # do we have anything to commit?
        if git diff-index --cached --quiet HEAD --
        then
@@ -853,41 +1080,43 @@ continue)
 
                test ! -f "$GIT_DIR"/CHERRY_PICK_HEAD ||
                rm "$GIT_DIR"/CHERRY_PICK_HEAD ||
-               die "Could not remove CHERRY_PICK_HEAD"
+               die "$(gettext "Could not remove CHERRY_PICK_HEAD")"
        else
                if ! test -f "$author_script"
                then
                        gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
-                       die "You have staged changes in your working tree. If these changes are meant to be
+                       die "$(eval_gettext "\
+You have staged changes in your working tree.
+If these changes are meant to be
 squashed into the previous commit, run:
 
-  git commit --amend $gpg_sign_opt_quoted
+  git commit --amend \$gpg_sign_opt_quoted
 
 If they are meant to go into a new commit, run:
 
-  git commit $gpg_sign_opt_quoted
+  git commit \$gpg_sign_opt_quoted
 
-In both case, once you're done, continue with:
+In both cases, once you're done, continue with:
 
   git rebase --continue
-"
+")"
                fi
                . "$author_script" ||
-                       die "Error trying to find the author identity to amend commit"
+                       die "$(gettext "Error trying to find the author identity to amend commit")"
                if test -f "$amend"
                then
                        current_head=$(git rev-parse --verify HEAD)
                        test "$current_head" = $(cat "$amend") ||
-                       die "\
-You have uncommitted changes in your working tree. Please, commit them
-first and then run 'git rebase --continue' again."
+                       die "$(gettext "\
+You have uncommitted changes in your working tree. Please commit them
+first and then run 'git rebase --continue' again.")"
                        do_with_author git commit --amend --no-verify -F "$msg" -e \
                                ${gpg_sign_opt:+"$gpg_sign_opt"} ||
-                               die "Could not commit staged changes."
+                               die "$(gettext "Could not commit staged changes.")"
                else
                        do_with_author git commit --no-verify -F "$msg" -e \
                                ${gpg_sign_opt:+"$gpg_sign_opt"} ||
-                               die "Could not commit staged changes."
+                               die "$(gettext "Could not commit staged changes.")"
                fi
        fi
 
@@ -903,6 +1132,10 @@ first and then run 'git rebase --continue' again."
 skip)
        git rerere clear
 
+       if test ! -d "$rewritten"
+       then
+               exec git rebase--helper ${force_rebase:+--no-ff} --continue
+       fi
        do_rest
        return 0
        ;;
@@ -911,40 +1144,36 @@ edit-todo)
        mv -f "$todo".new "$todo"
        collapse_todo_ids
        append_todo_help
-       git stripspace --comment-lines >>"$todo" <<\EOF
-
+       gettext "
 You are editing the todo file of an ongoing interactive rebase.
 To continue rebase after editing, run:
     git rebase --continue
 
-EOF
+" | git stripspace --comment-lines >>"$todo"
 
        git_sequence_editor "$todo" ||
-               die "Could not execute editor"
+               die "$(gettext "Could not execute editor")"
        expand_todo_ids
 
        exit
        ;;
 esac
 
-git var GIT_COMMITTER_IDENT >/dev/null ||
-       die "You need to set your committer info first"
-
 comment_for_reflog start
 
 if test ! -z "$switch_to"
 then
        GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to"
        output git checkout "$switch_to" -- ||
-       die "Could not checkout $switch_to"
+               die "$(eval_gettext "Could not checkout \$switch_to")"
 
        comment_for_reflog start
 fi
 
-orig_head=$(git rev-parse --verify HEAD) || die "No HEAD?"
-mkdir -p "$state_dir" || die "Could not create temporary $state_dir"
+orig_head=$(git rev-parse --verify HEAD) || die "$(gettext "No HEAD?")"
+mkdir -p "$state_dir" || die "$(eval_gettext "Could not create temporary \$state_dir")"
 
-: > "$state_dir"/interactive || die "Could not mark as interactive"
+: > "$state_dir"/interactive || die "$(gettext "Could not mark as interactive")"
 write_basic_state
 if test t = "$preserve_merges"
 then
@@ -954,12 +1183,12 @@ then
                for c in $(git merge-base --all $orig_head $upstream)
                do
                        echo $onto > "$rewritten"/$c ||
-                               die "Could not init rewritten commits"
+                               die "$(gettext "Could not init rewritten commits")"
                done
        else
                mkdir "$rewritten" &&
                echo $onto > "$rewritten"/root ||
-                       die "Could not init rewritten commits"
+                       die "$(gettext "Could not init rewritten commits")"
        fi
        # No cherry-pick because our first pass is to determine
        # parents to rewrite and skipping dropped commits would
@@ -981,7 +1210,10 @@ else
        revisions=$onto...$orig_head
        shortrevisions=$shorthead
 fi
-git rev-list $merges_option --pretty=oneline --reverse --left-right --topo-order \
+format=$(git config --get rebase.instructionFormat)
+# the 'rev-list .. | sed' requires %m to parse; the instruction requires %H to parse
+git rev-list $merges_option --format="%m%H ${format:-%s}" \
+       --reverse --left-right --topo-order \
        $revisions ${restrict_revision+^$restrict_revision} | \
        sed -n "s/^>//p" |
 while read -r sha1 rest
@@ -1031,7 +1263,8 @@ then
        git rev-list $revisions |
        while read rev
        do
-               if test -f "$rewritten"/$rev && test "$(sane_grep "$rev" "$state_dir"/not-cherry-picks)" = ""
+               if test -f "$rewritten"/$rev &&
+                  ! sane_grep "$rev" "$state_dir"/not-cherry-picks >/dev/null
                then
                        # Use -f2 because if rev-list is telling us this commit is
                        # not worthwhile, we don't want to track its multiple heads,
@@ -1054,18 +1287,20 @@ todocount=${todocount##* }
 
 cat >>"$todo" <<EOF
 
-$comment_char Rebase $shortrevisions onto $shortonto ($todocount command(s))
+$comment_char $(eval_ngettext \
+       "Rebase \$shortrevisions onto \$shortonto (\$todocount command)" \
+       "Rebase \$shortrevisions onto \$shortonto (\$todocount commands)" \
+       "$todocount")
 EOF
 append_todo_help
-git stripspace --comment-lines >>"$todo" <<\EOF
-
+gettext "
 However, if you remove everything, the rebase will be aborted.
 
-EOF
+" | git stripspace --comment-lines >>"$todo"
 
 if test -z "$keep_empty"
 then
-       printf '%s\n' "$comment_char Note that empty commits are commented out" >>"$todo"
+       printf '%s\n' "$comment_char $(gettext "Note that empty commits are commented out")" >>"$todo"
 fi
 
 
@@ -1075,18 +1310,23 @@ has_action "$todo" ||
 cp "$todo" "$todo".backup
 collapse_todo_ids
 git_sequence_editor "$todo" ||
-       die_abort "Could not execute editor"
+       die_abort "$(gettext "Could not execute editor")"
 
 has_action "$todo" ||
        return 2
 
+check_todo_list
+
 expand_todo_ids
 
 test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks
 
-GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name"
-output git checkout $onto || die_abort "could not detach HEAD"
-git update-ref ORIG_HEAD $orig_head
+checkout_onto
+if test -z "$rebase_root" && test ! -d "$rewritten"
+then
+       require_clean_work_tree "rebase"
+       exec git rebase--helper ${force_rebase:+--no-ff} --continue
+fi
 do_rest
 
 }