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" |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [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" |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 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 |
| 407 | case "$n" in |
| 408 | 1) gettext "This is the 1st commit message:";; |
| 409 | 2) gettext "This is the 2nd commit message:";; |
| 410 | 3) gettext "This is the 3rd commit message:";; |
| 411 | 4) gettext "This is the 4th commit message:";; |
| 412 | 5) gettext "This is the 5th commit message:";; |
| 413 | 6) gettext "This is the 6th commit message:";; |
| 414 | 7) gettext "This is the 7th commit message:";; |
| 415 | 8) gettext "This is the 8th commit message:";; |
| 416 | 9) gettext "This is the 9th commit message:";; |
| 417 | 10) gettext "This is the 10th commit message:";; |
| 418 | # TRANSLATORS: if the language you are translating into |
| 419 | # doesn't allow you to compose a sentence in this fashion, |
| 420 | # consider translating as if this and the following few strings |
| 421 | # were "This is the commit message ${n}:" |
| 422 | *1[0-9]|*[04-9]) eval_gettext "This is the \${n}th commit message:";; |
| 423 | *1) eval_gettext "This is the \${n}st commit message:";; |
| 424 | *2) eval_gettext "This is the \${n}nd commit message:";; |
| 425 | *3) eval_gettext "This is the \${n}rd commit message:";; |
| 426 | *) eval_gettext "This is the commit message \${n}:";; |
| 427 | esac |
| 428 | } |
| 429 | skip_nth_commit_message () { |
| 430 | n=$1 |
| 431 | case "$n" in |
| 432 | 1) gettext "The 1st commit message will be skipped:";; |
| 433 | 2) gettext "The 2nd commit message will be skipped:";; |
| 434 | 3) gettext "The 3rd commit message will be skipped:";; |
| 435 | 4) gettext "The 4th commit message will be skipped:";; |
| 436 | 5) gettext "The 5th commit message will be skipped:";; |
| 437 | 6) gettext "The 6th commit message will be skipped:";; |
| 438 | 7) gettext "The 7th commit message will be skipped:";; |
| 439 | 8) gettext "The 8th commit message will be skipped:";; |
| 440 | 9) gettext "The 9th commit message will be skipped:";; |
| 441 | 10) gettext "The 10th commit message will be skipped:";; |
| 442 | # TRANSLATORS: if the language you are translating into |
| 443 | # doesn't allow you to compose a sentence in this fashion, |
| 444 | # consider translating as if this and the following few strings |
| 445 | # were "The commit message ${n} will be skipped:" |
| 446 | *1[0-9]|*[04-9]) eval_gettext "The \${n}th commit message will be skipped:";; |
| 447 | *1) eval_gettext "The \${n}st commit message will be skipped:";; |
| 448 | *2) eval_gettext "The \${n}nd commit message will be skipped:";; |
| 449 | *3) eval_gettext "The \${n}rd commit message will be skipped:";; |
| 450 | *) eval_gettext "The commit message \${n} will be skipped:";; |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 451 | esac |
| 452 | } |
| 453 | |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 454 | update_squash_messages () { |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 455 | if test -f "$squash_msg"; then |
| 456 | mv "$squash_msg" "$squash_msg".bak || exit |
| 457 | count=$(($(sed -n \ |
Vasco Almeida | f2d1706 | 2016-06-17 20:21:05 +0000 | [diff] [blame] | 458 | -e "1s/^$comment_char.*\([0-9][0-9]*\).*/\1/p" \ |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 459 | -e "q" < "$squash_msg".bak)+1)) |
Michael Haggerty | bde1a68 | 2010-01-14 06:54:54 +0100 | [diff] [blame] | 460 | { |
Vasco Almeida | f2d1706 | 2016-06-17 20:21:05 +0000 | [diff] [blame] | 461 | printf '%s\n' "$comment_char $(eval_ngettext \ |
| 462 | "This is a combination of \$count commit." \ |
| 463 | "This is a combination of \$count commits." \ |
| 464 | $count)" |
Michael Haggerty | bde1a68 | 2010-01-14 06:54:54 +0100 | [diff] [blame] | 465 | sed -e 1d -e '2,/^./{ |
| 466 | /^$/d |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 467 | }' <"$squash_msg".bak |
| 468 | } >"$squash_msg" |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 469 | else |
Vasco Almeida | f2d1706 | 2016-06-17 20:21:05 +0000 | [diff] [blame] | 470 | commit_message HEAD > "$fixup_msg" || die "$(gettext "Cannot write \$fixup_msg")" |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 471 | count=2 |
Michael Haggerty | bde1a68 | 2010-01-14 06:54:54 +0100 | [diff] [blame] | 472 | { |
Vasco Almeida | f2d1706 | 2016-06-17 20:21:05 +0000 | [diff] [blame] | 473 | printf '%s\n' "$comment_char $(gettext "This is a combination of 2 commits.")" |
| 474 | printf '%s\n' "$comment_char $(gettext "This is the 1st commit message:")" |
Michael Haggerty | bde1a68 | 2010-01-14 06:54:54 +0100 | [diff] [blame] | 475 | echo |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 476 | cat "$fixup_msg" |
| 477 | } >"$squash_msg" |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 478 | fi |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 479 | case $1 in |
| 480 | squash) |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 481 | rm -f "$fixup_msg" |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 482 | echo |
Vasco Almeida | f2d1706 | 2016-06-17 20:21:05 +0000 | [diff] [blame] | 483 | printf '%s\n' "$comment_char $(this_nth_commit_message $count)" |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 484 | echo |
Michael Haggerty | ee0a4af | 2010-01-14 06:54:51 +0100 | [diff] [blame] | 485 | commit_message $2 |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 486 | ;; |
| 487 | fixup) |
| 488 | echo |
Vasco Almeida | f2d1706 | 2016-06-17 20:21:05 +0000 | [diff] [blame] | 489 | printf '%s\n' "$comment_char $(skip_nth_commit_message $count)" |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 490 | echo |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 491 | # Change the space after the comment character to TAB: |
| 492 | commit_message $2 | git stripspace --comment-lines | sed -e 's/ / /' |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 493 | ;; |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 494 | esac >>"$squash_msg" |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | peek_next_command () { |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 498 | git stripspace --strip-comments <"$todo" | sed -n -e 's/ .*//p' -e q |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 499 | } |
| 500 | |
Michael Haggerty | 6bdcd0d | 2010-01-14 06:54:57 +0100 | [diff] [blame] | 501 | # A squash/fixup has failed. Prepare the long version of the squash |
| 502 | # commit message, then die_with_patch. This code path requires the |
| 503 | # user to edit the combined commit message for all commits that have |
| 504 | # been squashed/fixedup so far. So also erase the old squash |
| 505 | # messages, effectively causing the combined commit to be used as the |
| 506 | # new basis for any further squash/fixups. Args: sha1 rest |
| 507 | die_failed_squash() { |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 508 | sha1=$1 |
| 509 | rest=$2 |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 510 | mv "$squash_msg" "$msg" || exit |
| 511 | rm -f "$fixup_msg" |
| 512 | cp "$msg" "$GIT_DIR"/MERGE_MSG || exit |
Michael Haggerty | 6bdcd0d | 2010-01-14 06:54:57 +0100 | [diff] [blame] | 513 | warn |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 514 | warn "$(eval_gettext "Could not apply \$sha1... \$rest")" |
| 515 | die_with_patch $sha1 "" |
Michael Haggerty | 6bdcd0d | 2010-01-14 06:54:57 +0100 | [diff] [blame] | 516 | } |
| 517 | |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 518 | flush_rewritten_pending() { |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 519 | test -s "$rewritten_pending" || return |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 520 | newsha1="$(git rev-parse HEAD^0)" |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 521 | sed "s/$/ $newsha1/" < "$rewritten_pending" >> "$rewritten_list" |
| 522 | rm -f "$rewritten_pending" |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | record_in_rewritten() { |
| 526 | oldsha1="$(git rev-parse $1)" |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 527 | echo "$oldsha1" >> "$rewritten_pending" |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 528 | |
| 529 | case "$(peek_next_command)" in |
Junio C Hamano | 41f556b | 2010-07-05 22:16:15 -0700 | [diff] [blame] | 530 | squash|s|fixup|f) |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 531 | ;; |
Junio C Hamano | 41f556b | 2010-07-05 22:16:15 -0700 | [diff] [blame] | 532 | *) |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 533 | flush_rewritten_pending |
| 534 | ;; |
| 535 | esac |
| 536 | } |
| 537 | |
Chris Webb | df5df20 | 2012-06-26 22:55:23 +0100 | [diff] [blame] | 538 | do_pick () { |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 539 | sha1=$1 |
| 540 | rest=$2 |
Chris Webb | df5df20 | 2012-06-26 22:55:23 +0100 | [diff] [blame] | 541 | if test "$(git rev-parse HEAD)" = "$squash_onto" |
| 542 | then |
| 543 | # Set the correct commit message and author info on the |
| 544 | # sentinel root before cherry-picking the original changes |
| 545 | # without committing (-n). Finally, update the sentinel again |
| 546 | # to include these changes. If the cherry-pick results in a |
| 547 | # conflict, this means our behaviour is similar to a standard |
| 548 | # failed cherry-pick during rebase, with a dirty index to |
| 549 | # resolve before manually running git commit --amend then git |
| 550 | # rebase --continue. |
| 551 | git commit --allow-empty --allow-empty-message --amend \ |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 552 | --no-post-rewrite -n -q -C $sha1 && |
| 553 | pick_one -n $sha1 && |
Chris Webb | df5df20 | 2012-06-26 22:55:23 +0100 | [diff] [blame] | 554 | git commit --allow-empty --allow-empty-message \ |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 555 | --amend --no-post-rewrite -n -q -C $sha1 \ |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 556 | ${gpg_sign_opt:+"$gpg_sign_opt"} || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 557 | die_with_patch $sha1 "$(eval_gettext "Could not apply \$sha1... \$rest")" |
Chris Webb | df5df20 | 2012-06-26 22:55:23 +0100 | [diff] [blame] | 558 | else |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 559 | pick_one $sha1 || |
| 560 | die_with_patch $sha1 "$(eval_gettext "Could not apply \$sha1... \$rest")" |
Chris Webb | df5df20 | 2012-06-26 22:55:23 +0100 | [diff] [blame] | 561 | fi |
| 562 | } |
| 563 | |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 564 | do_next () { |
Matthieu Moy | b12d3e9 | 2015-05-22 13:15:49 +0000 | [diff] [blame] | 565 | rm -f "$msg" "$author_script" "$amend" "$state_dir"/stopped-sha || exit |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 566 | read -r command sha1 rest < "$todo" |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 567 | case "$command" in |
Galan Rémi | c9266d5 | 2015-06-29 22:20:30 +0200 | [diff] [blame] | 568 | "$comment_char"*|''|noop|drop|d) |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 569 | mark_action_done |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 570 | ;; |
Junio C Hamano | 39743cf | 2015-10-28 15:54:48 +0100 | [diff] [blame] | 571 | "$cr") |
| 572 | # Work around CR left by "read" (e.g. with Git for Windows' Bash). |
| 573 | mark_action_done |
| 574 | ;; |
Johannes Schindelin | f8babc4 | 2007-09-29 03:32:11 +0100 | [diff] [blame] | 575 | pick|p) |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 576 | comment_for_reflog pick |
| 577 | |
| 578 | mark_action_done |
Chris Webb | df5df20 | 2012-06-26 22:55:23 +0100 | [diff] [blame] | 579 | do_pick $sha1 "$rest" |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 580 | record_in_rewritten $sha1 |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 581 | ;; |
Björn Gustavsson | 6741aa6 | 2009-10-07 08:13:23 +0200 | [diff] [blame] | 582 | reword|r) |
| 583 | comment_for_reflog reword |
| 584 | |
| 585 | mark_action_done |
Chris Webb | df5df20 | 2012-06-26 22:55:23 +0100 | [diff] [blame] | 586 | do_pick $sha1 "$rest" |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 587 | git commit --amend --no-post-rewrite ${gpg_sign_opt:+"$gpg_sign_opt"} || { |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 588 | warn "$(eval_gettext "\ |
| 589 | Could not amend commit after successfully picking \$sha1... \$rest |
| 590 | This is most likely due to an empty commit message, or the pre-commit hook |
| 591 | failed. If the pre-commit hook failed, you may need to resolve the issue before |
| 592 | you are able to reword the commit.")" |
Andrew Wong | 0becb3e | 2011-11-30 10:52:51 -0500 | [diff] [blame] | 593 | exit_with_patch $sha1 1 |
| 594 | } |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 595 | record_in_rewritten $sha1 |
Björn Gustavsson | 6741aa6 | 2009-10-07 08:13:23 +0200 | [diff] [blame] | 596 | ;; |
Johannes Schindelin | f8babc4 | 2007-09-29 03:32:11 +0100 | [diff] [blame] | 597 | edit|e) |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 598 | comment_for_reflog edit |
| 599 | |
| 600 | mark_action_done |
Chris Webb | df5df20 | 2012-06-26 22:55:23 +0100 | [diff] [blame] | 601 | do_pick $sha1 "$rest" |
Ralf Thielow | 14c793e | 2016-03-28 18:00:00 +0200 | [diff] [blame] | 602 | sha1_abbrev=$(git rev-parse --short $sha1) |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 603 | warn "$(eval_gettext "Stopped at \$sha1_abbrev... \$rest")" |
Andrew Wong | 0becb3e | 2011-11-30 10:52:51 -0500 | [diff] [blame] | 604 | exit_with_patch $sha1 0 |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 605 | ;; |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 606 | squash|s|fixup|f) |
| 607 | case "$command" in |
| 608 | squash|s) |
| 609 | squash_style=squash |
| 610 | ;; |
| 611 | fixup|f) |
| 612 | squash_style=fixup |
| 613 | ;; |
| 614 | esac |
| 615 | comment_for_reflog $squash_style |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 616 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 617 | test -f "$done" && has_action "$done" || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 618 | die "$(eval_gettext "Cannot '\$squash_style' without a previous commit")" |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 619 | |
| 620 | mark_action_done |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 621 | update_squash_messages $squash_style $sha1 |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 622 | author_script_content=$(get_author_ident_from_commit HEAD) |
| 623 | echo "$author_script_content" > "$author_script" |
| 624 | eval "$author_script_content" |
Chris Webb | 2147f84 | 2012-07-24 13:17:03 +0100 | [diff] [blame] | 625 | if ! pick_one -n $sha1 |
| 626 | then |
| 627 | git rev-parse --verify HEAD >"$amend" |
| 628 | die_failed_squash $sha1 "$rest" |
| 629 | fi |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 630 | case "$(peek_next_command)" in |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 631 | squash|s|fixup|f) |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 632 | # This is an intermediate commit; its message will only be |
| 633 | # used in case of trouble. So use the long version: |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 634 | do_with_author output git commit --amend --no-verify -F "$squash_msg" \ |
| 635 | ${gpg_sign_opt:+"$gpg_sign_opt"} || |
Michael Haggerty | 6bdcd0d | 2010-01-14 06:54:57 +0100 | [diff] [blame] | 636 | die_failed_squash $sha1 "$rest" |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 637 | ;; |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 638 | *) |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 639 | # This is the final command of this squash/fixup group |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 640 | if test -f "$fixup_msg" |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 641 | then |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 642 | do_with_author git commit --amend --no-verify -F "$fixup_msg" \ |
| 643 | ${gpg_sign_opt:+"$gpg_sign_opt"} || |
Michael Haggerty | 6bdcd0d | 2010-01-14 06:54:57 +0100 | [diff] [blame] | 644 | die_failed_squash $sha1 "$rest" |
| 645 | else |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 646 | cp "$squash_msg" "$GIT_DIR"/SQUASH_MSG || exit |
Michael Haggerty | 6bdcd0d | 2010-01-14 06:54:57 +0100 | [diff] [blame] | 647 | rm -f "$GIT_DIR"/MERGE_MSG |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 648 | do_with_author git commit --amend --no-verify -F "$GIT_DIR"/SQUASH_MSG -e \ |
| 649 | ${gpg_sign_opt:+"$gpg_sign_opt"} || |
Michael Haggerty | 6bdcd0d | 2010-01-14 06:54:57 +0100 | [diff] [blame] | 650 | die_failed_squash $sha1 "$rest" |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 651 | fi |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 652 | rm -f "$squash_msg" "$fixup_msg" |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 653 | ;; |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 654 | esac |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 655 | record_in_rewritten $sha1 |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 656 | ;; |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 657 | x|"exec") |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 658 | read -r command rest < "$todo" |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 659 | mark_action_done |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 660 | eval_gettextln "Executing: \$rest" |
Fredrik Medley | fe9394a | 2015-11-13 07:03:19 +0100 | [diff] [blame] | 661 | "${SHELL:-@SHELL_PATH@}" -c "$rest" # Actual execution |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 662 | status=$? |
Junio C Hamano | 1686519 | 2011-08-24 11:54:50 -0700 | [diff] [blame] | 663 | # Run in subshell because require_clean_work_tree can die. |
| 664 | dirty=f |
| 665 | (require_clean_work_tree "rebase" 2>/dev/null) || dirty=t |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 666 | if test "$status" -ne 0 |
| 667 | then |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 668 | warn "$(eval_gettext "Execution failed: \$rest")" |
Junio C Hamano | 1686519 | 2011-08-24 11:54:50 -0700 | [diff] [blame] | 669 | test "$dirty" = f || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 670 | 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] | 671 | |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 672 | warn "$(gettext "\ |
| 673 | You can fix the problem, and then run |
| 674 | |
| 675 | git rebase --continue")" |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 676 | warn |
Johannes Sixt | ecfe1ea | 2012-09-18 13:15:26 +0200 | [diff] [blame] | 677 | if test $status -eq 127 # command not found |
| 678 | then |
| 679 | status=1 |
| 680 | fi |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 681 | exit "$status" |
Junio C Hamano | 1686519 | 2011-08-24 11:54:50 -0700 | [diff] [blame] | 682 | elif test "$dirty" = t |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 683 | then |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 684 | # TRANSLATORS: after these lines is a command to be issued by the user |
| 685 | warn "$(eval_gettext "\ |
| 686 | Execution succeeded: \$rest |
| 687 | but left changes to the index and/or the working tree |
| 688 | Commit or stash your changes, and then run |
| 689 | |
| 690 | git rebase --continue")" |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 691 | warn |
| 692 | exit 1 |
| 693 | fi |
| 694 | ;; |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 695 | *) |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 696 | warn "$(eval_gettext "Unknown command: \$command \$sha1 \$rest")" |
| 697 | fixtodo="$(gettext "Please fix this using 'git rebase --edit-todo'.")" |
Jan Krüger | f1be316 | 2009-10-27 15:58:14 +0100 | [diff] [blame] | 698 | if git rev-parse --verify -q "$sha1" >/dev/null |
| 699 | then |
Johannes Sixt | 9c8e101 | 2012-09-19 08:43:54 +0200 | [diff] [blame] | 700 | die_with_patch $sha1 "$fixtodo" |
Jan Krüger | f1be316 | 2009-10-27 15:58:14 +0100 | [diff] [blame] | 701 | else |
Johannes Sixt | 9c8e101 | 2012-09-19 08:43:54 +0200 | [diff] [blame] | 702 | die "$fixtodo" |
Jan Krüger | f1be316 | 2009-10-27 15:58:14 +0100 | [diff] [blame] | 703 | fi |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 704 | ;; |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 705 | esac |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 706 | test -s "$todo" && return |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 707 | |
Johannes Schindelin | 68a163c | 2007-06-25 18:58:28 +0100 | [diff] [blame] | 708 | comment_for_reflog finish && |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 709 | newhead=$(git rev-parse HEAD) && |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 710 | case $head_name in |
Johannes Schindelin | 73697a0 | 2007-09-25 16:43:15 +0100 | [diff] [blame] | 711 | refs/*) |
Michael J Gruber | 1af221e | 2012-08-10 08:51:19 +0200 | [diff] [blame] | 712 | message="$GIT_REFLOG_ACTION: $head_name onto $onto" && |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 713 | git update-ref -m "$message" $head_name $newhead $orig_head && |
Jeff King | 53f2ffa | 2011-05-27 16:16:14 -0400 | [diff] [blame] | 714 | git symbolic-ref \ |
| 715 | -m "$GIT_REFLOG_ACTION: returning to $head_name" \ |
| 716 | HEAD $head_name |
Johannes Schindelin | 73697a0 | 2007-09-25 16:43:15 +0100 | [diff] [blame] | 717 | ;; |
| 718 | esac && { |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 719 | test ! -f "$state_dir"/verbose || |
Martin von Zweigbergk | 2959c28 | 2011-02-06 13:43:52 -0500 | [diff] [blame] | 720 | git diff-tree --stat $orig_head..HEAD |
Johannes Schindelin | 3df0a85 | 2007-07-08 03:02:13 +0100 | [diff] [blame] | 721 | } && |
Thomas Rast | eb2151b | 2010-03-12 18:04:33 +0100 | [diff] [blame] | 722 | { |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 723 | test -s "$rewritten_list" && |
| 724 | git notes copy --for-rewrite=rebase < "$rewritten_list" || |
Thomas Rast | eb2151b | 2010-03-12 18:04:33 +0100 | [diff] [blame] | 725 | true # we don't care if this copying failed |
| 726 | } && |
Nguyễn Thái Ngọc Duy | b849b95 | 2014-11-30 15:24:38 +0700 | [diff] [blame] | 727 | hook="$(git rev-parse --git-path hooks/post-rewrite)" |
| 728 | if test -x "$hook" && test -s "$rewritten_list"; then |
| 729 | "$hook" rebase < "$rewritten_list" |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 730 | true # we don't care if this hook failed |
| 731 | fi && |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 732 | warn "$(eval_gettext "Successfully rebased and updated \$head_name.")" |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 733 | |
Ramkumar Ramachandra | 15d4bf2 | 2013-05-12 17:26:39 +0530 | [diff] [blame] | 734 | return 1 # not failure; just to break the do_rest loop |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 735 | } |
| 736 | |
Ramkumar Ramachandra | 15d4bf2 | 2013-05-12 17:26:39 +0530 | [diff] [blame] | 737 | # can only return 0, when the infinite loop breaks |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 738 | do_rest () { |
| 739 | while : |
| 740 | do |
Ramkumar Ramachandra | 15d4bf2 | 2013-05-12 17:26:39 +0530 | [diff] [blame] | 741 | do_next || break |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 742 | done |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 743 | } |
| 744 | |
Johannes Schindelin | 0e757e3 | 2009-03-03 10:55:31 +0100 | [diff] [blame] | 745 | # skip picking commits whose parents are unchanged |
| 746 | skip_unnecessary_picks () { |
| 747 | fd=3 |
Brandon Casey | 2d6ca6e | 2010-08-13 15:47:34 -0500 | [diff] [blame] | 748 | while read -r command rest |
Johannes Schindelin | 0e757e3 | 2009-03-03 10:55:31 +0100 | [diff] [blame] | 749 | do |
| 750 | # fd=3 means we skip the command |
Brandon Casey | 2d6ca6e | 2010-08-13 15:47:34 -0500 | [diff] [blame] | 751 | case "$fd,$command" in |
| 752 | 3,pick|3,p) |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 753 | # pick a commit whose parent is current $onto -> skip |
Chris Johnsen | 14d8729 | 2010-09-17 16:42:51 -0500 | [diff] [blame] | 754 | sha1=${rest%% *} |
Brandon Casey | 2d6ca6e | 2010-08-13 15:47:34 -0500 | [diff] [blame] | 755 | case "$(git rev-parse --verify --quiet "$sha1"^)" in |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 756 | "$onto"*) |
| 757 | onto=$sha1 |
Brandon Casey | 2d6ca6e | 2010-08-13 15:47:34 -0500 | [diff] [blame] | 758 | ;; |
| 759 | *) |
| 760 | fd=1 |
| 761 | ;; |
| 762 | esac |
Johannes Schindelin | 0e757e3 | 2009-03-03 10:55:31 +0100 | [diff] [blame] | 763 | ;; |
Eric Sunshine | 7bca7af | 2013-08-16 17:44:07 -0400 | [diff] [blame] | 764 | 3,"$comment_char"*|3,) |
Johannes Schindelin | 0e757e3 | 2009-03-03 10:55:31 +0100 | [diff] [blame] | 765 | # copy comments |
| 766 | ;; |
| 767 | *) |
| 768 | fd=1 |
| 769 | ;; |
| 770 | esac |
Brandon Casey | d1c3b10 | 2010-08-13 15:47:35 -0500 | [diff] [blame] | 771 | printf '%s\n' "$command${rest:+ }$rest" >&$fd |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 772 | done <"$todo" >"$todo.new" 3>>"$done" && |
| 773 | mv -f "$todo".new "$todo" && |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 774 | case "$(peek_next_command)" in |
| 775 | squash|s|fixup|f) |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 776 | record_in_rewritten "$onto" |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 777 | ;; |
| 778 | esac || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 779 | die "$(gettext "Could not skip unnecessary pick commands")" |
Johannes Schindelin | 0e757e3 | 2009-03-03 10:55:31 +0100 | [diff] [blame] | 780 | } |
| 781 | |
Junio C Hamano | 75c6976 | 2013-08-23 20:10:42 -0400 | [diff] [blame] | 782 | transform_todo_ids () { |
| 783 | while read -r command rest |
| 784 | do |
| 785 | case "$command" in |
| 786 | "$comment_char"* | exec) |
| 787 | # Be careful for oddball commands like 'exec' |
| 788 | # that do not have a SHA-1 at the beginning of $rest. |
| 789 | ;; |
| 790 | *) |
Matthieu Moy | 31bff64 | 2015-10-01 10:18:41 +0200 | [diff] [blame] | 791 | sha1=$(git rev-parse --verify --quiet "$@" ${rest%%[ ]*}) && |
| 792 | rest="$sha1 ${rest#*[ ]}" |
Junio C Hamano | 75c6976 | 2013-08-23 20:10:42 -0400 | [diff] [blame] | 793 | ;; |
| 794 | esac |
| 795 | printf '%s\n' "$command${rest:+ }$rest" |
| 796 | done <"$todo" >"$todo.new" && |
| 797 | mv -f "$todo.new" "$todo" |
| 798 | } |
| 799 | |
| 800 | expand_todo_ids() { |
| 801 | transform_todo_ids |
| 802 | } |
| 803 | |
| 804 | collapse_todo_ids() { |
Kirill A. Shutemov | 5689503 | 2013-09-28 18:53:05 +0300 | [diff] [blame] | 805 | transform_todo_ids --short |
Junio C Hamano | 75c6976 | 2013-08-23 20:10:42 -0400 | [diff] [blame] | 806 | } |
| 807 | |
Nanako Shiraishi | f59baa5 | 2009-12-08 12:13:14 +0900 | [diff] [blame] | 808 | # Rearrange the todo list that has both "pick sha1 msg" and |
| 809 | # "pick sha1 fixup!/squash! msg" appears in it so that the latter |
| 810 | # comes immediately after the former, and change "pick" to |
| 811 | # "fixup"/"squash". |
Michael Rappazzo | 16cf51c | 2015-06-13 12:26:58 -0400 | [diff] [blame] | 812 | # |
| 813 | # Note that if the config has specified a custom instruction format |
| 814 | # each log message will be re-retrieved in order to normalize the |
| 815 | # autosquash arrangement |
Nanako Shiraishi | f59baa5 | 2009-12-08 12:13:14 +0900 | [diff] [blame] | 816 | rearrange_squash () { |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 817 | # extract fixup!/squash! lines and resolve any referenced sha1's |
| 818 | while read -r pick sha1 message |
| 819 | do |
Michael Rappazzo | 16cf51c | 2015-06-13 12:26:58 -0400 | [diff] [blame] | 820 | test -z "${format}" || message=$(git log -n 1 --format="%s" ${sha1}) |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 821 | case "$message" in |
| 822 | "squash! "*|"fixup! "*) |
| 823 | action="${message%%!*}" |
Andrew Pimlott | 22c5b13 | 2013-06-27 12:26:31 -0700 | [diff] [blame] | 824 | rest=$message |
| 825 | prefix= |
| 826 | # skip all squash! or fixup! (but save for later) |
| 827 | while : |
| 828 | do |
| 829 | case "$rest" in |
| 830 | "squash! "*|"fixup! "*) |
| 831 | prefix="$prefix${rest%%!*}," |
| 832 | rest="${rest#*! }" |
| 833 | ;; |
| 834 | *) |
| 835 | break |
| 836 | ;; |
| 837 | esac |
| 838 | done |
Uwe Storbeck | 47be066 | 2014-03-15 00:56:43 +0100 | [diff] [blame] | 839 | printf '%s %s %s %s\n' "$sha1" "$action" "$prefix" "$rest" |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 840 | # if it's a single word, try to resolve to a full sha1 and |
| 841 | # emit a second copy. This allows us to match on both message |
| 842 | # and on sha1 prefix |
| 843 | if test "${rest#* }" = "$rest"; then |
| 844 | fullsha="$(git rev-parse -q --verify "$rest" 2>/dev/null)" |
| 845 | if test -n "$fullsha"; then |
| 846 | # prefix the action to uniquely identify this line as |
| 847 | # intended for full sha1 match |
Andrew Pimlott | 22c5b13 | 2013-06-27 12:26:31 -0700 | [diff] [blame] | 848 | echo "$sha1 +$action $prefix $fullsha" |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 849 | fi |
| 850 | fi |
| 851 | esac |
| 852 | done >"$1.sq" <"$1" |
Nanako Shiraishi | f59baa5 | 2009-12-08 12:13:14 +0900 | [diff] [blame] | 853 | test -s "$1.sq" || return |
| 854 | |
| 855 | used= |
Junio C Hamano | 57f2b6b | 2010-07-05 23:08:36 -0700 | [diff] [blame] | 856 | while read -r pick sha1 message |
Nanako Shiraishi | f59baa5 | 2009-12-08 12:13:14 +0900 | [diff] [blame] | 857 | do |
| 858 | case " $used" in |
| 859 | *" $sha1 "*) continue ;; |
| 860 | esac |
Brandon Casey | 938791c | 2010-07-22 14:15:11 -0500 | [diff] [blame] | 861 | printf '%s\n' "$pick $sha1 $message" |
Michael Rappazzo | 16cf51c | 2015-06-13 12:26:58 -0400 | [diff] [blame] | 862 | test -z "${format}" || message=$(git log -n 1 --format="%s" ${sha1}) |
Kevin Ballard | d3d7a42 | 2010-11-04 15:36:31 -0700 | [diff] [blame] | 863 | used="$used$sha1 " |
Andrew Pimlott | 22c5b13 | 2013-06-27 12:26:31 -0700 | [diff] [blame] | 864 | while read -r squash action msg_prefix msg_content |
Nanako Shiraishi | f59baa5 | 2009-12-08 12:13:14 +0900 | [diff] [blame] | 865 | do |
Kevin Ballard | d3d7a42 | 2010-11-04 15:36:31 -0700 | [diff] [blame] | 866 | case " $used" in |
| 867 | *" $squash "*) continue ;; |
| 868 | esac |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 869 | emit=0 |
| 870 | case "$action" in |
| 871 | +*) |
| 872 | action="${action#+}" |
| 873 | # full sha1 prefix test |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 874 | case "$msg_content" in "$sha1"*) emit=1;; esac ;; |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 875 | *) |
| 876 | # message prefix test |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 877 | case "$message" in "$msg_content"*) emit=1;; esac ;; |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 878 | esac |
| 879 | if test $emit = 1; then |
Michael Rappazzo | 16cf51c | 2015-06-13 12:26:58 -0400 | [diff] [blame] | 880 | if test -n "${format}" |
| 881 | then |
| 882 | msg_content=$(git log -n 1 --format="${format}" ${squash}) |
| 883 | else |
| 884 | msg_content="$(echo "$msg_prefix" | sed "s/,/! /g")$msg_content" |
| 885 | fi |
| 886 | printf '%s\n' "$action $squash $msg_content" |
Nanako Shiraishi | f59baa5 | 2009-12-08 12:13:14 +0900 | [diff] [blame] | 887 | used="$used$squash " |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 888 | fi |
Nanako Shiraishi | f59baa5 | 2009-12-08 12:13:14 +0900 | [diff] [blame] | 889 | done <"$1.sq" |
| 890 | done >"$1.rearranged" <"$1" |
| 891 | cat "$1.rearranged" >"$1" |
| 892 | rm -f "$1.sq" "$1.rearranged" |
| 893 | } |
| 894 | |
Lucien Kong | c214538 | 2012-06-12 10:05:12 +0200 | [diff] [blame] | 895 | # Add commands after a pick or after a squash/fixup serie |
| 896 | # in the todo list. |
| 897 | add_exec_commands () { |
| 898 | { |
| 899 | first=t |
| 900 | while read -r insn rest |
| 901 | do |
| 902 | case $insn in |
| 903 | pick) |
| 904 | test -n "$first" || |
| 905 | printf "%s" "$cmd" |
| 906 | ;; |
| 907 | esac |
| 908 | printf "%s %s\n" "$insn" "$rest" |
| 909 | first= |
| 910 | done |
| 911 | printf "%s" "$cmd" |
| 912 | } <"$1" >"$1.new" && |
| 913 | mv "$1.new" "$1" |
| 914 | } |
| 915 | |
Galan Rémi | 804098b | 2015-06-29 22:20:32 +0200 | [diff] [blame] | 916 | # Check if the SHA-1 passed as an argument is a |
| 917 | # correct one, if not then print $2 in "$todo".badsha |
| 918 | # $1: the SHA-1 to test |
Matthieu Moy | 1db168e | 2015-10-01 10:18:42 +0200 | [diff] [blame] | 919 | # $2: the line number of the input |
| 920 | # $3: the input filename |
Galan Rémi | 804098b | 2015-06-29 22:20:32 +0200 | [diff] [blame] | 921 | check_commit_sha () { |
| 922 | badsha=0 |
Jeff King | 268ef4d | 2016-05-13 16:47:33 -0400 | [diff] [blame] | 923 | if test -z "$1" |
Galan Rémi | 804098b | 2015-06-29 22:20:32 +0200 | [diff] [blame] | 924 | then |
| 925 | badsha=1 |
| 926 | else |
| 927 | sha1_verif="$(git rev-parse --verify --quiet $1^{commit})" |
Jeff King | 268ef4d | 2016-05-13 16:47:33 -0400 | [diff] [blame] | 928 | if test -z "$sha1_verif" |
Galan Rémi | 804098b | 2015-06-29 22:20:32 +0200 | [diff] [blame] | 929 | then |
| 930 | badsha=1 |
| 931 | fi |
| 932 | fi |
| 933 | |
| 934 | if test $badsha -ne 0 |
| 935 | then |
Matthieu Moy | 1db168e | 2015-10-01 10:18:42 +0200 | [diff] [blame] | 936 | line="$(sed -n -e "${2}p" "$3")" |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 937 | warn "$(eval_gettext "\ |
| 938 | Warning: the SHA-1 is missing or isn't a commit in the following line: |
| 939 | - \$line")" |
Galan Rémi | 804098b | 2015-06-29 22:20:32 +0200 | [diff] [blame] | 940 | warn |
| 941 | fi |
| 942 | |
| 943 | return $badsha |
| 944 | } |
| 945 | |
| 946 | # prints the bad commits and bad commands |
| 947 | # from the todolist in stdin |
| 948 | check_bad_cmd_and_sha () { |
| 949 | retval=0 |
Matthieu Moy | 1db168e | 2015-10-01 10:18:42 +0200 | [diff] [blame] | 950 | lineno=0 |
| 951 | while read -r command rest |
| 952 | do |
| 953 | lineno=$(( $lineno + 1 )) |
| 954 | case $command in |
| 955 | "$comment_char"*|''|noop|x|exec) |
| 956 | # Doesn't expect a SHA-1 |
| 957 | ;; |
Junio C Hamano | 39743cf | 2015-10-28 15:54:48 +0100 | [diff] [blame] | 958 | "$cr") |
| 959 | # Work around CR left by "read" (e.g. with Git for |
| 960 | # Windows' Bash). |
| 961 | ;; |
Matthieu Moy | 1db168e | 2015-10-01 10:18:42 +0200 | [diff] [blame] | 962 | pick|p|drop|d|reword|r|edit|e|squash|s|fixup|f) |
| 963 | if ! check_commit_sha "${rest%%[ ]*}" "$lineno" "$1" |
| 964 | then |
Galan Rémi | 804098b | 2015-06-29 22:20:32 +0200 | [diff] [blame] | 965 | retval=1 |
Matthieu Moy | 1db168e | 2015-10-01 10:18:42 +0200 | [diff] [blame] | 966 | fi |
| 967 | ;; |
| 968 | *) |
| 969 | line="$(sed -n -e "${lineno}p" "$1")" |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 970 | warn "$(eval_gettext "\ |
| 971 | Warning: the command isn't recognized in the following line: |
| 972 | - \$line")" |
Matthieu Moy | 1db168e | 2015-10-01 10:18:42 +0200 | [diff] [blame] | 973 | warn |
| 974 | retval=1 |
| 975 | ;; |
| 976 | esac |
| 977 | done <"$1" |
| 978 | return $retval |
Galan Rémi | 804098b | 2015-06-29 22:20:32 +0200 | [diff] [blame] | 979 | } |
| 980 | |
Galan Rémi | 3707995 | 2015-06-29 22:20:31 +0200 | [diff] [blame] | 981 | # Print the list of the SHA-1 of the commits |
| 982 | # from stdin to stdout |
| 983 | todo_list_to_sha_list () { |
| 984 | git stripspace --strip-comments | |
| 985 | while read -r command sha1 rest |
| 986 | do |
| 987 | case $command in |
| 988 | "$comment_char"*|''|noop|x|"exec") |
| 989 | ;; |
| 990 | *) |
| 991 | long_sha=$(git rev-list --no-walk "$sha1" 2>/dev/null) |
| 992 | printf "%s\n" "$long_sha" |
| 993 | ;; |
| 994 | esac |
| 995 | done |
| 996 | } |
| 997 | |
| 998 | # Use warn for each line in stdin |
| 999 | warn_lines () { |
| 1000 | while read -r line |
| 1001 | do |
| 1002 | warn " - $line" |
| 1003 | done |
| 1004 | } |
| 1005 | |
| 1006 | # Switch to the branch in $into and notify it in the reflog |
| 1007 | checkout_onto () { |
| 1008 | GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name" |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1009 | output git checkout $onto || die_abort "$(gettext "could not detach HEAD")" |
Galan Rémi | 3707995 | 2015-06-29 22:20:31 +0200 | [diff] [blame] | 1010 | git update-ref ORIG_HEAD $orig_head |
| 1011 | } |
| 1012 | |
| 1013 | get_missing_commit_check_level () { |
| 1014 | check_level=$(git config --get rebase.missingCommitsCheck) |
| 1015 | check_level=${check_level:-ignore} |
| 1016 | # Don't be case sensitive |
| 1017 | printf '%s' "$check_level" | tr 'A-Z' 'a-z' |
| 1018 | } |
| 1019 | |
| 1020 | # Check if the user dropped some commits by mistake |
| 1021 | # Behaviour determined by rebase.missingCommitsCheck. |
Galan Rémi | 804098b | 2015-06-29 22:20:32 +0200 | [diff] [blame] | 1022 | # Check if there is an unrecognized command or a |
| 1023 | # bad SHA-1 in a command. |
Galan Rémi | 3707995 | 2015-06-29 22:20:31 +0200 | [diff] [blame] | 1024 | check_todo_list () { |
| 1025 | raise_error=f |
| 1026 | |
| 1027 | check_level=$(get_missing_commit_check_level) |
| 1028 | |
| 1029 | case "$check_level" in |
| 1030 | warn|error) |
| 1031 | # Get the SHA-1 of the commits |
| 1032 | todo_list_to_sha_list <"$todo".backup >"$todo".oldsha1 |
| 1033 | todo_list_to_sha_list <"$todo" >"$todo".newsha1 |
| 1034 | |
| 1035 | # Sort the SHA-1 and compare them |
| 1036 | sort -u "$todo".oldsha1 >"$todo".oldsha1+ |
| 1037 | mv "$todo".oldsha1+ "$todo".oldsha1 |
| 1038 | sort -u "$todo".newsha1 >"$todo".newsha1+ |
| 1039 | mv "$todo".newsha1+ "$todo".newsha1 |
| 1040 | comm -2 -3 "$todo".oldsha1 "$todo".newsha1 >"$todo".miss |
| 1041 | |
| 1042 | # Warn about missing commits |
| 1043 | if test -s "$todo".miss |
| 1044 | then |
| 1045 | test "$check_level" = error && raise_error=t |
| 1046 | |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1047 | warn "$(gettext "\ |
| 1048 | Warning: some commits may have been dropped accidentally. |
| 1049 | Dropped commits (newer to older):")" |
Galan Rémi | 3707995 | 2015-06-29 22:20:31 +0200 | [diff] [blame] | 1050 | |
| 1051 | # Make the list user-friendly and display |
| 1052 | opt="--no-walk=sorted --format=oneline --abbrev-commit --stdin" |
| 1053 | git rev-list $opt <"$todo".miss | warn_lines |
| 1054 | |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1055 | warn "$(gettext "\ |
| 1056 | To avoid this message, use \"drop\" to explicitly remove a commit. |
| 1057 | |
| 1058 | Use 'git config rebase.missingCommitsCheck' to change the level of warnings. |
| 1059 | The possible behaviours are: ignore, warn, error.")" |
Galan Rémi | 3707995 | 2015-06-29 22:20:31 +0200 | [diff] [blame] | 1060 | warn |
| 1061 | fi |
| 1062 | ;; |
| 1063 | ignore) |
| 1064 | ;; |
| 1065 | *) |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1066 | 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] | 1067 | ;; |
| 1068 | esac |
| 1069 | |
Matthieu Moy | 1db168e | 2015-10-01 10:18:42 +0200 | [diff] [blame] | 1070 | if ! check_bad_cmd_and_sha "$todo" |
Galan Rémi | 804098b | 2015-06-29 22:20:32 +0200 | [diff] [blame] | 1071 | then |
| 1072 | raise_error=t |
| 1073 | fi |
| 1074 | |
Galan Rémi | 3707995 | 2015-06-29 22:20:31 +0200 | [diff] [blame] | 1075 | if test $raise_error = t |
| 1076 | then |
| 1077 | # Checkout before the first commit of the |
| 1078 | # rebase: this way git rebase --continue |
| 1079 | # will work correctly as it expects HEAD to be |
| 1080 | # placed before the commit of the next action |
| 1081 | checkout_onto |
| 1082 | |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1083 | warn "$(gettext "You can fix this with 'git rebase --edit-todo'.")" |
| 1084 | 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] | 1085 | fi |
| 1086 | } |
| 1087 | |
Kyle J. McKay | 9f50d32 | 2014-04-11 01:28:17 -0700 | [diff] [blame] | 1088 | # The whole contents of this file is run by dot-sourcing it from |
| 1089 | # inside a shell function. It used to be that "return"s we see |
| 1090 | # below were not inside any function, and expected to return |
| 1091 | # to the function that dot-sourced us. |
| 1092 | # |
Ed Maste | 9b35cad | 2016-06-17 11:33:29 -0400 | [diff] [blame] | 1093 | # However, older (9.x) versions of FreeBSD /bin/sh misbehave on such a |
| 1094 | # 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] | 1095 | # As a work-around, we introduce an extra layer of a function |
| 1096 | # here, and immediately call it after defining it. |
| 1097 | git_rebase__interactive () { |
| 1098 | |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1099 | case "$action" in |
| 1100 | continue) |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1101 | # do we have anything to commit? |
John Keeping | a6754cd | 2012-04-07 11:20:53 +0100 | [diff] [blame] | 1102 | if git diff-index --cached --quiet HEAD -- |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1103 | then |
Johannes Schindelin | 0e0aff4 | 2015-06-18 18:38:53 +0200 | [diff] [blame] | 1104 | # Nothing to commit -- skip this commit |
| 1105 | |
| 1106 | test ! -f "$GIT_DIR"/CHERRY_PICK_HEAD || |
| 1107 | rm "$GIT_DIR"/CHERRY_PICK_HEAD || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1108 | die "$(gettext "Could not remove CHERRY_PICK_HEAD")" |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1109 | else |
Matthieu Moy | ffaaed8 | 2011-08-24 16:01:48 +0200 | [diff] [blame] | 1110 | if ! test -f "$author_script" |
| 1111 | then |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 1112 | 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] | 1113 | die "$(eval_gettext "\ |
| 1114 | You have staged changes in your working tree. |
| 1115 | If these changes are meant to be |
Matthieu Moy | ffaaed8 | 2011-08-24 16:01:48 +0200 | [diff] [blame] | 1116 | squashed into the previous commit, run: |
| 1117 | |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1118 | git commit --amend \$gpg_sign_opt_quoted |
Matthieu Moy | ffaaed8 | 2011-08-24 16:01:48 +0200 | [diff] [blame] | 1119 | |
| 1120 | If they are meant to go into a new commit, run: |
| 1121 | |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1122 | git commit \$gpg_sign_opt_quoted |
Matthieu Moy | ffaaed8 | 2011-08-24 16:01:48 +0200 | [diff] [blame] | 1123 | |
| 1124 | In both case, once you're done, continue with: |
| 1125 | |
| 1126 | git rebase --continue |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1127 | ")" |
Matthieu Moy | ffaaed8 | 2011-08-24 16:01:48 +0200 | [diff] [blame] | 1128 | fi |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1129 | . "$author_script" || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1130 | 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] | 1131 | if test -f "$amend" |
Shawn O. Pearce | 0327062 | 2007-12-20 02:12:12 -0500 | [diff] [blame] | 1132 | then |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1133 | current_head=$(git rev-parse --verify HEAD) |
| 1134 | test "$current_head" = $(cat "$amend") || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1135 | die "$(gettext "\ |
| 1136 | You have uncommitted changes in your working tree. Please commit them |
| 1137 | first and then run 'git rebase --continue' again.")" |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 1138 | do_with_author git commit --amend --no-verify -F "$msg" -e \ |
| 1139 | ${gpg_sign_opt:+"$gpg_sign_opt"} || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1140 | die "$(gettext "Could not commit staged changes.")" |
Chris Webb | 2147f84 | 2012-07-24 13:17:03 +0100 | [diff] [blame] | 1141 | else |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 1142 | do_with_author git commit --no-verify -F "$msg" -e \ |
| 1143 | ${gpg_sign_opt:+"$gpg_sign_opt"} || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1144 | die "$(gettext "Could not commit staged changes.")" |
Shawn O. Pearce | 0327062 | 2007-12-20 02:12:12 -0500 | [diff] [blame] | 1145 | fi |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1146 | fi |
Johannes Schindelin | 18640d9 | 2007-07-08 03:01:29 +0100 | [diff] [blame] | 1147 | |
Matthieu Moy | b12d3e9 | 2015-05-22 13:15:49 +0000 | [diff] [blame] | 1148 | if test -r "$state_dir"/stopped-sha |
| 1149 | then |
| 1150 | record_in_rewritten "$(cat "$state_dir"/stopped-sha)" |
| 1151 | fi |
Thomas Rast | 0acb62f | 2010-03-28 21:36:00 +0200 | [diff] [blame] | 1152 | |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1153 | require_clean_work_tree "rebase" |
| 1154 | do_rest |
Ramkumar Ramachandra | 15d4bf2 | 2013-05-12 17:26:39 +0530 | [diff] [blame] | 1155 | return 0 |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1156 | ;; |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1157 | skip) |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1158 | git rerere clear |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 1159 | |
Martin von Zweigbergk | 2959c28 | 2011-02-06 13:43:52 -0500 | [diff] [blame] | 1160 | do_rest |
Ramkumar Ramachandra | 15d4bf2 | 2013-05-12 17:26:39 +0530 | [diff] [blame] | 1161 | return 0 |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1162 | ;; |
Andrew Wong | eb9a7cb | 2012-09-17 21:28:09 -0400 | [diff] [blame] | 1163 | edit-todo) |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 1164 | git stripspace --strip-comments <"$todo" >"$todo".new |
Andrew Wong | eb9a7cb | 2012-09-17 21:28:09 -0400 | [diff] [blame] | 1165 | mv -f "$todo".new "$todo" |
Junio C Hamano | 75c6976 | 2013-08-23 20:10:42 -0400 | [diff] [blame] | 1166 | collapse_todo_ids |
Andrew Wong | eb9a7cb | 2012-09-17 21:28:09 -0400 | [diff] [blame] | 1167 | append_todo_help |
Vasco Almeida | b8fc9e4 | 2016-06-17 20:21:04 +0000 | [diff] [blame] | 1168 | gettext " |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 1169 | You are editing the todo file of an ongoing interactive rebase. |
| 1170 | To continue rebase after editing, run: |
| 1171 | git rebase --continue |
| 1172 | |
Vasco Almeida | b8fc9e4 | 2016-06-17 20:21:04 +0000 | [diff] [blame] | 1173 | " | git stripspace --comment-lines >>"$todo" |
Andrew Wong | eb9a7cb | 2012-09-17 21:28:09 -0400 | [diff] [blame] | 1174 | |
| 1175 | git_sequence_editor "$todo" || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1176 | die "$(gettext "Could not execute editor")" |
Junio C Hamano | 75c6976 | 2013-08-23 20:10:42 -0400 | [diff] [blame] | 1177 | expand_todo_ids |
Andrew Wong | eb9a7cb | 2012-09-17 21:28:09 -0400 | [diff] [blame] | 1178 | |
| 1179 | exit |
| 1180 | ;; |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 1181 | esac |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 1182 | |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1183 | git var GIT_COMMITTER_IDENT >/dev/null || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1184 | die "$(gettext "You need to set your committer info first")" |
Thomas Rast | d8fab02 | 2009-01-02 23:28:26 +0100 | [diff] [blame] | 1185 | |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1186 | comment_for_reflog start |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 1187 | |
Martin von Zweigbergk | 71786f5 | 2011-02-06 13:43:42 -0500 | [diff] [blame] | 1188 | if test ! -z "$switch_to" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1189 | then |
Ramkumar Ramachandra | 26cd160 | 2013-06-16 14:15:13 +0530 | [diff] [blame] | 1190 | GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to" |
Martin von Zweigbergk | 71786f5 | 2011-02-06 13:43:42 -0500 | [diff] [blame] | 1191 | output git checkout "$switch_to" -- || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1192 | die "$(eval_gettext "Could not checkout \$switch_to")" |
Ramkumar Ramachandra | 26cd160 | 2013-06-16 14:15:13 +0530 | [diff] [blame] | 1193 | |
| 1194 | comment_for_reflog start |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1195 | fi |
Matt Kraai | 5166810 | 2007-09-25 18:30:13 -0700 | [diff] [blame] | 1196 | |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1197 | orig_head=$(git rev-parse --verify HEAD) || die "$(gettext "No HEAD?")" |
| 1198 | 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] | 1199 | |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1200 | : > "$state_dir"/interactive || die "$(gettext "Could not mark as interactive")" |
Martin von Zweigbergk | 84df456 | 2011-02-06 13:43:53 -0500 | [diff] [blame] | 1201 | write_basic_state |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1202 | if test t = "$preserve_merges" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1203 | then |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1204 | if test -z "$rebase_root" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1205 | then |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1206 | mkdir "$rewritten" && |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 1207 | for c in $(git merge-base --all $orig_head $upstream) |
Stephen Haberman | acc8559 | 2008-10-15 02:44:38 -0500 | [diff] [blame] | 1208 | do |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1209 | echo $onto > "$rewritten"/$c || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1210 | die "$(gettext "Could not init rewritten commits")" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1211 | done |
| 1212 | else |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1213 | mkdir "$rewritten" && |
| 1214 | echo $onto > "$rewritten"/root || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1215 | die "$(gettext "Could not init rewritten commits")" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1216 | fi |
| 1217 | # No cherry-pick because our first pass is to determine |
| 1218 | # parents to rewrite and skipping dropped commits would |
| 1219 | # prematurely end our probe |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1220 | merges_option= |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1221 | else |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1222 | merges_option="--no-merges --cherry-pick" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1223 | fi |
| 1224 | |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 1225 | shorthead=$(git rev-parse --short $orig_head) |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1226 | shortonto=$(git rev-parse --short $onto) |
| 1227 | if test -z "$rebase_root" |
| 1228 | # this is now equivalent to ! -z "$upstream" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1229 | then |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1230 | shortupstream=$(git rev-parse --short $upstream) |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 1231 | revisions=$upstream...$orig_head |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1232 | shortrevisions=$shortupstream..$shorthead |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1233 | else |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 1234 | revisions=$onto...$orig_head |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1235 | shortrevisions=$shorthead |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1236 | fi |
Michael Rappazzo | 16cf51c | 2015-06-13 12:26:58 -0400 | [diff] [blame] | 1237 | format=$(git config --get rebase.instructionFormat) |
| 1238 | # the 'rev-list .. | sed' requires %m to parse; the instruction requires %H to parse |
| 1239 | git rev-list $merges_option --format="%m%H ${format:-%s}" \ |
| 1240 | --reverse --left-right --topo-order \ |
John Keeping | 1e0dacd | 2014-07-16 20:23:49 +0100 | [diff] [blame] | 1241 | $revisions ${restrict_revision+^$restrict_revision} | \ |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1242 | sed -n "s/^>//p" | |
Kirill A. Shutemov | edb72d5 | 2015-01-22 13:50:15 +0200 | [diff] [blame] | 1243 | while read -r sha1 rest |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1244 | do |
Neil Horman | 90e1818 | 2012-04-20 10:36:17 -0400 | [diff] [blame] | 1245 | |
Kirill A. Shutemov | edb72d5 | 2015-01-22 13:50:15 +0200 | [diff] [blame] | 1246 | 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] | 1247 | then |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 1248 | comment_out="$comment_char " |
Neil Horman | 90e1818 | 2012-04-20 10:36:17 -0400 | [diff] [blame] | 1249 | else |
| 1250 | comment_out= |
| 1251 | fi |
| 1252 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1253 | if test t != "$preserve_merges" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1254 | then |
Kirill A. Shutemov | edb72d5 | 2015-01-22 13:50:15 +0200 | [diff] [blame] | 1255 | printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1256 | else |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1257 | if test -z "$rebase_root" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1258 | then |
| 1259 | preserve=t |
| 1260 | for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-) |
| 1261 | do |
Andrew Wong | 12bf828 | 2011-06-18 18:12:01 -0400 | [diff] [blame] | 1262 | if test -f "$rewritten"/$p |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 1263 | then |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 1264 | preserve=f |
| 1265 | fi |
Stephen Haberman | acc8559 | 2008-10-15 02:44:38 -0500 | [diff] [blame] | 1266 | done |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1267 | else |
| 1268 | preserve=f |
Stephen Haberman | acc8559 | 2008-10-15 02:44:38 -0500 | [diff] [blame] | 1269 | fi |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1270 | if test f = "$preserve" |
| 1271 | then |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1272 | touch "$rewritten"/$sha1 |
Kirill A. Shutemov | edb72d5 | 2015-01-22 13:50:15 +0200 | [diff] [blame] | 1273 | printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1274 | fi |
| 1275 | fi |
| 1276 | done |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 1277 | |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1278 | # Watch for commits that been dropped by --cherry-pick |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1279 | if test t = "$preserve_merges" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1280 | then |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1281 | mkdir "$dropped" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1282 | # Save all non-cherry-picked changes |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1283 | git rev-list $revisions --left-right --cherry-pick | \ |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 1284 | sed -n "s/^>//p" > "$state_dir"/not-cherry-picks |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1285 | # Now all commits and note which ones are missing in |
| 1286 | # not-cherry-picks and hence being dropped |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1287 | git rev-list $revisions | |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1288 | while read rev |
| 1289 | do |
Junio C Hamano | 214123c | 2016-03-08 15:51:36 -0800 | [diff] [blame] | 1290 | if test -f "$rewritten"/$rev && |
| 1291 | ! sane_grep "$rev" "$state_dir"/not-cherry-picks >/dev/null |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1292 | then |
| 1293 | # Use -f2 because if rev-list is telling us this commit is |
| 1294 | # not worthwhile, we don't want to track its multiple heads, |
| 1295 | # just the history of its first-parent for others that will |
| 1296 | # be rebasing on top of it |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1297 | 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] | 1298 | sha1=$(git rev-list -1 $rev) |
| 1299 | 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] | 1300 | rm "$rewritten"/$rev |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1301 | fi |
| 1302 | done |
| 1303 | fi |
| 1304 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1305 | test -s "$todo" || echo noop >> "$todo" |
| 1306 | test -n "$autosquash" && rearrange_squash "$todo" |
Lucien Kong | c214538 | 2012-06-12 10:05:12 +0200 | [diff] [blame] | 1307 | test -n "$cmd" && add_exec_commands "$todo" |
| 1308 | |
Onno Kortmann | 97f05f4 | 2014-12-10 19:16:44 +0100 | [diff] [blame] | 1309 | todocount=$(git stripspace --strip-comments <"$todo" | wc -l) |
Eric Sunshine | 28c8cfc | 2015-03-04 02:53:04 -0500 | [diff] [blame] | 1310 | todocount=${todocount##* } |
Onno Kortmann | 97f05f4 | 2014-12-10 19:16:44 +0100 | [diff] [blame] | 1311 | |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 1312 | cat >>"$todo" <<EOF |
Johannes Schindelin | 6047a23 | 2007-11-22 12:30:10 +0000 | [diff] [blame] | 1313 | |
Vasco Almeida | b8fc9e4 | 2016-06-17 20:21:04 +0000 | [diff] [blame] | 1314 | $comment_char $(eval_ngettext \ |
| 1315 | "Rebase \$shortrevisions onto \$shortonto (\$todocount command)" \ |
| 1316 | "Rebase \$shortrevisions onto \$shortonto (\$todocount commands)" \ |
| 1317 | "$todocount") |
Andrew Wong | fcc5ef1 | 2012-09-17 21:28:08 -0400 | [diff] [blame] | 1318 | EOF |
| 1319 | append_todo_help |
Vasco Almeida | b8fc9e4 | 2016-06-17 20:21:04 +0000 | [diff] [blame] | 1320 | gettext " |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 1321 | However, if you remove everything, the rebase will be aborted. |
| 1322 | |
Vasco Almeida | b8fc9e4 | 2016-06-17 20:21:04 +0000 | [diff] [blame] | 1323 | " | git stripspace --comment-lines >>"$todo" |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 1324 | |
Neil Horman | 90e1818 | 2012-04-20 10:36:17 -0400 | [diff] [blame] | 1325 | if test -z "$keep_empty" |
| 1326 | then |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1327 | 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] | 1328 | fi |
| 1329 | |
| 1330 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1331 | has_action "$todo" || |
Ramkumar Ramachandra | e4244eb | 2014-05-19 18:05:20 -0400 | [diff] [blame] | 1332 | return 2 |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 1333 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1334 | cp "$todo" "$todo".backup |
Kirill A. Shutemov | edb72d5 | 2015-01-22 13:50:15 +0200 | [diff] [blame] | 1335 | collapse_todo_ids |
Peter Oberndorfer | 821881d | 2011-10-17 22:26:23 +0200 | [diff] [blame] | 1336 | git_sequence_editor "$todo" || |
Vasco Almeida | 9588c52 | 2016-06-17 20:21:03 +0000 | [diff] [blame] | 1337 | die_abort "$(gettext "Could not execute editor")" |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 1338 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1339 | has_action "$todo" || |
Ramkumar Ramachandra | e4244eb | 2014-05-19 18:05:20 -0400 | [diff] [blame] | 1340 | return 2 |
Johannes Schindelin | c54b781 | 2007-06-25 18:56:55 +0100 | [diff] [blame] | 1341 | |
Galan Rémi | 3707995 | 2015-06-29 22:20:31 +0200 | [diff] [blame] | 1342 | check_todo_list |
| 1343 | |
Junio C Hamano | 75c6976 | 2013-08-23 20:10:42 -0400 | [diff] [blame] | 1344 | expand_todo_ids |
| 1345 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1346 | test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks |
Johannes Schindelin | 0e757e3 | 2009-03-03 10:55:31 +0100 | [diff] [blame] | 1347 | |
Galan Rémi | 3707995 | 2015-06-29 22:20:31 +0200 | [diff] [blame] | 1348 | checkout_onto |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1349 | do_rest |
Kyle J. McKay | 9f50d32 | 2014-04-11 01:28:17 -0700 | [diff] [blame] | 1350 | |
| 1351 | } |
| 1352 | # ... and then we call the whole thing. |
| 1353 | git_rebase__interactive |