Jonathan Nieder | 11d6214 | 2013-11-25 13:03:52 -0800 | [diff] [blame] | 1 | # This shell script fragment is sourced by git-rebase to implement |
| 2 | # its interactive mode. "git rebase --interactive" makes it easy |
| 3 | # to fix up commits in the middle of a series and rearrange commits. |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 4 | # |
| 5 | # Copyright (c) 2006 Johannes E. Schindelin |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 6 | # |
| 7 | # The original idea comes from Eric W. Biederman, in |
| 8 | # http://article.gmane.org/gmane.comp.version-control.git/22407 |
Martin von Zweigbergk | 572a7c5 | 2012-06-26 07:51:54 -0700 | [diff] [blame] | 9 | # |
Michael Haggerty | 80883bb | 2010-01-14 06:54:45 +0100 | [diff] [blame] | 10 | # The file containing rebase commands, comments, and empty lines. |
| 11 | # This file is created by "git rebase -i" then edited by the user. As |
| 12 | # the lines are processed, they are removed from the front of this |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 13 | # file and written to the tail of $done. |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 14 | todo="$state_dir"/git-rebase-todo |
Michael Haggerty | 80883bb | 2010-01-14 06:54:45 +0100 | [diff] [blame] | 15 | |
| 16 | # The rebase command lines that have already been processed. A line |
| 17 | # is moved here when it is first handled, before any associated user |
| 18 | # actions. |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 19 | done="$state_dir"/done |
Michael Haggerty | 80883bb | 2010-01-14 06:54:45 +0100 | [diff] [blame] | 20 | |
| 21 | # The commit message that is planned to be used for any changes that |
| 22 | # need to be committed following a user interaction. |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 23 | msg="$state_dir"/message |
Michael Haggerty | 80883bb | 2010-01-14 06:54:45 +0100 | [diff] [blame] | 24 | |
| 25 | # The file into which is accumulated the suggested commit message for |
| 26 | # squash/fixup commands. When the first of a series of squash/fixups |
| 27 | # is seen, the file is created and the commit message from the |
| 28 | # previous commit and from the first squash/fixup commit are written |
| 29 | # to it. The commit message for each subsequent squash/fixup commit |
| 30 | # is appended to the file as it is processed. |
| 31 | # |
| 32 | # The first line of the file is of the form |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 33 | # # This is a combination of $count commits. |
| 34 | # where $count is the number of commits whose messages have been |
Michael Haggerty | 80883bb | 2010-01-14 06:54:45 +0100 | [diff] [blame] | 35 | # written to the file so far (including the initial "pick" commit). |
| 36 | # Each time that a commit message is processed, this line is read and |
| 37 | # updated. It is deleted just before the combined commit is made. |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 38 | squash_msg="$state_dir"/message-squash |
Michael Haggerty | 80883bb | 2010-01-14 06:54:45 +0100 | [diff] [blame] | 39 | |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 40 | # If the current series of squash/fixups has not yet included a squash |
| 41 | # command, then this file exists and holds the commit message of the |
| 42 | # original "pick" commit. (If the series ends without a "squash" |
| 43 | # command, then this can be used as the commit message of the combined |
| 44 | # commit without opening the editor.) |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 45 | fixup_msg="$state_dir"/message-fixup |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 46 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 47 | # $rewritten is the name of a directory containing files for each |
| 48 | # commit that is reachable by at least one merge base of $head and |
| 49 | # $upstream. They are not necessarily rewritten, but their children |
Michael Haggerty | 80883bb | 2010-01-14 06:54:45 +0100 | [diff] [blame] | 50 | # might be. This ensures that commits on merged, but otherwise |
| 51 | # unrelated side branches are left alone. (Think "X" in the man page's |
| 52 | # example.) |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 53 | rewritten="$state_dir"/rewritten |
Michael Haggerty | 80883bb | 2010-01-14 06:54:45 +0100 | [diff] [blame] | 54 | |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 55 | dropped="$state_dir"/dropped |
Michael Haggerty | 0aac0de | 2010-01-14 06:54:46 +0100 | [diff] [blame] | 56 | |
Zoltan Klinger | b71dc3e | 2013-04-25 19:28:54 +1000 | [diff] [blame] | 57 | end="$state_dir"/end |
| 58 | msgnum="$state_dir"/msgnum |
| 59 | |
Michael Haggerty | 0aac0de | 2010-01-14 06:54:46 +0100 | [diff] [blame] | 60 | # A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and |
| 61 | # GIT_AUTHOR_DATE that will be used for the commit that is currently |
| 62 | # being rebased. |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 63 | author_script="$state_dir"/author-script |
Michael Haggerty | 0aac0de | 2010-01-14 06:54:46 +0100 | [diff] [blame] | 64 | |
Michael Haggerty | a4049ae | 2010-01-14 06:54:47 +0100 | [diff] [blame] | 65 | # When an "edit" rebase command is being processed, the SHA1 of the |
| 66 | # commit to be edited is recorded in this file. When "git rebase |
| 67 | # --continue" is executed, if there are any staged changes then they |
| 68 | # will be amended to the HEAD commit, but only provided the HEAD |
| 69 | # commit is still the commit to be edited. When any other rebase |
| 70 | # command is processed, this file is deleted. |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 71 | amend="$state_dir"/amend |
Michael Haggerty | a4049ae | 2010-01-14 06:54:47 +0100 | [diff] [blame] | 72 | |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 73 | # For the post-rewrite hook, we make a list of rewritten commits and |
| 74 | # their new sha1s. The rewritten-pending list keeps the sha1s of |
| 75 | # commits that have been processed, but not committed yet, |
| 76 | # e.g. because they are waiting for a 'squash' command. |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 77 | rewritten_list="$state_dir"/rewritten-list |
| 78 | rewritten_pending="$state_dir"/rewritten-pending |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 79 | |
Junio C Hamano | 39743cf | 2015-10-28 15:54:48 +0100 | [diff] [blame] | 80 | # Work around Git for Windows' Bash whose "read" does not strip CRLF |
| 81 | # and leaves CR at the end instead. |
| 82 | cr=$(printf "\015") |
| 83 | |
Fabian Ruch | 040fd39 | 2015-12-11 21:30:36 +0100 | [diff] [blame] | 84 | strategy_args=${strategy:+--strategy=$strategy} |
Jeff King | 8e98b35 | 2016-05-10 17:07:10 -0400 | [diff] [blame] | 85 | test -n "$strategy_opts" && |
Fabian Ruch | 040fd39 | 2015-12-11 21:30:36 +0100 | [diff] [blame] | 86 | eval ' |
| 87 | for strategy_opt in '"$strategy_opts"' |
| 88 | do |
| 89 | strategy_args="$strategy_args -X$(git rev-parse --sq-quote "${strategy_opt#--}")" |
| 90 | done |
| 91 | ' |
Arnaud Fontaine | db2b3b8 | 2013-07-02 17:05:48 +0900 | [diff] [blame] | 92 | |
Martin von Zweigbergk | 89c7ae9 | 2011-02-06 13:43:49 -0500 | [diff] [blame] | 93 | GIT_CHERRY_PICK_HELP="$resolvemsg" |
Wincent Colaiuta | 804c717 | 2007-11-28 00:06:36 -0800 | [diff] [blame] | 94 | export GIT_CHERRY_PICK_HELP |
| 95 | |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 96 | comment_char=$(git config --get core.commentchar 2>/dev/null | cut -c1) |
| 97 | : ${comment_char:=#} |
| 98 | |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 99 | warn () { |
Brandon Casey | 938791c | 2010-07-22 14:15:11 -0500 | [diff] [blame] | 100 | printf '%s\n' "$*" >&2 |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 101 | } |
| 102 | |
Michael Haggerty | ee0a4af | 2010-01-14 06:54:51 +0100 | [diff] [blame] | 103 | # Output the commit message for the specified commit. |
| 104 | commit_message () { |
| 105 | git cat-file commit "$1" | sed "1,/^$/d" |
| 106 | } |
| 107 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 108 | orig_reflog_action="$GIT_REFLOG_ACTION" |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 109 | |
| 110 | comment_for_reflog () { |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 111 | case "$orig_reflog_action" in |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 112 | ''|rebase*) |
| 113 | GIT_REFLOG_ACTION="rebase -i ($1)" |
| 114 | export GIT_REFLOG_ACTION |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 115 | ;; |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 116 | esac |
| 117 | } |
| 118 | |
Junio C Hamano | 4e67387 | 2008-01-14 20:01:21 -0800 | [diff] [blame] | 119 | last_count= |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 120 | mark_action_done () { |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 121 | sed -e 1q < "$todo" >> "$done" |
| 122 | sed -e 1d < "$todo" >> "$todo".new |
| 123 | mv -f "$todo".new "$todo" |
Johannes Sixt | d949751 | 2016-07-28 19:47:23 +0200 | [diff] [blame] | 124 | new_count=$(( $(git stripspace --strip-comments <"$done" | wc -l) )) |
Zoltan Klinger | b71dc3e | 2013-04-25 19:28:54 +1000 | [diff] [blame] | 125 | echo $new_count >"$msgnum" |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 126 | total=$(($new_count + $(git stripspace --strip-comments <"$todo" | wc -l))) |
Zoltan Klinger | b71dc3e | 2013-04-25 19:28:54 +1000 | [diff] [blame] | 127 | echo $total >"$end" |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 128 | if test "$last_count" != "$new_count" |
Junio C Hamano | 4e67387 | 2008-01-14 20:01:21 -0800 | [diff] [blame] | 129 | then |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 130 | last_count=$new_count |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 131 | eval_gettext "Rebasing (\$new_count/\$total)"; printf "\r" |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 132 | test -z "$verbose" || echo |
Junio C Hamano | 4e67387 | 2008-01-14 20:01:21 -0800 | [diff] [blame] | 133 | fi |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 134 | } |
| 135 | |
Phil Hord | 8cbc57c | 2015-04-28 18:55:20 -0400 | [diff] [blame] | 136 | # Put the last action marked done at the beginning of the todo list |
| 137 | # again. If there has not been an action marked done yet, leave the list of |
| 138 | # items on the todo list unchanged. |
| 139 | reschedule_last_action () { |
| 140 | tail -n 1 "$done" | cat - "$todo" >"$todo".new |
| 141 | sed -e \$d <"$done" >"$done".new |
| 142 | mv -f "$todo".new "$todo" |
| 143 | mv -f "$done".new "$done" |
| 144 | } |
| 145 | |
Andrew Wong | fcc5ef1 | 2012-09-17 21:28:08 -0400 | [diff] [blame] | 146 | append_todo_help () { |
Vasco Almeida | b8fc9e4 | 2016-06-17 20:21:04 +0000 | [diff] [blame] | 147 | gettext " |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 148 | Commands: |
| 149 | p, pick = use commit |
| 150 | r, reword = use commit, but edit the commit message |
| 151 | e, edit = use commit, but stop for amending |
| 152 | s, squash = use commit, but meld into previous commit |
Vasco Almeida | b8fc9e4 | 2016-06-17 20:21:04 +0000 | [diff] [blame] | 153 | f, fixup = like \"squash\", but discard this commit's log message |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 154 | x, exec = run command (the rest of the line) using shell |
Galan Rémi | c9266d5 | 2015-06-29 22:20:30 +0200 | [diff] [blame] | 155 | d, drop = remove commit |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 156 | |
| 157 | These lines can be re-ordered; they are executed from top to bottom. |
Vasco Almeida | b8fc9e4 | 2016-06-17 20:21:04 +0000 | [diff] [blame] | 158 | " | git stripspace --comment-lines >>"$todo" |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 159 | |
Galan Rémi | 3707995 | 2015-06-29 22:20:31 +0200 | [diff] [blame] | 160 | if test $(get_missing_commit_check_level) = error |
| 161 | then |
Vasco Almeida | b8fc9e4 | 2016-06-17 20:21:04 +0000 | [diff] [blame] | 162 | gettext " |
Galan Rémi | 3707995 | 2015-06-29 22:20:31 +0200 | [diff] [blame] | 163 | Do not remove any line. Use 'drop' explicitly to remove a commit. |
Vasco Almeida | b8fc9e4 | 2016-06-17 20:21:04 +0000 | [diff] [blame] | 164 | " | git stripspace --comment-lines >>"$todo" |
Galan Rémi | 3707995 | 2015-06-29 22:20:31 +0200 | [diff] [blame] | 165 | else |
Vasco Almeida | b8fc9e4 | 2016-06-17 20:21:04 +0000 | [diff] [blame] | 166 | gettext " |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 167 | If you remove a line here THAT COMMIT WILL BE LOST. |
Vasco Almeida | b8fc9e4 | 2016-06-17 20:21:04 +0000 | [diff] [blame] | 168 | " | git stripspace --comment-lines >>"$todo" |
Galan Rémi | 3707995 | 2015-06-29 22:20:31 +0200 | [diff] [blame] | 169 | fi |
Andrew Wong | fcc5ef1 | 2012-09-17 21:28:08 -0400 | [diff] [blame] | 170 | } |
| 171 | |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 172 | make_patch () { |
Johannes Schindelin | 4fb1a19 | 2008-12-22 22:16:51 +0100 | [diff] [blame] | 173 | sha1_and_parents="$(git rev-list --parents -1 "$1")" |
| 174 | case "$sha1_and_parents" in |
| 175 | ?*' '?*' '?*) |
| 176 | git diff --cc $sha1_and_parents |
| 177 | ;; |
| 178 | ?*' '?*) |
| 179 | git diff-tree -p "$1^!" |
| 180 | ;; |
| 181 | *) |
| 182 | echo "Root commit" |
| 183 | ;; |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 184 | esac > "$state_dir"/patch |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 185 | test -f "$msg" || |
| 186 | commit_message "$1" > "$msg" |
| 187 | test -f "$author_script" || |
| 188 | get_author_ident_from_commit "$1" > "$author_script" |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | die_with_patch () { |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 192 | echo "$1" > "$state_dir"/stopped-sha |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 193 | make_patch "$1" |
| 194 | die "$2" |
| 195 | } |
| 196 | |
Andrew Wong | 0becb3e | 2011-11-30 10:52:51 -0500 | [diff] [blame] | 197 | exit_with_patch () { |
| 198 | echo "$1" > "$state_dir"/stopped-sha |
| 199 | make_patch $1 |
| 200 | git rev-parse --verify HEAD > "$amend" |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 201 | gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 202 | warn "$(eval_gettext "\ |
| 203 | You can amend the commit now, with |
| 204 | |
| 205 | git commit --amend \$gpg_sign_opt_quoted |
| 206 | |
| 207 | Once you are satisfied with your changes, run |
| 208 | |
| 209 | git rebase --continue")" |
Andrew Wong | 0becb3e | 2011-11-30 10:52:51 -0500 | [diff] [blame] | 210 | warn |
| 211 | exit $2 |
| 212 | } |
| 213 | |
Johannes Schindelin | c54b781 | 2007-06-25 18:56:55 +0100 | [diff] [blame] | 214 | die_abort () { |
Patrick Steinhardt | 33ba9c6 | 2016-06-29 08:21:27 +0200 | [diff] [blame] | 215 | apply_autostash |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 216 | rm -rf "$state_dir" |
Johannes Schindelin | c54b781 | 2007-06-25 18:56:55 +0100 | [diff] [blame] | 217 | die "$1" |
| 218 | } |
| 219 | |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 220 | has_action () { |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 221 | test -n "$(git stripspace --strip-comments <"$1")" |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 222 | } |
| 223 | |
Neil Horman | 90e1818 | 2012-04-20 10:36:17 -0400 | [diff] [blame] | 224 | is_empty_commit() { |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 225 | tree=$(git rev-parse -q --verify "$1"^{tree} 2>/dev/null) || { |
| 226 | sha1=$1 |
| 227 | die "$(eval_gettext "\$sha1: not a commit that can be picked")" |
| 228 | } |
| 229 | ptree=$(git rev-parse -q --verify "$1"^^{tree} 2>/dev/null) || |
| 230 | ptree=4b825dc642cb6eb9a060e54bf8d69288fbee4904 |
Neil Horman | 90e1818 | 2012-04-20 10:36:17 -0400 | [diff] [blame] | 231 | test "$tree" = "$ptree" |
| 232 | } |
| 233 | |
Phil Hord | 9869778 | 2013-01-12 15:46:01 -0500 | [diff] [blame] | 234 | is_merge_commit() |
| 235 | { |
| 236 | git rev-parse --verify --quiet "$1"^2 >/dev/null 2>&1 |
| 237 | } |
| 238 | |
Michael Haggerty | 7756ecf | 2010-01-14 06:54:53 +0100 | [diff] [blame] | 239 | # Run command with GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and |
| 240 | # GIT_AUTHOR_DATE exported from the current environment. |
| 241 | do_with_author () { |
Junio C Hamano | 76c9c0d | 2010-01-22 13:09:24 -0800 | [diff] [blame] | 242 | ( |
| 243 | export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE |
| 244 | "$@" |
| 245 | ) |
Michael Haggerty | 7756ecf | 2010-01-14 06:54:53 +0100 | [diff] [blame] | 246 | } |
| 247 | |
Peter Oberndorfer | 821881d | 2011-10-17 22:26:23 +0200 | [diff] [blame] | 248 | git_sequence_editor () { |
| 249 | if test -z "$GIT_SEQUENCE_EDITOR" |
| 250 | then |
| 251 | GIT_SEQUENCE_EDITOR="$(git config sequence.editor)" |
| 252 | if [ -z "$GIT_SEQUENCE_EDITOR" ] |
| 253 | then |
| 254 | GIT_SEQUENCE_EDITOR="$(git var GIT_EDITOR)" || return $? |
| 255 | fi |
| 256 | fi |
| 257 | |
| 258 | eval "$GIT_SEQUENCE_EDITOR" '"$@"' |
| 259 | } |
| 260 | |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 261 | pick_one () { |
Christian Couder | 8e75abf | 2010-03-06 21:34:46 +0100 | [diff] [blame] | 262 | ff=--ff |
Neil Horman | 90e1818 | 2012-04-20 10:36:17 -0400 | [diff] [blame] | 263 | |
Christian Couder | 8e75abf | 2010-03-06 21:34:46 +0100 | [diff] [blame] | 264 | case "$1" in -n) sha1=$2; ff= ;; *) sha1=$1 ;; esac |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 265 | case "$force_rebase" in '') ;; ?*) ff= ;; esac |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 266 | output git rev-parse --verify $sha1 || die "$(eval_gettext "Invalid commit name: \$sha1")" |
Neil Horman | 90e1818 | 2012-04-20 10:36:17 -0400 | [diff] [blame] | 267 | |
| 268 | if is_empty_commit "$sha1" |
| 269 | then |
| 270 | empty_args="--allow-empty" |
| 271 | fi |
| 272 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 273 | test -d "$rewritten" && |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 274 | pick_one_preserving_merges "$@" && return |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 275 | output eval git cherry-pick \ |
| 276 | ${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \ |
| 277 | "$strategy_args" $empty_args $ff "$@" |
Phil Hord | 8cbc57c | 2015-04-28 18:55:20 -0400 | [diff] [blame] | 278 | |
| 279 | # If cherry-pick dies it leaves the to-be-picked commit unrecorded. Reschedule |
| 280 | # previous task so this commit is not lost. |
| 281 | ret=$? |
| 282 | case "$ret" in [01]) ;; *) reschedule_last_action ;; esac |
| 283 | return $ret |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 284 | } |
| 285 | |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 286 | pick_one_preserving_merges () { |
Thomas Rast | 71d9451 | 2008-08-13 23:41:23 +0200 | [diff] [blame] | 287 | fast_forward=t |
| 288 | case "$1" in |
| 289 | -n) |
| 290 | fast_forward=f |
| 291 | sha1=$2 |
| 292 | ;; |
| 293 | *) |
| 294 | sha1=$1 |
| 295 | ;; |
| 296 | esac |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 297 | sha1=$(git rev-parse $sha1) |
| 298 | |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 299 | if test -f "$state_dir"/current-commit |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 300 | then |
Junio C Hamano | 4c1360f | 2008-10-22 11:59:30 -0700 | [diff] [blame] | 301 | if test "$fast_forward" = t |
Stephen Haberman | bb64507 | 2008-10-15 02:44:36 -0500 | [diff] [blame] | 302 | then |
Junio C Hamano | 41f556b | 2010-07-05 22:16:15 -0700 | [diff] [blame] | 303 | while read current_commit |
Stephen Haberman | bb64507 | 2008-10-15 02:44:36 -0500 | [diff] [blame] | 304 | do |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 305 | git rev-parse HEAD > "$rewritten"/$current_commit |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 306 | done <"$state_dir"/current-commit |
| 307 | rm "$state_dir"/current-commit || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 308 | die "$(gettext "Cannot write current commit's replacement sha1")" |
Stephen Haberman | bb64507 | 2008-10-15 02:44:36 -0500 | [diff] [blame] | 309 | fi |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 310 | fi |
| 311 | |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 312 | echo $sha1 >> "$state_dir"/current-commit |
Thomas Rast | a96dc01 | 2008-08-13 23:41:24 +0200 | [diff] [blame] | 313 | |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 314 | # rewrite parents; if none were rewritten, we can fast-forward. |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 315 | new_parents= |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 316 | pend=" $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)" |
| 317 | if test "$pend" = " " |
| 318 | then |
| 319 | pend=" root" |
| 320 | fi |
Stephen Haberman | faae853 | 2008-10-05 23:26:52 -0500 | [diff] [blame] | 321 | while [ "$pend" != "" ] |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 322 | do |
Stephen Haberman | faae853 | 2008-10-05 23:26:52 -0500 | [diff] [blame] | 323 | p=$(expr "$pend" : ' \([^ ]*\)') |
| 324 | pend="${pend# $p}" |
| 325 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 326 | if test -f "$rewritten"/$p |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 327 | then |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 328 | new_p=$(cat "$rewritten"/$p) |
Stephen Haberman | 80fe82e | 2008-10-15 02:44:40 -0500 | [diff] [blame] | 329 | |
| 330 | # If the todo reordered commits, and our parent is marked for |
| 331 | # rewriting, but hasn't been gotten to yet, assume the user meant to |
| 332 | # drop it on top of the current HEAD |
| 333 | if test -z "$new_p" |
| 334 | then |
| 335 | new_p=$(git rev-parse HEAD) |
| 336 | fi |
| 337 | |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 338 | test $p != $new_p && fast_forward=f |
| 339 | case "$new_parents" in |
| 340 | *$new_p*) |
| 341 | ;; # do nothing; that parent is already there |
| 342 | *) |
| 343 | new_parents="$new_parents $new_p" |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 344 | ;; |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 345 | esac |
Stephan Beyer | 1c5fa0a | 2008-07-16 03:51:49 +0200 | [diff] [blame] | 346 | else |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 347 | if test -f "$dropped"/$p |
Stephen Haberman | faae853 | 2008-10-05 23:26:52 -0500 | [diff] [blame] | 348 | then |
| 349 | fast_forward=f |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 350 | replacement="$(cat "$dropped"/$p)" |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 351 | test -z "$replacement" && replacement=root |
| 352 | pend=" $replacement$pend" |
Stephen Haberman | faae853 | 2008-10-05 23:26:52 -0500 | [diff] [blame] | 353 | else |
| 354 | new_parents="$new_parents $p" |
| 355 | fi |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 356 | fi |
| 357 | done |
| 358 | case $fast_forward in |
| 359 | t) |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 360 | output warn "$(eval_gettext "Fast-forward to \$sha1")" |
Thomas Rast | 71d9451 | 2008-08-13 23:41:23 +0200 | [diff] [blame] | 361 | output git reset --hard $sha1 || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 362 | die "$(eval_gettext "Cannot fast-forward to \$sha1")" |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 363 | ;; |
| 364 | f) |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 365 | first_parent=$(expr "$new_parents" : ' \([^ ]*\)') |
Stephen Haberman | a4f25e3 | 2008-10-15 02:44:37 -0500 | [diff] [blame] | 366 | |
| 367 | if [ "$1" != "-n" ] |
| 368 | then |
| 369 | # detach HEAD to current parent |
| 370 | output git checkout $first_parent 2> /dev/null || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 371 | die "$(eval_gettext "Cannot move HEAD to \$first_parent")" |
Stephen Haberman | a4f25e3 | 2008-10-15 02:44:37 -0500 | [diff] [blame] | 372 | fi |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 373 | |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 374 | case "$new_parents" in |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 375 | ' '*' '*) |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 376 | test "a$1" = a-n && die "$(eval_gettext "Refusing to squash a merge: \$sha1")" |
Stephen Haberman | a4f25e3 | 2008-10-15 02:44:37 -0500 | [diff] [blame] | 377 | |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 378 | # redo merge |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 379 | author_script_content=$(get_author_ident_from_commit $sha1) |
| 380 | eval "$author_script_content" |
| 381 | msg_content="$(commit_message $sha1)" |
Björn Steinbrink | f91333d | 2007-10-31 03:20:32 +0100 | [diff] [blame] | 382 | # No point in merging the first parent, that's HEAD |
| 383 | new_parents=${new_parents# $first_parent} |
Ralf Thielow | a9f739c | 2013-08-21 20:48:57 +0200 | [diff] [blame] | 384 | merge_args="--no-log --no-ff" |
Arnaud Fontaine | db2b3b8 | 2013-07-02 17:05:48 +0900 | [diff] [blame] | 385 | if ! do_with_author output eval \ |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 386 | 'git merge ${gpg_sign_opt:+"$gpg_sign_opt"} \ |
| 387 | $merge_args $strategy_args -m "$msg_content" $new_parents' |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 388 | then |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 389 | printf "%s\n" "$msg_content" > "$GIT_DIR"/MERGE_MSG |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 390 | die_with_patch $sha1 "$(eval_gettext "Error redoing merge \$sha1")" |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 391 | fi |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 392 | echo "$sha1 $(git rev-parse HEAD^0)" >> "$rewritten_list" |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 393 | ;; |
| 394 | *) |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 395 | output eval git cherry-pick \ |
| 396 | ${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \ |
| 397 | "$strategy_args" "$@" || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 398 | die_with_patch $sha1 "$(eval_gettext "Could not pick \$sha1")" |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 399 | ;; |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 400 | esac |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 401 | ;; |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 402 | esac |
| 403 | } |
| 404 | |
Vasco Almeida | f2d1706 | 2016-06-17 20:21:05 +0000 | [diff] [blame] | 405 | this_nth_commit_message () { |
| 406 | n=$1 |
Jean-Noel Avila | 8aa6dc1 | 2016-08-21 16:50:38 +0200 | [diff] [blame] | 407 | eval_gettext "This is the commit message #\${n}:" |
Vasco Almeida | f2d1706 | 2016-06-17 20:21:05 +0000 | [diff] [blame] | 408 | } |
Jean-Noel Avila | 8aa6dc1 | 2016-08-21 16:50:38 +0200 | [diff] [blame] | 409 | |
Vasco Almeida | f2d1706 | 2016-06-17 20:21:05 +0000 | [diff] [blame] | 410 | skip_nth_commit_message () { |
| 411 | n=$1 |
Jean-Noel Avila | 8aa6dc1 | 2016-08-21 16:50:38 +0200 | [diff] [blame] | 412 | eval_gettext "The commit message #\${n} will be skipped:" |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 413 | } |
| 414 | |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 415 | update_squash_messages () { |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 416 | if test -f "$squash_msg"; then |
| 417 | mv "$squash_msg" "$squash_msg".bak || exit |
| 418 | count=$(($(sed -n \ |
Vasco Almeida | f2d1706 | 2016-06-17 20:21:05 +0000 | [diff] [blame] | 419 | -e "1s/^$comment_char.*\([0-9][0-9]*\).*/\1/p" \ |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 420 | -e "q" < "$squash_msg".bak)+1)) |
Michael Haggerty | bde1a68 | 2010-01-14 06:54:54 +0100 | [diff] [blame] | 421 | { |
Vasco Almeida | f2d1706 | 2016-06-17 20:21:05 +0000 | [diff] [blame] | 422 | printf '%s\n' "$comment_char $(eval_ngettext \ |
| 423 | "This is a combination of \$count commit." \ |
| 424 | "This is a combination of \$count commits." \ |
| 425 | $count)" |
Michael Haggerty | bde1a68 | 2010-01-14 06:54:54 +0100 | [diff] [blame] | 426 | sed -e 1d -e '2,/^./{ |
| 427 | /^$/d |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 428 | }' <"$squash_msg".bak |
| 429 | } >"$squash_msg" |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 430 | else |
Vasco Almeida | f2d1706 | 2016-06-17 20:21:05 +0000 | [diff] [blame] | 431 | commit_message HEAD > "$fixup_msg" || die "$(gettext "Cannot write \$fixup_msg")" |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 432 | count=2 |
Michael Haggerty | bde1a68 | 2010-01-14 06:54:54 +0100 | [diff] [blame] | 433 | { |
Vasco Almeida | f2d1706 | 2016-06-17 20:21:05 +0000 | [diff] [blame] | 434 | printf '%s\n' "$comment_char $(gettext "This is a combination of 2 commits.")" |
| 435 | printf '%s\n' "$comment_char $(gettext "This is the 1st commit message:")" |
Michael Haggerty | bde1a68 | 2010-01-14 06:54:54 +0100 | [diff] [blame] | 436 | echo |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 437 | cat "$fixup_msg" |
| 438 | } >"$squash_msg" |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 439 | fi |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 440 | case $1 in |
| 441 | squash) |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 442 | rm -f "$fixup_msg" |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 443 | echo |
Vasco Almeida | f2d1706 | 2016-06-17 20:21:05 +0000 | [diff] [blame] | 444 | printf '%s\n' "$comment_char $(this_nth_commit_message $count)" |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 445 | echo |
Michael Haggerty | ee0a4af | 2010-01-14 06:54:51 +0100 | [diff] [blame] | 446 | commit_message $2 |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 447 | ;; |
| 448 | fixup) |
| 449 | echo |
Vasco Almeida | f2d1706 | 2016-06-17 20:21:05 +0000 | [diff] [blame] | 450 | printf '%s\n' "$comment_char $(skip_nth_commit_message $count)" |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 451 | echo |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 452 | # Change the space after the comment character to TAB: |
| 453 | commit_message $2 | git stripspace --comment-lines | sed -e 's/ / /' |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 454 | ;; |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 455 | esac >>"$squash_msg" |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | peek_next_command () { |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 459 | git stripspace --strip-comments <"$todo" | sed -n -e 's/ .*//p' -e q |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 460 | } |
| 461 | |
Michael Haggerty | 6bdcd0d | 2010-01-14 06:54:57 +0100 | [diff] [blame] | 462 | # A squash/fixup has failed. Prepare the long version of the squash |
| 463 | # commit message, then die_with_patch. This code path requires the |
| 464 | # user to edit the combined commit message for all commits that have |
| 465 | # been squashed/fixedup so far. So also erase the old squash |
| 466 | # messages, effectively causing the combined commit to be used as the |
| 467 | # new basis for any further squash/fixups. Args: sha1 rest |
| 468 | die_failed_squash() { |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 469 | sha1=$1 |
| 470 | rest=$2 |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 471 | mv "$squash_msg" "$msg" || exit |
| 472 | rm -f "$fixup_msg" |
| 473 | cp "$msg" "$GIT_DIR"/MERGE_MSG || exit |
Michael Haggerty | 6bdcd0d | 2010-01-14 06:54:57 +0100 | [diff] [blame] | 474 | warn |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 475 | warn "$(eval_gettext "Could not apply \$sha1... \$rest")" |
| 476 | die_with_patch $sha1 "" |
Michael Haggerty | 6bdcd0d | 2010-01-14 06:54:57 +0100 | [diff] [blame] | 477 | } |
| 478 | |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 479 | flush_rewritten_pending() { |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 480 | test -s "$rewritten_pending" || return |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 481 | newsha1="$(git rev-parse HEAD^0)" |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 482 | sed "s/$/ $newsha1/" < "$rewritten_pending" >> "$rewritten_list" |
| 483 | rm -f "$rewritten_pending" |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | record_in_rewritten() { |
| 487 | oldsha1="$(git rev-parse $1)" |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 488 | echo "$oldsha1" >> "$rewritten_pending" |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 489 | |
| 490 | case "$(peek_next_command)" in |
Junio C Hamano | 41f556b | 2010-07-05 22:16:15 -0700 | [diff] [blame] | 491 | squash|s|fixup|f) |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 492 | ;; |
Junio C Hamano | 41f556b | 2010-07-05 22:16:15 -0700 | [diff] [blame] | 493 | *) |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 494 | flush_rewritten_pending |
| 495 | ;; |
| 496 | esac |
| 497 | } |
| 498 | |
Chris Webb | df5df20 | 2012-06-26 22:55:23 +0100 | [diff] [blame] | 499 | do_pick () { |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 500 | sha1=$1 |
| 501 | rest=$2 |
Chris Webb | df5df20 | 2012-06-26 22:55:23 +0100 | [diff] [blame] | 502 | if test "$(git rev-parse HEAD)" = "$squash_onto" |
| 503 | then |
| 504 | # Set the correct commit message and author info on the |
| 505 | # sentinel root before cherry-picking the original changes |
| 506 | # without committing (-n). Finally, update the sentinel again |
| 507 | # to include these changes. If the cherry-pick results in a |
| 508 | # conflict, this means our behaviour is similar to a standard |
| 509 | # failed cherry-pick during rebase, with a dirty index to |
| 510 | # resolve before manually running git commit --amend then git |
| 511 | # rebase --continue. |
| 512 | git commit --allow-empty --allow-empty-message --amend \ |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 513 | --no-post-rewrite -n -q -C $sha1 && |
| 514 | pick_one -n $sha1 && |
Chris Webb | df5df20 | 2012-06-26 22:55:23 +0100 | [diff] [blame] | 515 | git commit --allow-empty --allow-empty-message \ |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 516 | --amend --no-post-rewrite -n -q -C $sha1 \ |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 517 | ${gpg_sign_opt:+"$gpg_sign_opt"} || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 518 | die_with_patch $sha1 "$(eval_gettext "Could not apply \$sha1... \$rest")" |
Chris Webb | df5df20 | 2012-06-26 22:55:23 +0100 | [diff] [blame] | 519 | else |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 520 | pick_one $sha1 || |
| 521 | die_with_patch $sha1 "$(eval_gettext "Could not apply \$sha1... \$rest")" |
Chris Webb | df5df20 | 2012-06-26 22:55:23 +0100 | [diff] [blame] | 522 | fi |
| 523 | } |
| 524 | |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 525 | do_next () { |
Matthieu Moy | b12d3e9 | 2015-05-22 13:15:49 +0000 | [diff] [blame] | 526 | rm -f "$msg" "$author_script" "$amend" "$state_dir"/stopped-sha || exit |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 527 | read -r command sha1 rest < "$todo" |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 528 | case "$command" in |
Galan Rémi | c9266d5 | 2015-06-29 22:20:30 +0200 | [diff] [blame] | 529 | "$comment_char"*|''|noop|drop|d) |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 530 | mark_action_done |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 531 | ;; |
Junio C Hamano | 39743cf | 2015-10-28 15:54:48 +0100 | [diff] [blame] | 532 | "$cr") |
| 533 | # Work around CR left by "read" (e.g. with Git for Windows' Bash). |
| 534 | mark_action_done |
| 535 | ;; |
Johannes Schindelin | f8babc4 | 2007-09-29 03:32:11 +0100 | [diff] [blame] | 536 | pick|p) |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 537 | comment_for_reflog pick |
| 538 | |
| 539 | mark_action_done |
Chris Webb | df5df20 | 2012-06-26 22:55:23 +0100 | [diff] [blame] | 540 | do_pick $sha1 "$rest" |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 541 | record_in_rewritten $sha1 |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 542 | ;; |
Björn Gustavsson | 6741aa6 | 2009-10-07 08:13:23 +0200 | [diff] [blame] | 543 | reword|r) |
| 544 | comment_for_reflog reword |
| 545 | |
| 546 | mark_action_done |
Chris Webb | df5df20 | 2012-06-26 22:55:23 +0100 | [diff] [blame] | 547 | do_pick $sha1 "$rest" |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 548 | git commit --amend --no-post-rewrite ${gpg_sign_opt:+"$gpg_sign_opt"} || { |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 549 | warn "$(eval_gettext "\ |
| 550 | Could not amend commit after successfully picking \$sha1... \$rest |
| 551 | This is most likely due to an empty commit message, or the pre-commit hook |
| 552 | failed. If the pre-commit hook failed, you may need to resolve the issue before |
| 553 | you are able to reword the commit.")" |
Andrew Wong | 0becb3e | 2011-11-30 10:52:51 -0500 | [diff] [blame] | 554 | exit_with_patch $sha1 1 |
| 555 | } |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 556 | record_in_rewritten $sha1 |
Björn Gustavsson | 6741aa6 | 2009-10-07 08:13:23 +0200 | [diff] [blame] | 557 | ;; |
Johannes Schindelin | f8babc4 | 2007-09-29 03:32:11 +0100 | [diff] [blame] | 558 | edit|e) |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 559 | comment_for_reflog edit |
| 560 | |
| 561 | mark_action_done |
Chris Webb | df5df20 | 2012-06-26 22:55:23 +0100 | [diff] [blame] | 562 | do_pick $sha1 "$rest" |
Ralf Thielow | 14c793e | 2016-03-28 18:00:00 +0200 | [diff] [blame] | 563 | sha1_abbrev=$(git rev-parse --short $sha1) |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 564 | warn "$(eval_gettext "Stopped at \$sha1_abbrev... \$rest")" |
Andrew Wong | 0becb3e | 2011-11-30 10:52:51 -0500 | [diff] [blame] | 565 | exit_with_patch $sha1 0 |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 566 | ;; |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 567 | squash|s|fixup|f) |
| 568 | case "$command" in |
| 569 | squash|s) |
| 570 | squash_style=squash |
| 571 | ;; |
| 572 | fixup|f) |
| 573 | squash_style=fixup |
| 574 | ;; |
| 575 | esac |
| 576 | comment_for_reflog $squash_style |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 577 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 578 | test -f "$done" && has_action "$done" || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 579 | die "$(eval_gettext "Cannot '\$squash_style' without a previous commit")" |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 580 | |
| 581 | mark_action_done |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 582 | update_squash_messages $squash_style $sha1 |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 583 | author_script_content=$(get_author_ident_from_commit HEAD) |
| 584 | echo "$author_script_content" > "$author_script" |
| 585 | eval "$author_script_content" |
Chris Webb | 2147f84 | 2012-07-24 13:17:03 +0100 | [diff] [blame] | 586 | if ! pick_one -n $sha1 |
| 587 | then |
| 588 | git rev-parse --verify HEAD >"$amend" |
| 589 | die_failed_squash $sha1 "$rest" |
| 590 | fi |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 591 | case "$(peek_next_command)" in |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 592 | squash|s|fixup|f) |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 593 | # This is an intermediate commit; its message will only be |
| 594 | # used in case of trouble. So use the long version: |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 595 | do_with_author output git commit --amend --no-verify -F "$squash_msg" \ |
| 596 | ${gpg_sign_opt:+"$gpg_sign_opt"} || |
Michael Haggerty | 6bdcd0d | 2010-01-14 06:54:57 +0100 | [diff] [blame] | 597 | die_failed_squash $sha1 "$rest" |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 598 | ;; |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 599 | *) |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 600 | # This is the final command of this squash/fixup group |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 601 | if test -f "$fixup_msg" |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 602 | then |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 603 | do_with_author git commit --amend --no-verify -F "$fixup_msg" \ |
| 604 | ${gpg_sign_opt:+"$gpg_sign_opt"} || |
Michael Haggerty | 6bdcd0d | 2010-01-14 06:54:57 +0100 | [diff] [blame] | 605 | die_failed_squash $sha1 "$rest" |
| 606 | else |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 607 | cp "$squash_msg" "$GIT_DIR"/SQUASH_MSG || exit |
Michael Haggerty | 6bdcd0d | 2010-01-14 06:54:57 +0100 | [diff] [blame] | 608 | rm -f "$GIT_DIR"/MERGE_MSG |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 609 | do_with_author git commit --amend --no-verify -F "$GIT_DIR"/SQUASH_MSG -e \ |
| 610 | ${gpg_sign_opt:+"$gpg_sign_opt"} || |
Michael Haggerty | 6bdcd0d | 2010-01-14 06:54:57 +0100 | [diff] [blame] | 611 | die_failed_squash $sha1 "$rest" |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 612 | fi |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 613 | rm -f "$squash_msg" "$fixup_msg" |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 614 | ;; |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 615 | esac |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 616 | record_in_rewritten $sha1 |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 617 | ;; |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 618 | x|"exec") |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 619 | read -r command rest < "$todo" |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 620 | mark_action_done |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 621 | eval_gettextln "Executing: \$rest" |
Fredrik Medley | fe9394a | 2015-11-13 07:03:19 +0100 | [diff] [blame] | 622 | "${SHELL:-@SHELL_PATH@}" -c "$rest" # Actual execution |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 623 | status=$? |
Junio C Hamano | 1686519 | 2011-08-24 11:54:50 -0700 | [diff] [blame] | 624 | # Run in subshell because require_clean_work_tree can die. |
| 625 | dirty=f |
| 626 | (require_clean_work_tree "rebase" 2>/dev/null) || dirty=t |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 627 | if test "$status" -ne 0 |
| 628 | then |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 629 | warn "$(eval_gettext "Execution failed: \$rest")" |
Junio C Hamano | 1686519 | 2011-08-24 11:54:50 -0700 | [diff] [blame] | 630 | test "$dirty" = f || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 631 | warn "$(gettext "and made changes to the index and/or the working tree")" |
Junio C Hamano | 1686519 | 2011-08-24 11:54:50 -0700 | [diff] [blame] | 632 | |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 633 | warn "$(gettext "\ |
| 634 | You can fix the problem, and then run |
| 635 | |
| 636 | git rebase --continue")" |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 637 | warn |
Johannes Sixt | ecfe1ea | 2012-09-18 13:15:26 +0200 | [diff] [blame] | 638 | if test $status -eq 127 # command not found |
| 639 | then |
| 640 | status=1 |
| 641 | fi |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 642 | exit "$status" |
Junio C Hamano | 1686519 | 2011-08-24 11:54:50 -0700 | [diff] [blame] | 643 | elif test "$dirty" = t |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 644 | then |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 645 | # TRANSLATORS: after these lines is a command to be issued by the user |
| 646 | warn "$(eval_gettext "\ |
| 647 | Execution succeeded: \$rest |
| 648 | but left changes to the index and/or the working tree |
| 649 | Commit or stash your changes, and then run |
| 650 | |
| 651 | git rebase --continue")" |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 652 | warn |
| 653 | exit 1 |
| 654 | fi |
| 655 | ;; |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 656 | *) |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 657 | warn "$(eval_gettext "Unknown command: \$command \$sha1 \$rest")" |
| 658 | fixtodo="$(gettext "Please fix this using 'git rebase --edit-todo'.")" |
Jan Krüger | f1be316 | 2009-10-27 15:58:14 +0100 | [diff] [blame] | 659 | if git rev-parse --verify -q "$sha1" >/dev/null |
| 660 | then |
Johannes Sixt | 9c8e101 | 2012-09-19 08:43:54 +0200 | [diff] [blame] | 661 | die_with_patch $sha1 "$fixtodo" |
Jan Krüger | f1be316 | 2009-10-27 15:58:14 +0100 | [diff] [blame] | 662 | else |
Johannes Sixt | 9c8e101 | 2012-09-19 08:43:54 +0200 | [diff] [blame] | 663 | die "$fixtodo" |
Jan Krüger | f1be316 | 2009-10-27 15:58:14 +0100 | [diff] [blame] | 664 | fi |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 665 | ;; |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 666 | esac |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 667 | test -s "$todo" && return |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 668 | |
Johannes Schindelin | 68a163c | 2007-06-25 18:58:28 +0100 | [diff] [blame] | 669 | comment_for_reflog finish && |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 670 | newhead=$(git rev-parse HEAD) && |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 671 | case $head_name in |
Johannes Schindelin | 73697a0 | 2007-09-25 16:43:15 +0100 | [diff] [blame] | 672 | refs/*) |
Michael J Gruber | 1af221e | 2012-08-10 08:51:19 +0200 | [diff] [blame] | 673 | message="$GIT_REFLOG_ACTION: $head_name onto $onto" && |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 674 | git update-ref -m "$message" $head_name $newhead $orig_head && |
Jeff King | 53f2ffa | 2011-05-27 16:16:14 -0400 | [diff] [blame] | 675 | git symbolic-ref \ |
| 676 | -m "$GIT_REFLOG_ACTION: returning to $head_name" \ |
| 677 | HEAD $head_name |
Johannes Schindelin | 73697a0 | 2007-09-25 16:43:15 +0100 | [diff] [blame] | 678 | ;; |
| 679 | esac && { |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 680 | test ! -f "$state_dir"/verbose || |
Martin von Zweigbergk | 2959c28 | 2011-02-06 13:43:52 -0500 | [diff] [blame] | 681 | git diff-tree --stat $orig_head..HEAD |
Johannes Schindelin | 3df0a85 | 2007-07-08 03:02:13 +0100 | [diff] [blame] | 682 | } && |
Thomas Rast | eb2151b | 2010-03-12 18:04:33 +0100 | [diff] [blame] | 683 | { |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 684 | test -s "$rewritten_list" && |
| 685 | git notes copy --for-rewrite=rebase < "$rewritten_list" || |
Thomas Rast | eb2151b | 2010-03-12 18:04:33 +0100 | [diff] [blame] | 686 | true # we don't care if this copying failed |
| 687 | } && |
Nguyễn Thái Ngọc Duy | b849b95 | 2014-11-30 15:24:38 +0700 | [diff] [blame] | 688 | hook="$(git rev-parse --git-path hooks/post-rewrite)" |
| 689 | if test -x "$hook" && test -s "$rewritten_list"; then |
| 690 | "$hook" rebase < "$rewritten_list" |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 691 | true # we don't care if this hook failed |
| 692 | fi && |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 693 | warn "$(eval_gettext "Successfully rebased and updated \$head_name.")" |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 694 | |
Ramkumar Ramachandra | 15d4bf2 | 2013-05-12 17:26:39 +0530 | [diff] [blame] | 695 | return 1 # not failure; just to break the do_rest loop |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 696 | } |
| 697 | |
Ramkumar Ramachandra | 15d4bf2 | 2013-05-12 17:26:39 +0530 | [diff] [blame] | 698 | # can only return 0, when the infinite loop breaks |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 699 | do_rest () { |
| 700 | while : |
| 701 | do |
Ramkumar Ramachandra | 15d4bf2 | 2013-05-12 17:26:39 +0530 | [diff] [blame] | 702 | do_next || break |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 703 | done |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 704 | } |
| 705 | |
Johannes Schindelin | 0e757e3 | 2009-03-03 10:55:31 +0100 | [diff] [blame] | 706 | # skip picking commits whose parents are unchanged |
| 707 | skip_unnecessary_picks () { |
| 708 | fd=3 |
Brandon Casey | 2d6ca6e | 2010-08-13 15:47:34 -0500 | [diff] [blame] | 709 | while read -r command rest |
Johannes Schindelin | 0e757e3 | 2009-03-03 10:55:31 +0100 | [diff] [blame] | 710 | do |
| 711 | # fd=3 means we skip the command |
Brandon Casey | 2d6ca6e | 2010-08-13 15:47:34 -0500 | [diff] [blame] | 712 | case "$fd,$command" in |
| 713 | 3,pick|3,p) |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 714 | # pick a commit whose parent is current $onto -> skip |
Chris Johnsen | 14d8729 | 2010-09-17 16:42:51 -0500 | [diff] [blame] | 715 | sha1=${rest%% *} |
Brandon Casey | 2d6ca6e | 2010-08-13 15:47:34 -0500 | [diff] [blame] | 716 | case "$(git rev-parse --verify --quiet "$sha1"^)" in |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 717 | "$onto"*) |
| 718 | onto=$sha1 |
Brandon Casey | 2d6ca6e | 2010-08-13 15:47:34 -0500 | [diff] [blame] | 719 | ;; |
| 720 | *) |
| 721 | fd=1 |
| 722 | ;; |
| 723 | esac |
Johannes Schindelin | 0e757e3 | 2009-03-03 10:55:31 +0100 | [diff] [blame] | 724 | ;; |
Eric Sunshine | 7bca7af | 2013-08-16 17:44:07 -0400 | [diff] [blame] | 725 | 3,"$comment_char"*|3,) |
Johannes Schindelin | 0e757e3 | 2009-03-03 10:55:31 +0100 | [diff] [blame] | 726 | # copy comments |
| 727 | ;; |
| 728 | *) |
| 729 | fd=1 |
| 730 | ;; |
| 731 | esac |
Brandon Casey | d1c3b10 | 2010-08-13 15:47:35 -0500 | [diff] [blame] | 732 | printf '%s\n' "$command${rest:+ }$rest" >&$fd |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 733 | done <"$todo" >"$todo.new" 3>>"$done" && |
| 734 | mv -f "$todo".new "$todo" && |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 735 | case "$(peek_next_command)" in |
| 736 | squash|s|fixup|f) |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 737 | record_in_rewritten "$onto" |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 738 | ;; |
| 739 | esac || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 740 | die "$(gettext "Could not skip unnecessary pick commands")" |
Johannes Schindelin | 0e757e3 | 2009-03-03 10:55:31 +0100 | [diff] [blame] | 741 | } |
| 742 | |
Junio C Hamano | 75c6976 | 2013-08-23 20:10:42 -0400 | [diff] [blame] | 743 | transform_todo_ids () { |
| 744 | while read -r command rest |
| 745 | do |
| 746 | case "$command" in |
| 747 | "$comment_char"* | exec) |
| 748 | # Be careful for oddball commands like 'exec' |
| 749 | # that do not have a SHA-1 at the beginning of $rest. |
| 750 | ;; |
| 751 | *) |
Matthieu Moy | 31bff64 | 2015-10-01 10:18:41 +0200 | [diff] [blame] | 752 | sha1=$(git rev-parse --verify --quiet "$@" ${rest%%[ ]*}) && |
| 753 | rest="$sha1 ${rest#*[ ]}" |
Junio C Hamano | 75c6976 | 2013-08-23 20:10:42 -0400 | [diff] [blame] | 754 | ;; |
| 755 | esac |
| 756 | printf '%s\n' "$command${rest:+ }$rest" |
| 757 | done <"$todo" >"$todo.new" && |
| 758 | mv -f "$todo.new" "$todo" |
| 759 | } |
| 760 | |
| 761 | expand_todo_ids() { |
| 762 | transform_todo_ids |
| 763 | } |
| 764 | |
| 765 | collapse_todo_ids() { |
Kirill A. Shutemov | 5689503 | 2013-09-28 18:53:05 +0300 | [diff] [blame] | 766 | transform_todo_ids --short |
Junio C Hamano | 75c6976 | 2013-08-23 20:10:42 -0400 | [diff] [blame] | 767 | } |
| 768 | |
Nanako Shiraishi | f59baa5 | 2009-12-08 12:13:14 +0900 | [diff] [blame] | 769 | # Rearrange the todo list that has both "pick sha1 msg" and |
| 770 | # "pick sha1 fixup!/squash! msg" appears in it so that the latter |
| 771 | # comes immediately after the former, and change "pick" to |
| 772 | # "fixup"/"squash". |
Michael Rappazzo | 16cf51c | 2015-06-13 12:26:58 -0400 | [diff] [blame] | 773 | # |
| 774 | # Note that if the config has specified a custom instruction format |
| 775 | # each log message will be re-retrieved in order to normalize the |
| 776 | # autosquash arrangement |
Nanako Shiraishi | f59baa5 | 2009-12-08 12:13:14 +0900 | [diff] [blame] | 777 | rearrange_squash () { |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 778 | # extract fixup!/squash! lines and resolve any referenced sha1's |
| 779 | while read -r pick sha1 message |
| 780 | do |
Michael Rappazzo | 16cf51c | 2015-06-13 12:26:58 -0400 | [diff] [blame] | 781 | test -z "${format}" || message=$(git log -n 1 --format="%s" ${sha1}) |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 782 | case "$message" in |
| 783 | "squash! "*|"fixup! "*) |
| 784 | action="${message%%!*}" |
Andrew Pimlott | 22c5b13 | 2013-06-27 12:26:31 -0700 | [diff] [blame] | 785 | rest=$message |
| 786 | prefix= |
| 787 | # skip all squash! or fixup! (but save for later) |
| 788 | while : |
| 789 | do |
| 790 | case "$rest" in |
| 791 | "squash! "*|"fixup! "*) |
| 792 | prefix="$prefix${rest%%!*}," |
| 793 | rest="${rest#*! }" |
| 794 | ;; |
| 795 | *) |
| 796 | break |
| 797 | ;; |
| 798 | esac |
| 799 | done |
Uwe Storbeck | 47be066 | 2014-03-15 00:56:43 +0100 | [diff] [blame] | 800 | printf '%s %s %s %s\n' "$sha1" "$action" "$prefix" "$rest" |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 801 | # if it's a single word, try to resolve to a full sha1 and |
| 802 | # emit a second copy. This allows us to match on both message |
| 803 | # and on sha1 prefix |
| 804 | if test "${rest#* }" = "$rest"; then |
| 805 | fullsha="$(git rev-parse -q --verify "$rest" 2>/dev/null)" |
| 806 | if test -n "$fullsha"; then |
| 807 | # prefix the action to uniquely identify this line as |
| 808 | # intended for full sha1 match |
Andrew Pimlott | 22c5b13 | 2013-06-27 12:26:31 -0700 | [diff] [blame] | 809 | echo "$sha1 +$action $prefix $fullsha" |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 810 | fi |
| 811 | fi |
| 812 | esac |
| 813 | done >"$1.sq" <"$1" |
Nanako Shiraishi | f59baa5 | 2009-12-08 12:13:14 +0900 | [diff] [blame] | 814 | test -s "$1.sq" || return |
| 815 | |
| 816 | used= |
Junio C Hamano | 57f2b6b | 2010-07-05 23:08:36 -0700 | [diff] [blame] | 817 | while read -r pick sha1 message |
Nanako Shiraishi | f59baa5 | 2009-12-08 12:13:14 +0900 | [diff] [blame] | 818 | do |
| 819 | case " $used" in |
| 820 | *" $sha1 "*) continue ;; |
| 821 | esac |
Brandon Casey | 938791c | 2010-07-22 14:15:11 -0500 | [diff] [blame] | 822 | printf '%s\n' "$pick $sha1 $message" |
Michael Rappazzo | 16cf51c | 2015-06-13 12:26:58 -0400 | [diff] [blame] | 823 | test -z "${format}" || message=$(git log -n 1 --format="%s" ${sha1}) |
Kevin Ballard | d3d7a42 | 2010-11-04 15:36:31 -0700 | [diff] [blame] | 824 | used="$used$sha1 " |
Andrew Pimlott | 22c5b13 | 2013-06-27 12:26:31 -0700 | [diff] [blame] | 825 | while read -r squash action msg_prefix msg_content |
Nanako Shiraishi | f59baa5 | 2009-12-08 12:13:14 +0900 | [diff] [blame] | 826 | do |
Kevin Ballard | d3d7a42 | 2010-11-04 15:36:31 -0700 | [diff] [blame] | 827 | case " $used" in |
| 828 | *" $squash "*) continue ;; |
| 829 | esac |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 830 | emit=0 |
| 831 | case "$action" in |
| 832 | +*) |
| 833 | action="${action#+}" |
| 834 | # full sha1 prefix test |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 835 | case "$msg_content" in "$sha1"*) emit=1;; esac ;; |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 836 | *) |
| 837 | # message prefix test |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 838 | case "$message" in "$msg_content"*) emit=1;; esac ;; |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 839 | esac |
| 840 | if test $emit = 1; then |
Michael Rappazzo | 16cf51c | 2015-06-13 12:26:58 -0400 | [diff] [blame] | 841 | if test -n "${format}" |
| 842 | then |
| 843 | msg_content=$(git log -n 1 --format="${format}" ${squash}) |
| 844 | else |
| 845 | msg_content="$(echo "$msg_prefix" | sed "s/,/! /g")$msg_content" |
| 846 | fi |
| 847 | printf '%s\n' "$action $squash $msg_content" |
Nanako Shiraishi | f59baa5 | 2009-12-08 12:13:14 +0900 | [diff] [blame] | 848 | used="$used$squash " |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 849 | fi |
Nanako Shiraishi | f59baa5 | 2009-12-08 12:13:14 +0900 | [diff] [blame] | 850 | done <"$1.sq" |
| 851 | done >"$1.rearranged" <"$1" |
| 852 | cat "$1.rearranged" >"$1" |
| 853 | rm -f "$1.sq" "$1.rearranged" |
| 854 | } |
| 855 | |
Lucien Kong | c214538 | 2012-06-12 10:05:12 +0200 | [diff] [blame] | 856 | # Add commands after a pick or after a squash/fixup serie |
| 857 | # in the todo list. |
| 858 | add_exec_commands () { |
| 859 | { |
| 860 | first=t |
| 861 | while read -r insn rest |
| 862 | do |
| 863 | case $insn in |
| 864 | pick) |
| 865 | test -n "$first" || |
| 866 | printf "%s" "$cmd" |
| 867 | ;; |
| 868 | esac |
| 869 | printf "%s %s\n" "$insn" "$rest" |
| 870 | first= |
| 871 | done |
| 872 | printf "%s" "$cmd" |
| 873 | } <"$1" >"$1.new" && |
| 874 | mv "$1.new" "$1" |
| 875 | } |
| 876 | |
Galan Rémi | 804098b | 2015-06-29 22:20:32 +0200 | [diff] [blame] | 877 | # Check if the SHA-1 passed as an argument is a |
| 878 | # correct one, if not then print $2 in "$todo".badsha |
| 879 | # $1: the SHA-1 to test |
Matthieu Moy | 1db168e | 2015-10-01 10:18:42 +0200 | [diff] [blame] | 880 | # $2: the line number of the input |
| 881 | # $3: the input filename |
Galan Rémi | 804098b | 2015-06-29 22:20:32 +0200 | [diff] [blame] | 882 | check_commit_sha () { |
| 883 | badsha=0 |
Jeff King | 268ef4d | 2016-05-13 16:47:33 -0400 | [diff] [blame] | 884 | if test -z "$1" |
Galan Rémi | 804098b | 2015-06-29 22:20:32 +0200 | [diff] [blame] | 885 | then |
| 886 | badsha=1 |
| 887 | else |
| 888 | sha1_verif="$(git rev-parse --verify --quiet $1^{commit})" |
Jeff King | 268ef4d | 2016-05-13 16:47:33 -0400 | [diff] [blame] | 889 | if test -z "$sha1_verif" |
Galan Rémi | 804098b | 2015-06-29 22:20:32 +0200 | [diff] [blame] | 890 | then |
| 891 | badsha=1 |
| 892 | fi |
| 893 | fi |
| 894 | |
| 895 | if test $badsha -ne 0 |
| 896 | then |
Matthieu Moy | 1db168e | 2015-10-01 10:18:42 +0200 | [diff] [blame] | 897 | line="$(sed -n -e "${2}p" "$3")" |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 898 | warn "$(eval_gettext "\ |
| 899 | Warning: the SHA-1 is missing or isn't a commit in the following line: |
| 900 | - \$line")" |
Galan Rémi | 804098b | 2015-06-29 22:20:32 +0200 | [diff] [blame] | 901 | warn |
| 902 | fi |
| 903 | |
| 904 | return $badsha |
| 905 | } |
| 906 | |
| 907 | # prints the bad commits and bad commands |
| 908 | # from the todolist in stdin |
| 909 | check_bad_cmd_and_sha () { |
| 910 | retval=0 |
Matthieu Moy | 1db168e | 2015-10-01 10:18:42 +0200 | [diff] [blame] | 911 | lineno=0 |
| 912 | while read -r command rest |
| 913 | do |
| 914 | lineno=$(( $lineno + 1 )) |
| 915 | case $command in |
| 916 | "$comment_char"*|''|noop|x|exec) |
| 917 | # Doesn't expect a SHA-1 |
| 918 | ;; |
Junio C Hamano | 39743cf | 2015-10-28 15:54:48 +0100 | [diff] [blame] | 919 | "$cr") |
| 920 | # Work around CR left by "read" (e.g. with Git for |
| 921 | # Windows' Bash). |
| 922 | ;; |
Matthieu Moy | 1db168e | 2015-10-01 10:18:42 +0200 | [diff] [blame] | 923 | pick|p|drop|d|reword|r|edit|e|squash|s|fixup|f) |
| 924 | if ! check_commit_sha "${rest%%[ ]*}" "$lineno" "$1" |
| 925 | then |
Galan Rémi | 804098b | 2015-06-29 22:20:32 +0200 | [diff] [blame] | 926 | retval=1 |
Matthieu Moy | 1db168e | 2015-10-01 10:18:42 +0200 | [diff] [blame] | 927 | fi |
| 928 | ;; |
| 929 | *) |
| 930 | line="$(sed -n -e "${lineno}p" "$1")" |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 931 | warn "$(eval_gettext "\ |
| 932 | Warning: the command isn't recognized in the following line: |
| 933 | - \$line")" |
Matthieu Moy | 1db168e | 2015-10-01 10:18:42 +0200 | [diff] [blame] | 934 | warn |
| 935 | retval=1 |
| 936 | ;; |
| 937 | esac |
| 938 | done <"$1" |
| 939 | return $retval |
Galan Rémi | 804098b | 2015-06-29 22:20:32 +0200 | [diff] [blame] | 940 | } |
| 941 | |
Galan Rémi | 3707995 | 2015-06-29 22:20:31 +0200 | [diff] [blame] | 942 | # Print the list of the SHA-1 of the commits |
| 943 | # from stdin to stdout |
| 944 | todo_list_to_sha_list () { |
| 945 | git stripspace --strip-comments | |
| 946 | while read -r command sha1 rest |
| 947 | do |
| 948 | case $command in |
| 949 | "$comment_char"*|''|noop|x|"exec") |
| 950 | ;; |
| 951 | *) |
| 952 | long_sha=$(git rev-list --no-walk "$sha1" 2>/dev/null) |
| 953 | printf "%s\n" "$long_sha" |
| 954 | ;; |
| 955 | esac |
| 956 | done |
| 957 | } |
| 958 | |
| 959 | # Use warn for each line in stdin |
| 960 | warn_lines () { |
| 961 | while read -r line |
| 962 | do |
| 963 | warn " - $line" |
| 964 | done |
| 965 | } |
| 966 | |
| 967 | # Switch to the branch in $into and notify it in the reflog |
| 968 | checkout_onto () { |
| 969 | GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name" |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 970 | output git checkout $onto || die_abort "$(gettext "could not detach HEAD")" |
Galan Rémi | 3707995 | 2015-06-29 22:20:31 +0200 | [diff] [blame] | 971 | git update-ref ORIG_HEAD $orig_head |
| 972 | } |
| 973 | |
| 974 | get_missing_commit_check_level () { |
| 975 | check_level=$(git config --get rebase.missingCommitsCheck) |
| 976 | check_level=${check_level:-ignore} |
| 977 | # Don't be case sensitive |
| 978 | printf '%s' "$check_level" | tr 'A-Z' 'a-z' |
| 979 | } |
| 980 | |
| 981 | # Check if the user dropped some commits by mistake |
| 982 | # Behaviour determined by rebase.missingCommitsCheck. |
Galan Rémi | 804098b | 2015-06-29 22:20:32 +0200 | [diff] [blame] | 983 | # Check if there is an unrecognized command or a |
| 984 | # bad SHA-1 in a command. |
Galan Rémi | 3707995 | 2015-06-29 22:20:31 +0200 | [diff] [blame] | 985 | check_todo_list () { |
| 986 | raise_error=f |
| 987 | |
| 988 | check_level=$(get_missing_commit_check_level) |
| 989 | |
| 990 | case "$check_level" in |
| 991 | warn|error) |
| 992 | # Get the SHA-1 of the commits |
| 993 | todo_list_to_sha_list <"$todo".backup >"$todo".oldsha1 |
| 994 | todo_list_to_sha_list <"$todo" >"$todo".newsha1 |
| 995 | |
| 996 | # Sort the SHA-1 and compare them |
| 997 | sort -u "$todo".oldsha1 >"$todo".oldsha1+ |
| 998 | mv "$todo".oldsha1+ "$todo".oldsha1 |
| 999 | sort -u "$todo".newsha1 >"$todo".newsha1+ |
| 1000 | mv "$todo".newsha1+ "$todo".newsha1 |
| 1001 | comm -2 -3 "$todo".oldsha1 "$todo".newsha1 >"$todo".miss |
| 1002 | |
| 1003 | # Warn about missing commits |
| 1004 | if test -s "$todo".miss |
| 1005 | then |
| 1006 | test "$check_level" = error && raise_error=t |
| 1007 | |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1008 | warn "$(gettext "\ |
| 1009 | Warning: some commits may have been dropped accidentally. |
| 1010 | Dropped commits (newer to older):")" |
Galan Rémi | 3707995 | 2015-06-29 22:20:31 +0200 | [diff] [blame] | 1011 | |
| 1012 | # Make the list user-friendly and display |
| 1013 | opt="--no-walk=sorted --format=oneline --abbrev-commit --stdin" |
| 1014 | git rev-list $opt <"$todo".miss | warn_lines |
| 1015 | |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1016 | warn "$(gettext "\ |
| 1017 | To avoid this message, use \"drop\" to explicitly remove a commit. |
| 1018 | |
| 1019 | Use 'git config rebase.missingCommitsCheck' to change the level of warnings. |
| 1020 | The possible behaviours are: ignore, warn, error.")" |
Galan Rémi | 3707995 | 2015-06-29 22:20:31 +0200 | [diff] [blame] | 1021 | warn |
| 1022 | fi |
| 1023 | ;; |
| 1024 | ignore) |
| 1025 | ;; |
| 1026 | *) |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1027 | warn "$(eval_gettext "Unrecognized setting \$check_level for option rebase.missingCommitsCheck. Ignoring.")" |
Galan Rémi | 3707995 | 2015-06-29 22:20:31 +0200 | [diff] [blame] | 1028 | ;; |
| 1029 | esac |
| 1030 | |
Matthieu Moy | 1db168e | 2015-10-01 10:18:42 +0200 | [diff] [blame] | 1031 | if ! check_bad_cmd_and_sha "$todo" |
Galan Rémi | 804098b | 2015-06-29 22:20:32 +0200 | [diff] [blame] | 1032 | then |
| 1033 | raise_error=t |
| 1034 | fi |
| 1035 | |
Galan Rémi | 3707995 | 2015-06-29 22:20:31 +0200 | [diff] [blame] | 1036 | if test $raise_error = t |
| 1037 | then |
| 1038 | # Checkout before the first commit of the |
| 1039 | # rebase: this way git rebase --continue |
| 1040 | # will work correctly as it expects HEAD to be |
| 1041 | # placed before the commit of the next action |
| 1042 | checkout_onto |
| 1043 | |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1044 | warn "$(gettext "You can fix this with 'git rebase --edit-todo'.")" |
| 1045 | die "$(gettext "Or you can abort the rebase with 'git rebase --abort'.")" |
Galan Rémi | 3707995 | 2015-06-29 22:20:31 +0200 | [diff] [blame] | 1046 | fi |
| 1047 | } |
| 1048 | |
Kyle J. McKay | 9f50d32 | 2014-04-11 01:28:17 -0700 | [diff] [blame] | 1049 | # The whole contents of this file is run by dot-sourcing it from |
| 1050 | # inside a shell function. It used to be that "return"s we see |
| 1051 | # below were not inside any function, and expected to return |
| 1052 | # to the function that dot-sourced us. |
| 1053 | # |
Ed Maste | 9b35cad | 2016-06-17 11:33:29 -0400 | [diff] [blame] | 1054 | # However, older (9.x) versions of FreeBSD /bin/sh misbehave on such a |
| 1055 | # construct and continue to run the statements that follow such a "return". |
Kyle J. McKay | 9f50d32 | 2014-04-11 01:28:17 -0700 | [diff] [blame] | 1056 | # As a work-around, we introduce an extra layer of a function |
| 1057 | # here, and immediately call it after defining it. |
| 1058 | git_rebase__interactive () { |
| 1059 | |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1060 | case "$action" in |
| 1061 | continue) |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1062 | # do we have anything to commit? |
John Keeping | a6754cd | 2012-04-07 11:20:53 +0100 | [diff] [blame] | 1063 | if git diff-index --cached --quiet HEAD -- |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1064 | then |
Johannes Schindelin | 0e0aff4 | 2015-06-18 18:38:53 +0200 | [diff] [blame] | 1065 | # Nothing to commit -- skip this commit |
| 1066 | |
| 1067 | test ! -f "$GIT_DIR"/CHERRY_PICK_HEAD || |
| 1068 | rm "$GIT_DIR"/CHERRY_PICK_HEAD || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1069 | die "$(gettext "Could not remove CHERRY_PICK_HEAD")" |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1070 | else |
Matthieu Moy | ffaaed8 | 2011-08-24 16:01:48 +0200 | [diff] [blame] | 1071 | if ! test -f "$author_script" |
| 1072 | then |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 1073 | gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1074 | die "$(eval_gettext "\ |
| 1075 | You have staged changes in your working tree. |
| 1076 | If these changes are meant to be |
Matthieu Moy | ffaaed8 | 2011-08-24 16:01:48 +0200 | [diff] [blame] | 1077 | squashed into the previous commit, run: |
| 1078 | |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1079 | git commit --amend \$gpg_sign_opt_quoted |
Matthieu Moy | ffaaed8 | 2011-08-24 16:01:48 +0200 | [diff] [blame] | 1080 | |
| 1081 | If they are meant to go into a new commit, run: |
| 1082 | |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1083 | git commit \$gpg_sign_opt_quoted |
Matthieu Moy | ffaaed8 | 2011-08-24 16:01:48 +0200 | [diff] [blame] | 1084 | |
| 1085 | In both case, once you're done, continue with: |
| 1086 | |
| 1087 | git rebase --continue |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1088 | ")" |
Matthieu Moy | ffaaed8 | 2011-08-24 16:01:48 +0200 | [diff] [blame] | 1089 | fi |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1090 | . "$author_script" || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1091 | die "$(gettext "Error trying to find the author identity to amend commit")" |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1092 | if test -f "$amend" |
Shawn O. Pearce | 0327062 | 2007-12-20 02:12:12 -0500 | [diff] [blame] | 1093 | then |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1094 | current_head=$(git rev-parse --verify HEAD) |
| 1095 | test "$current_head" = $(cat "$amend") || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1096 | die "$(gettext "\ |
| 1097 | You have uncommitted changes in your working tree. Please commit them |
| 1098 | first and then run 'git rebase --continue' again.")" |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 1099 | do_with_author git commit --amend --no-verify -F "$msg" -e \ |
| 1100 | ${gpg_sign_opt:+"$gpg_sign_opt"} || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1101 | die "$(gettext "Could not commit staged changes.")" |
Chris Webb | 2147f84 | 2012-07-24 13:17:03 +0100 | [diff] [blame] | 1102 | else |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 1103 | do_with_author git commit --no-verify -F "$msg" -e \ |
| 1104 | ${gpg_sign_opt:+"$gpg_sign_opt"} || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1105 | die "$(gettext "Could not commit staged changes.")" |
Shawn O. Pearce | 0327062 | 2007-12-20 02:12:12 -0500 | [diff] [blame] | 1106 | fi |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1107 | fi |
Johannes Schindelin | 18640d9 | 2007-07-08 03:01:29 +0100 | [diff] [blame] | 1108 | |
Matthieu Moy | b12d3e9 | 2015-05-22 13:15:49 +0000 | [diff] [blame] | 1109 | if test -r "$state_dir"/stopped-sha |
| 1110 | then |
| 1111 | record_in_rewritten "$(cat "$state_dir"/stopped-sha)" |
| 1112 | fi |
Thomas Rast | 0acb62f | 2010-03-28 21:36:00 +0200 | [diff] [blame] | 1113 | |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1114 | require_clean_work_tree "rebase" |
| 1115 | do_rest |
Ramkumar Ramachandra | 15d4bf2 | 2013-05-12 17:26:39 +0530 | [diff] [blame] | 1116 | return 0 |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1117 | ;; |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1118 | skip) |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1119 | git rerere clear |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 1120 | |
Martin von Zweigbergk | 2959c28 | 2011-02-06 13:43:52 -0500 | [diff] [blame] | 1121 | do_rest |
Ramkumar Ramachandra | 15d4bf2 | 2013-05-12 17:26:39 +0530 | [diff] [blame] | 1122 | return 0 |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1123 | ;; |
Andrew Wong | eb9a7cb | 2012-09-17 21:28:09 -0400 | [diff] [blame] | 1124 | edit-todo) |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 1125 | git stripspace --strip-comments <"$todo" >"$todo".new |
Andrew Wong | eb9a7cb | 2012-09-17 21:28:09 -0400 | [diff] [blame] | 1126 | mv -f "$todo".new "$todo" |
Junio C Hamano | 75c6976 | 2013-08-23 20:10:42 -0400 | [diff] [blame] | 1127 | collapse_todo_ids |
Andrew Wong | eb9a7cb | 2012-09-17 21:28:09 -0400 | [diff] [blame] | 1128 | append_todo_help |
Vasco Almeida | b8fc9e4 | 2016-06-17 20:21:04 +0000 | [diff] [blame] | 1129 | gettext " |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 1130 | You are editing the todo file of an ongoing interactive rebase. |
| 1131 | To continue rebase after editing, run: |
| 1132 | git rebase --continue |
| 1133 | |
Vasco Almeida | b8fc9e4 | 2016-06-17 20:21:04 +0000 | [diff] [blame] | 1134 | " | git stripspace --comment-lines >>"$todo" |
Andrew Wong | eb9a7cb | 2012-09-17 21:28:09 -0400 | [diff] [blame] | 1135 | |
| 1136 | git_sequence_editor "$todo" || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1137 | die "$(gettext "Could not execute editor")" |
Junio C Hamano | 75c6976 | 2013-08-23 20:10:42 -0400 | [diff] [blame] | 1138 | expand_todo_ids |
Andrew Wong | eb9a7cb | 2012-09-17 21:28:09 -0400 | [diff] [blame] | 1139 | |
| 1140 | exit |
| 1141 | ;; |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1142 | esac |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 1143 | |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1144 | git var GIT_COMMITTER_IDENT >/dev/null || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1145 | die "$(gettext "You need to set your committer info first")" |
Thomas Rast | d8fab02 | 2009-01-02 23:28:26 +0100 | [diff] [blame] | 1146 | |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1147 | comment_for_reflog start |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 1148 | |
Martin von Zweigbergk | 71786f5 | 2011-02-06 13:43:42 -0500 | [diff] [blame] | 1149 | if test ! -z "$switch_to" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1150 | then |
Ramkumar Ramachandra | 26cd160 | 2013-06-16 14:15:13 +0530 | [diff] [blame] | 1151 | GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to" |
Martin von Zweigbergk | 71786f5 | 2011-02-06 13:43:42 -0500 | [diff] [blame] | 1152 | output git checkout "$switch_to" -- || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1153 | die "$(eval_gettext "Could not checkout \$switch_to")" |
Ramkumar Ramachandra | 26cd160 | 2013-06-16 14:15:13 +0530 | [diff] [blame] | 1154 | |
| 1155 | comment_for_reflog start |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1156 | fi |
Matt Kraai | 5166810 | 2007-09-25 18:30:13 -0700 | [diff] [blame] | 1157 | |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1158 | orig_head=$(git rev-parse --verify HEAD) || die "$(gettext "No HEAD?")" |
| 1159 | mkdir -p "$state_dir" || die "$(eval_gettext "Could not create temporary \$state_dir")" |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 1160 | |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1161 | : > "$state_dir"/interactive || die "$(gettext "Could not mark as interactive")" |
Martin von Zweigbergk | 84df456 | 2011-02-06 13:43:53 -0500 | [diff] [blame] | 1162 | write_basic_state |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1163 | if test t = "$preserve_merges" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1164 | then |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1165 | if test -z "$rebase_root" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1166 | then |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1167 | mkdir "$rewritten" && |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 1168 | for c in $(git merge-base --all $orig_head $upstream) |
Stephen Haberman | acc8559 | 2008-10-15 02:44:38 -0500 | [diff] [blame] | 1169 | do |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1170 | echo $onto > "$rewritten"/$c || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1171 | die "$(gettext "Could not init rewritten commits")" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1172 | done |
| 1173 | else |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1174 | mkdir "$rewritten" && |
| 1175 | echo $onto > "$rewritten"/root || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1176 | die "$(gettext "Could not init rewritten commits")" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1177 | fi |
| 1178 | # No cherry-pick because our first pass is to determine |
| 1179 | # parents to rewrite and skipping dropped commits would |
| 1180 | # prematurely end our probe |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1181 | merges_option= |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1182 | else |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1183 | merges_option="--no-merges --cherry-pick" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1184 | fi |
| 1185 | |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 1186 | shorthead=$(git rev-parse --short $orig_head) |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1187 | shortonto=$(git rev-parse --short $onto) |
| 1188 | if test -z "$rebase_root" |
| 1189 | # this is now equivalent to ! -z "$upstream" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1190 | then |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1191 | shortupstream=$(git rev-parse --short $upstream) |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 1192 | revisions=$upstream...$orig_head |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1193 | shortrevisions=$shortupstream..$shorthead |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1194 | else |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 1195 | revisions=$onto...$orig_head |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1196 | shortrevisions=$shorthead |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1197 | fi |
Michael Rappazzo | 16cf51c | 2015-06-13 12:26:58 -0400 | [diff] [blame] | 1198 | format=$(git config --get rebase.instructionFormat) |
| 1199 | # the 'rev-list .. | sed' requires %m to parse; the instruction requires %H to parse |
| 1200 | git rev-list $merges_option --format="%m%H ${format:-%s}" \ |
| 1201 | --reverse --left-right --topo-order \ |
John Keeping | 1e0dacd | 2014-07-16 20:23:49 +0100 | [diff] [blame] | 1202 | $revisions ${restrict_revision+^$restrict_revision} | \ |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1203 | sed -n "s/^>//p" | |
Kirill A. Shutemov | edb72d5 | 2015-01-22 13:50:15 +0200 | [diff] [blame] | 1204 | while read -r sha1 rest |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1205 | do |
Neil Horman | 90e1818 | 2012-04-20 10:36:17 -0400 | [diff] [blame] | 1206 | |
Kirill A. Shutemov | edb72d5 | 2015-01-22 13:50:15 +0200 | [diff] [blame] | 1207 | if test -z "$keep_empty" && is_empty_commit $sha1 && ! is_merge_commit $sha1 |
Neil Horman | 90e1818 | 2012-04-20 10:36:17 -0400 | [diff] [blame] | 1208 | then |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 1209 | comment_out="$comment_char " |
Neil Horman | 90e1818 | 2012-04-20 10:36:17 -0400 | [diff] [blame] | 1210 | else |
| 1211 | comment_out= |
| 1212 | fi |
| 1213 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1214 | if test t != "$preserve_merges" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1215 | then |
Kirill A. Shutemov | edb72d5 | 2015-01-22 13:50:15 +0200 | [diff] [blame] | 1216 | printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1217 | else |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1218 | if test -z "$rebase_root" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1219 | then |
| 1220 | preserve=t |
| 1221 | for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-) |
| 1222 | do |
Andrew Wong | 12bf828 | 2011-06-18 18:12:01 -0400 | [diff] [blame] | 1223 | if test -f "$rewritten"/$p |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 1224 | then |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 1225 | preserve=f |
| 1226 | fi |
Stephen Haberman | acc8559 | 2008-10-15 02:44:38 -0500 | [diff] [blame] | 1227 | done |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1228 | else |
| 1229 | preserve=f |
Stephen Haberman | acc8559 | 2008-10-15 02:44:38 -0500 | [diff] [blame] | 1230 | fi |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1231 | if test f = "$preserve" |
| 1232 | then |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1233 | touch "$rewritten"/$sha1 |
Kirill A. Shutemov | edb72d5 | 2015-01-22 13:50:15 +0200 | [diff] [blame] | 1234 | printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1235 | fi |
| 1236 | fi |
| 1237 | done |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 1238 | |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1239 | # Watch for commits that been dropped by --cherry-pick |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1240 | if test t = "$preserve_merges" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1241 | then |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1242 | mkdir "$dropped" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1243 | # Save all non-cherry-picked changes |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1244 | git rev-list $revisions --left-right --cherry-pick | \ |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 1245 | sed -n "s/^>//p" > "$state_dir"/not-cherry-picks |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1246 | # Now all commits and note which ones are missing in |
| 1247 | # not-cherry-picks and hence being dropped |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1248 | git rev-list $revisions | |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1249 | while read rev |
| 1250 | do |
Junio C Hamano | 214123c | 2016-03-08 15:51:36 -0800 | [diff] [blame] | 1251 | if test -f "$rewritten"/$rev && |
| 1252 | ! sane_grep "$rev" "$state_dir"/not-cherry-picks >/dev/null |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1253 | then |
| 1254 | # Use -f2 because if rev-list is telling us this commit is |
| 1255 | # not worthwhile, we don't want to track its multiple heads, |
| 1256 | # just the history of its first-parent for others that will |
| 1257 | # be rebasing on top of it |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1258 | git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$dropped"/$rev |
Kirill A. Shutemov | edb72d5 | 2015-01-22 13:50:15 +0200 | [diff] [blame] | 1259 | sha1=$(git rev-list -1 $rev) |
| 1260 | sane_grep -v "^[a-z][a-z]* $sha1" <"$todo" > "${todo}2" ; mv "${todo}2" "$todo" |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1261 | rm "$rewritten"/$rev |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1262 | fi |
| 1263 | done |
| 1264 | fi |
| 1265 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1266 | test -s "$todo" || echo noop >> "$todo" |
| 1267 | test -n "$autosquash" && rearrange_squash "$todo" |
Lucien Kong | c214538 | 2012-06-12 10:05:12 +0200 | [diff] [blame] | 1268 | test -n "$cmd" && add_exec_commands "$todo" |
| 1269 | |
Onno Kortmann | 97f05f4 | 2014-12-10 19:16:44 +0100 | [diff] [blame] | 1270 | todocount=$(git stripspace --strip-comments <"$todo" | wc -l) |
Eric Sunshine | 28c8cfc | 2015-03-04 02:53:04 -0500 | [diff] [blame] | 1271 | todocount=${todocount##* } |
Onno Kortmann | 97f05f4 | 2014-12-10 19:16:44 +0100 | [diff] [blame] | 1272 | |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 1273 | cat >>"$todo" <<EOF |
Johannes Schindelin | 6047a23 | 2007-11-22 12:30:10 +0000 | [diff] [blame] | 1274 | |
Vasco Almeida | b8fc9e4 | 2016-06-17 20:21:04 +0000 | [diff] [blame] | 1275 | $comment_char $(eval_ngettext \ |
| 1276 | "Rebase \$shortrevisions onto \$shortonto (\$todocount command)" \ |
| 1277 | "Rebase \$shortrevisions onto \$shortonto (\$todocount commands)" \ |
| 1278 | "$todocount") |
Andrew Wong | fcc5ef1 | 2012-09-17 21:28:08 -0400 | [diff] [blame] | 1279 | EOF |
| 1280 | append_todo_help |
Vasco Almeida | b8fc9e4 | 2016-06-17 20:21:04 +0000 | [diff] [blame] | 1281 | gettext " |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 1282 | However, if you remove everything, the rebase will be aborted. |
| 1283 | |
Vasco Almeida | b8fc9e4 | 2016-06-17 20:21:04 +0000 | [diff] [blame] | 1284 | " | git stripspace --comment-lines >>"$todo" |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 1285 | |
Neil Horman | 90e1818 | 2012-04-20 10:36:17 -0400 | [diff] [blame] | 1286 | if test -z "$keep_empty" |
| 1287 | then |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1288 | printf '%s\n' "$comment_char $(gettext "Note that empty commits are commented out")" >>"$todo" |
Neil Horman | 90e1818 | 2012-04-20 10:36:17 -0400 | [diff] [blame] | 1289 | fi |
| 1290 | |
| 1291 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1292 | has_action "$todo" || |
Ramkumar Ramachandra | e4244eb | 2014-05-19 18:05:20 -0400 | [diff] [blame] | 1293 | return 2 |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 1294 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1295 | cp "$todo" "$todo".backup |
Kirill A. Shutemov | edb72d5 | 2015-01-22 13:50:15 +0200 | [diff] [blame] | 1296 | collapse_todo_ids |
Peter Oberndorfer | 821881d | 2011-10-17 22:26:23 +0200 | [diff] [blame] | 1297 | git_sequence_editor "$todo" || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1298 | die_abort "$(gettext "Could not execute editor")" |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 1299 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1300 | has_action "$todo" || |
Ramkumar Ramachandra | e4244eb | 2014-05-19 18:05:20 -0400 | [diff] [blame] | 1301 | return 2 |
Johannes Schindelin | c54b781 | 2007-06-25 18:56:55 +0100 | [diff] [blame] | 1302 | |
Galan Rémi | 3707995 | 2015-06-29 22:20:31 +0200 | [diff] [blame] | 1303 | check_todo_list |
| 1304 | |
Junio C Hamano | 75c6976 | 2013-08-23 20:10:42 -0400 | [diff] [blame] | 1305 | expand_todo_ids |
| 1306 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1307 | test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks |
Johannes Schindelin | 0e757e3 | 2009-03-03 10:55:31 +0100 | [diff] [blame] | 1308 | |
Galan Rémi | 3707995 | 2015-06-29 22:20:31 +0200 | [diff] [blame] | 1309 | checkout_onto |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1310 | do_rest |
Kyle J. McKay | 9f50d32 | 2014-04-11 01:28:17 -0700 | [diff] [blame] | 1311 | |
| 1312 | } |
| 1313 | # ... and then we call the whole thing. |
| 1314 | git_rebase__interactive |