diff options
Diffstat (limited to 'git-rebase--interactive.sh')
-rw-r--r-- | git-rebase--interactive.sh | 503 |
1 files changed, 381 insertions, 122 deletions
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 0564ad41f2..ded4595638 100644 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -77,17 +77,18 @@ 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 @@ -127,7 +128,7 @@ mark_action_done () { 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 +144,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 +191,6 @@ make_patch () { die_with_patch () { echo "$1" > "$state_dir"/stopped-sha make_patch "$1" - git rerere die "$2" } @@ -190,18 +199,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 +222,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 +263,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 +305,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 +357,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 +368,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 +387,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,19 +395,59 @@ 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;; +this_nth_commit_message () { + n=$1 + case "$n" in + 1) gettext "This is the 1st commit message:";; + 2) gettext "This is the 2nd commit message:";; + 3) gettext "This is the 3rd commit message:";; + 4) gettext "This is the 4th commit message:";; + 5) gettext "This is the 5th commit message:";; + 6) gettext "This is the 6th commit message:";; + 7) gettext "This is the 7th commit message:";; + 8) gettext "This is the 8th commit message:";; + 9) gettext "This is the 9th commit message:";; + 10) gettext "This is the 10th commit message:";; + # TRANSLATORS: if the language you are translating into + # doesn't allow you to compose a sentence in this fashion, + # consider translating as if this and the following few strings + # were "This is the commit message ${n}:" + *1[0-9]|*[04-9]) eval_gettext "This is the \${n}th commit message:";; + *1) eval_gettext "This is the \${n}st commit message:";; + *2) eval_gettext "This is the \${n}nd commit message:";; + *3) eval_gettext "This is the \${n}rd commit message:";; + *) eval_gettext "This is the commit message \${n}:";; + esac +} +skip_nth_commit_message () { + n=$1 + case "$n" in + 1) gettext "The 1st commit message will be skipped:";; + 2) gettext "The 2nd commit message will be skipped:";; + 3) gettext "The 3rd commit message will be skipped:";; + 4) gettext "The 4th commit message will be skipped:";; + 5) gettext "The 5th commit message will be skipped:";; + 6) gettext "The 6th commit message will be skipped:";; + 7) gettext "The 7th commit message will be skipped:";; + 8) gettext "The 8th commit message will be skipped:";; + 9) gettext "The 9th commit message will be skipped:";; + 10) gettext "The 10th commit message will be skipped:";; + # TRANSLATORS: if the language you are translating into + # doesn't allow you to compose a sentence in this fashion, + # consider translating as if this and the following few strings + # were "The commit message ${n} will be skipped:" + *1[0-9]|*[04-9]) eval_gettext "The \${n}th commit message will be skipped:";; + *1) eval_gettext "The \${n}st commit message will be skipped:";; + *2) eval_gettext "The \${n}nd commit message will be skipped:";; + *3) eval_gettext "The \${n}rd commit message will be skipped:";; + *) eval_gettext "The commit message \${n} will be skipped:";; esac } @@ -402,20 +455,23 @@ 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]*\).*/\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 "$(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 +480,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 +505,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 +536,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 +549,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 +565,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 +585,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 +599,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 +615,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 +657,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 +681,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" @@ -655,12 +724,12 @@ do_next () { git notes copy --for-rewrite=rebase < "$rewritten_list" || true # we don't care if this copying failed } && - if test -x "$GIT_DIR"/hooks/post-rewrite && - test -s "$rewritten_list"; then - "$GIT_DIR"/hooks/post-rewrite rebase < "$rewritten_list" + hook="$(git rev-parse --git-path hooks/post-rewrite)" + if test -x "$hook" && test -s "$rewritten_list"; then + "$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 +776,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 +788,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 +809,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 +859,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 +877,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,13 +913,185 @@ 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'.")" + 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 () { @@ -853,41 +1105,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: 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 @@ -911,16 +1165,15 @@ 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 @@ -928,7 +1181,7 @@ EOF esac git var GIT_COMMITTER_IDENT >/dev/null || - die "You need to set your committer info first" + die "$(gettext "You need to set your committer info first")" comment_for_reflog start @@ -936,15 +1189,15 @@ 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 +1207,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 +1234,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 +1287,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 +1311,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 +1334,18 @@ 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 do_rest } |