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 | |
Arnaud Fontaine | db2b3b8 | 2013-07-02 17:05:48 +0900 | [diff] [blame] | 80 | strategy_args= |
| 81 | if test -n "$do_merge" |
| 82 | then |
| 83 | strategy_args=${strategy:+--strategy=$strategy} |
| 84 | eval ' |
| 85 | for strategy_opt in '"$strategy_opts"' |
| 86 | do |
| 87 | strategy_args="$strategy_args -X$(git rev-parse --sq-quote "${strategy_opt#--}")" |
| 88 | done |
| 89 | ' |
| 90 | fi |
| 91 | |
Martin von Zweigbergk | 89c7ae9 | 2011-02-06 13:43:49 -0500 | [diff] [blame] | 92 | GIT_CHERRY_PICK_HELP="$resolvemsg" |
Wincent Colaiuta | 804c717 | 2007-11-28 00:06:36 -0800 | [diff] [blame] | 93 | export GIT_CHERRY_PICK_HELP |
| 94 | |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 95 | comment_char=$(git config --get core.commentchar 2>/dev/null | cut -c1) |
| 96 | : ${comment_char:=#} |
| 97 | |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 98 | warn () { |
Brandon Casey | 938791c | 2010-07-22 14:15:11 -0500 | [diff] [blame] | 99 | printf '%s\n' "$*" >&2 |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 100 | } |
| 101 | |
Michael Haggerty | ee0a4af | 2010-01-14 06:54:51 +0100 | [diff] [blame] | 102 | # Output the commit message for the specified commit. |
| 103 | commit_message () { |
| 104 | git cat-file commit "$1" | sed "1,/^$/d" |
| 105 | } |
| 106 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 107 | orig_reflog_action="$GIT_REFLOG_ACTION" |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 108 | |
| 109 | comment_for_reflog () { |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 110 | case "$orig_reflog_action" in |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 111 | ''|rebase*) |
| 112 | GIT_REFLOG_ACTION="rebase -i ($1)" |
| 113 | export GIT_REFLOG_ACTION |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 114 | ;; |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 115 | esac |
| 116 | } |
| 117 | |
Junio C Hamano | 4e67387 | 2008-01-14 20:01:21 -0800 | [diff] [blame] | 118 | last_count= |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 119 | mark_action_done () { |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 120 | sed -e 1q < "$todo" >> "$done" |
| 121 | sed -e 1d < "$todo" >> "$todo".new |
| 122 | mv -f "$todo".new "$todo" |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 123 | new_count=$(git stripspace --strip-comments <"$done" | wc -l) |
Zoltan Klinger | b71dc3e | 2013-04-25 19:28:54 +1000 | [diff] [blame] | 124 | echo $new_count >"$msgnum" |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 125 | total=$(($new_count + $(git stripspace --strip-comments <"$todo" | wc -l))) |
Zoltan Klinger | b71dc3e | 2013-04-25 19:28:54 +1000 | [diff] [blame] | 126 | echo $total >"$end" |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 127 | if test "$last_count" != "$new_count" |
Junio C Hamano | 4e67387 | 2008-01-14 20:01:21 -0800 | [diff] [blame] | 128 | then |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 129 | last_count=$new_count |
| 130 | printf "Rebasing (%d/%d)\r" $new_count $total |
| 131 | test -z "$verbose" || echo |
Junio C Hamano | 4e67387 | 2008-01-14 20:01:21 -0800 | [diff] [blame] | 132 | fi |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 133 | } |
| 134 | |
Andrew Wong | fcc5ef1 | 2012-09-17 21:28:08 -0400 | [diff] [blame] | 135 | append_todo_help () { |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 136 | git stripspace --comment-lines >>"$todo" <<\EOF |
| 137 | |
| 138 | Commands: |
| 139 | p, pick = use commit |
| 140 | r, reword = use commit, but edit the commit message |
| 141 | e, edit = use commit, but stop for amending |
| 142 | s, squash = use commit, but meld into previous commit |
| 143 | f, fixup = like "squash", but discard this commit's log message |
| 144 | x, exec = run command (the rest of the line) using shell |
| 145 | |
| 146 | These lines can be re-ordered; they are executed from top to bottom. |
| 147 | |
| 148 | If you remove a line here THAT COMMIT WILL BE LOST. |
Andrew Wong | fcc5ef1 | 2012-09-17 21:28:08 -0400 | [diff] [blame] | 149 | EOF |
| 150 | } |
| 151 | |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 152 | make_patch () { |
Johannes Schindelin | 4fb1a19 | 2008-12-22 22:16:51 +0100 | [diff] [blame] | 153 | sha1_and_parents="$(git rev-list --parents -1 "$1")" |
| 154 | case "$sha1_and_parents" in |
| 155 | ?*' '?*' '?*) |
| 156 | git diff --cc $sha1_and_parents |
| 157 | ;; |
| 158 | ?*' '?*) |
| 159 | git diff-tree -p "$1^!" |
| 160 | ;; |
| 161 | *) |
| 162 | echo "Root commit" |
| 163 | ;; |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 164 | esac > "$state_dir"/patch |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 165 | test -f "$msg" || |
| 166 | commit_message "$1" > "$msg" |
| 167 | test -f "$author_script" || |
| 168 | get_author_ident_from_commit "$1" > "$author_script" |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | die_with_patch () { |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 172 | echo "$1" > "$state_dir"/stopped-sha |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 173 | make_patch "$1" |
Johannes Schindelin | ecfe72f | 2007-11-22 11:18:10 +0000 | [diff] [blame] | 174 | git rerere |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 175 | die "$2" |
| 176 | } |
| 177 | |
Andrew Wong | 0becb3e | 2011-11-30 10:52:51 -0500 | [diff] [blame] | 178 | exit_with_patch () { |
| 179 | echo "$1" > "$state_dir"/stopped-sha |
| 180 | make_patch $1 |
| 181 | git rev-parse --verify HEAD > "$amend" |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 182 | gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} |
Andrew Wong | 0becb3e | 2011-11-30 10:52:51 -0500 | [diff] [blame] | 183 | warn "You can amend the commit now, with" |
| 184 | warn |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 185 | warn " git commit --amend $gpg_sign_opt_quoted" |
Andrew Wong | 0becb3e | 2011-11-30 10:52:51 -0500 | [diff] [blame] | 186 | warn |
| 187 | warn "Once you are satisfied with your changes, run" |
| 188 | warn |
| 189 | warn " git rebase --continue" |
| 190 | warn |
| 191 | exit $2 |
| 192 | } |
| 193 | |
Johannes Schindelin | c54b781 | 2007-06-25 18:56:55 +0100 | [diff] [blame] | 194 | die_abort () { |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 195 | rm -rf "$state_dir" |
Johannes Schindelin | c54b781 | 2007-06-25 18:56:55 +0100 | [diff] [blame] | 196 | die "$1" |
| 197 | } |
| 198 | |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 199 | has_action () { |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 200 | test -n "$(git stripspace --strip-comments <"$1")" |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 201 | } |
| 202 | |
Neil Horman | 90e1818 | 2012-04-20 10:36:17 -0400 | [diff] [blame] | 203 | is_empty_commit() { |
| 204 | tree=$(git rev-parse -q --verify "$1"^{tree} 2>/dev/null || |
| 205 | die "$1: not a commit that can be picked") |
| 206 | ptree=$(git rev-parse -q --verify "$1"^^{tree} 2>/dev/null || |
| 207 | ptree=4b825dc642cb6eb9a060e54bf8d69288fbee4904) |
| 208 | test "$tree" = "$ptree" |
| 209 | } |
| 210 | |
Phil Hord | 9869778 | 2013-01-12 15:46:01 -0500 | [diff] [blame] | 211 | is_merge_commit() |
| 212 | { |
| 213 | git rev-parse --verify --quiet "$1"^2 >/dev/null 2>&1 |
| 214 | } |
| 215 | |
Michael Haggerty | 7756ecf | 2010-01-14 06:54:53 +0100 | [diff] [blame] | 216 | # Run command with GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and |
| 217 | # GIT_AUTHOR_DATE exported from the current environment. |
| 218 | do_with_author () { |
Junio C Hamano | 76c9c0d | 2010-01-22 13:09:24 -0800 | [diff] [blame] | 219 | ( |
| 220 | export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE |
| 221 | "$@" |
| 222 | ) |
Michael Haggerty | 7756ecf | 2010-01-14 06:54:53 +0100 | [diff] [blame] | 223 | } |
| 224 | |
Peter Oberndorfer | 821881d | 2011-10-17 22:26:23 +0200 | [diff] [blame] | 225 | git_sequence_editor () { |
| 226 | if test -z "$GIT_SEQUENCE_EDITOR" |
| 227 | then |
| 228 | GIT_SEQUENCE_EDITOR="$(git config sequence.editor)" |
| 229 | if [ -z "$GIT_SEQUENCE_EDITOR" ] |
| 230 | then |
| 231 | GIT_SEQUENCE_EDITOR="$(git var GIT_EDITOR)" || return $? |
| 232 | fi |
| 233 | fi |
| 234 | |
| 235 | eval "$GIT_SEQUENCE_EDITOR" '"$@"' |
| 236 | } |
| 237 | |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 238 | pick_one () { |
Christian Couder | 8e75abf | 2010-03-06 21:34:46 +0100 | [diff] [blame] | 239 | ff=--ff |
Neil Horman | 90e1818 | 2012-04-20 10:36:17 -0400 | [diff] [blame] | 240 | |
Christian Couder | 8e75abf | 2010-03-06 21:34:46 +0100 | [diff] [blame] | 241 | case "$1" in -n) sha1=$2; ff= ;; *) sha1=$1 ;; esac |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 242 | case "$force_rebase" in '') ;; ?*) ff= ;; esac |
Johannes Schindelin | dfa49f3 | 2007-07-23 23:45:49 +0100 | [diff] [blame] | 243 | output git rev-parse --verify $sha1 || die "Invalid commit name: $sha1" |
Neil Horman | 90e1818 | 2012-04-20 10:36:17 -0400 | [diff] [blame] | 244 | |
| 245 | if is_empty_commit "$sha1" |
| 246 | then |
| 247 | empty_args="--allow-empty" |
| 248 | fi |
| 249 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 250 | test -d "$rewritten" && |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 251 | pick_one_preserving_merges "$@" && return |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 252 | output eval git cherry-pick \ |
| 253 | ${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \ |
| 254 | "$strategy_args" $empty_args $ff "$@" |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 255 | } |
| 256 | |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 257 | pick_one_preserving_merges () { |
Thomas Rast | 71d9451 | 2008-08-13 23:41:23 +0200 | [diff] [blame] | 258 | fast_forward=t |
| 259 | case "$1" in |
| 260 | -n) |
| 261 | fast_forward=f |
| 262 | sha1=$2 |
| 263 | ;; |
| 264 | *) |
| 265 | sha1=$1 |
| 266 | ;; |
| 267 | esac |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 268 | sha1=$(git rev-parse $sha1) |
| 269 | |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 270 | if test -f "$state_dir"/current-commit |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 271 | then |
Junio C Hamano | 4c1360f | 2008-10-22 11:59:30 -0700 | [diff] [blame] | 272 | if test "$fast_forward" = t |
Stephen Haberman | bb64507 | 2008-10-15 02:44:36 -0500 | [diff] [blame] | 273 | then |
Junio C Hamano | 41f556b | 2010-07-05 22:16:15 -0700 | [diff] [blame] | 274 | while read current_commit |
Stephen Haberman | bb64507 | 2008-10-15 02:44:36 -0500 | [diff] [blame] | 275 | do |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 276 | git rev-parse HEAD > "$rewritten"/$current_commit |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 277 | done <"$state_dir"/current-commit |
| 278 | rm "$state_dir"/current-commit || |
Stephen Haberman | bb64507 | 2008-10-15 02:44:36 -0500 | [diff] [blame] | 279 | die "Cannot write current commit's replacement sha1" |
| 280 | fi |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 281 | fi |
| 282 | |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 283 | echo $sha1 >> "$state_dir"/current-commit |
Thomas Rast | a96dc01 | 2008-08-13 23:41:24 +0200 | [diff] [blame] | 284 | |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 285 | # rewrite parents; if none were rewritten, we can fast-forward. |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 286 | new_parents= |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 287 | pend=" $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)" |
| 288 | if test "$pend" = " " |
| 289 | then |
| 290 | pend=" root" |
| 291 | fi |
Stephen Haberman | faae853 | 2008-10-05 23:26:52 -0500 | [diff] [blame] | 292 | while [ "$pend" != "" ] |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 293 | do |
Stephen Haberman | faae853 | 2008-10-05 23:26:52 -0500 | [diff] [blame] | 294 | p=$(expr "$pend" : ' \([^ ]*\)') |
| 295 | pend="${pend# $p}" |
| 296 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 297 | if test -f "$rewritten"/$p |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 298 | then |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 299 | new_p=$(cat "$rewritten"/$p) |
Stephen Haberman | 80fe82e | 2008-10-15 02:44:40 -0500 | [diff] [blame] | 300 | |
| 301 | # If the todo reordered commits, and our parent is marked for |
| 302 | # rewriting, but hasn't been gotten to yet, assume the user meant to |
| 303 | # drop it on top of the current HEAD |
| 304 | if test -z "$new_p" |
| 305 | then |
| 306 | new_p=$(git rev-parse HEAD) |
| 307 | fi |
| 308 | |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 309 | test $p != $new_p && fast_forward=f |
| 310 | case "$new_parents" in |
| 311 | *$new_p*) |
| 312 | ;; # do nothing; that parent is already there |
| 313 | *) |
| 314 | new_parents="$new_parents $new_p" |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 315 | ;; |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 316 | esac |
Stephan Beyer | 1c5fa0a | 2008-07-16 03:51:49 +0200 | [diff] [blame] | 317 | else |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 318 | if test -f "$dropped"/$p |
Stephen Haberman | faae853 | 2008-10-05 23:26:52 -0500 | [diff] [blame] | 319 | then |
| 320 | fast_forward=f |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 321 | replacement="$(cat "$dropped"/$p)" |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 322 | test -z "$replacement" && replacement=root |
| 323 | pend=" $replacement$pend" |
Stephen Haberman | faae853 | 2008-10-05 23:26:52 -0500 | [diff] [blame] | 324 | else |
| 325 | new_parents="$new_parents $p" |
| 326 | fi |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 327 | fi |
| 328 | done |
| 329 | case $fast_forward in |
| 330 | t) |
Felipe Contreras | a75d7b5 | 2009-10-24 11:31:32 +0300 | [diff] [blame] | 331 | output warn "Fast-forward to $sha1" |
Thomas Rast | 71d9451 | 2008-08-13 23:41:23 +0200 | [diff] [blame] | 332 | output git reset --hard $sha1 || |
Felipe Contreras | a75d7b5 | 2009-10-24 11:31:32 +0300 | [diff] [blame] | 333 | die "Cannot fast-forward to $sha1" |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 334 | ;; |
| 335 | f) |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 336 | first_parent=$(expr "$new_parents" : ' \([^ ]*\)') |
Stephen Haberman | a4f25e3 | 2008-10-15 02:44:37 -0500 | [diff] [blame] | 337 | |
| 338 | if [ "$1" != "-n" ] |
| 339 | then |
| 340 | # detach HEAD to current parent |
| 341 | output git checkout $first_parent 2> /dev/null || |
| 342 | die "Cannot move HEAD to $first_parent" |
| 343 | fi |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 344 | |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 345 | case "$new_parents" in |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 346 | ' '*' '*) |
Stephen Haberman | a4f25e3 | 2008-10-15 02:44:37 -0500 | [diff] [blame] | 347 | test "a$1" = a-n && die "Refusing to squash a merge: $sha1" |
| 348 | |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 349 | # redo merge |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 350 | author_script_content=$(get_author_ident_from_commit $sha1) |
| 351 | eval "$author_script_content" |
| 352 | msg_content="$(commit_message $sha1)" |
Björn Steinbrink | f91333d | 2007-10-31 03:20:32 +0100 | [diff] [blame] | 353 | # No point in merging the first parent, that's HEAD |
| 354 | new_parents=${new_parents# $first_parent} |
Ralf Thielow | a9f739c | 2013-08-21 20:48:57 +0200 | [diff] [blame] | 355 | merge_args="--no-log --no-ff" |
Arnaud Fontaine | db2b3b8 | 2013-07-02 17:05:48 +0900 | [diff] [blame] | 356 | if ! do_with_author output eval \ |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 357 | 'git merge ${gpg_sign_opt:+"$gpg_sign_opt"} \ |
| 358 | $merge_args $strategy_args -m "$msg_content" $new_parents' |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 359 | then |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 360 | printf "%s\n" "$msg_content" > "$GIT_DIR"/MERGE_MSG |
Johannes Sixt | f5b49ea | 2008-12-15 11:05:31 +0100 | [diff] [blame] | 361 | die_with_patch $sha1 "Error redoing merge $sha1" |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 362 | fi |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 363 | echo "$sha1 $(git rev-parse HEAD^0)" >> "$rewritten_list" |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 364 | ;; |
| 365 | *) |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 366 | output eval git cherry-pick \ |
| 367 | ${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \ |
| 368 | "$strategy_args" "$@" || |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 369 | die_with_patch $sha1 "Could not pick $sha1" |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 370 | ;; |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 371 | esac |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 372 | ;; |
Johannes Schindelin | f09c9b8 | 2007-06-25 18:59:43 +0100 | [diff] [blame] | 373 | esac |
| 374 | } |
| 375 | |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 376 | nth_string () { |
| 377 | case "$1" in |
| 378 | *1[0-9]|*[04-9]) echo "$1"th;; |
| 379 | *1) echo "$1"st;; |
| 380 | *2) echo "$1"nd;; |
| 381 | *3) echo "$1"rd;; |
| 382 | esac |
| 383 | } |
| 384 | |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 385 | update_squash_messages () { |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 386 | if test -f "$squash_msg"; then |
| 387 | mv "$squash_msg" "$squash_msg".bak || exit |
| 388 | count=$(($(sed -n \ |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 389 | -e "1s/^. This is a combination of \(.*\) commits\./\1/p" \ |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 390 | -e "q" < "$squash_msg".bak)+1)) |
Michael Haggerty | bde1a68 | 2010-01-14 06:54:54 +0100 | [diff] [blame] | 391 | { |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 392 | printf '%s\n' "$comment_char This is a combination of $count commits." |
Michael Haggerty | bde1a68 | 2010-01-14 06:54:54 +0100 | [diff] [blame] | 393 | sed -e 1d -e '2,/^./{ |
| 394 | /^$/d |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 395 | }' <"$squash_msg".bak |
| 396 | } >"$squash_msg" |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 397 | else |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 398 | commit_message HEAD > "$fixup_msg" || die "Cannot write $fixup_msg" |
| 399 | count=2 |
Michael Haggerty | bde1a68 | 2010-01-14 06:54:54 +0100 | [diff] [blame] | 400 | { |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 401 | printf '%s\n' "$comment_char This is a combination of 2 commits." |
| 402 | printf '%s\n' "$comment_char The first commit's message is:" |
Michael Haggerty | bde1a68 | 2010-01-14 06:54:54 +0100 | [diff] [blame] | 403 | echo |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 404 | cat "$fixup_msg" |
| 405 | } >"$squash_msg" |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 406 | fi |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 407 | case $1 in |
| 408 | squash) |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 409 | rm -f "$fixup_msg" |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 410 | echo |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 411 | printf '%s\n' "$comment_char This is the $(nth_string $count) commit message:" |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 412 | echo |
Michael Haggerty | ee0a4af | 2010-01-14 06:54:51 +0100 | [diff] [blame] | 413 | commit_message $2 |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 414 | ;; |
| 415 | fixup) |
| 416 | echo |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 417 | printf '%s\n' "$comment_char The $(nth_string $count) commit message will be skipped:" |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 418 | echo |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 419 | # Change the space after the comment character to TAB: |
| 420 | commit_message $2 | git stripspace --comment-lines | sed -e 's/ / /' |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 421 | ;; |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 422 | esac >>"$squash_msg" |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | peek_next_command () { |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 426 | git stripspace --strip-comments <"$todo" | sed -n -e 's/ .*//p' -e q |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 427 | } |
| 428 | |
Michael Haggerty | 6bdcd0d | 2010-01-14 06:54:57 +0100 | [diff] [blame] | 429 | # A squash/fixup has failed. Prepare the long version of the squash |
| 430 | # commit message, then die_with_patch. This code path requires the |
| 431 | # user to edit the combined commit message for all commits that have |
| 432 | # been squashed/fixedup so far. So also erase the old squash |
| 433 | # messages, effectively causing the combined commit to be used as the |
| 434 | # new basis for any further squash/fixups. Args: sha1 rest |
| 435 | die_failed_squash() { |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 436 | mv "$squash_msg" "$msg" || exit |
| 437 | rm -f "$fixup_msg" |
| 438 | cp "$msg" "$GIT_DIR"/MERGE_MSG || exit |
Michael Haggerty | 6bdcd0d | 2010-01-14 06:54:57 +0100 | [diff] [blame] | 439 | warn |
| 440 | warn "Could not apply $1... $2" |
| 441 | die_with_patch $1 "" |
| 442 | } |
| 443 | |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 444 | flush_rewritten_pending() { |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 445 | test -s "$rewritten_pending" || return |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 446 | newsha1="$(git rev-parse HEAD^0)" |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 447 | sed "s/$/ $newsha1/" < "$rewritten_pending" >> "$rewritten_list" |
| 448 | rm -f "$rewritten_pending" |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | record_in_rewritten() { |
| 452 | oldsha1="$(git rev-parse $1)" |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 453 | echo "$oldsha1" >> "$rewritten_pending" |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 454 | |
| 455 | case "$(peek_next_command)" in |
Junio C Hamano | 41f556b | 2010-07-05 22:16:15 -0700 | [diff] [blame] | 456 | squash|s|fixup|f) |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 457 | ;; |
Junio C Hamano | 41f556b | 2010-07-05 22:16:15 -0700 | [diff] [blame] | 458 | *) |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 459 | flush_rewritten_pending |
| 460 | ;; |
| 461 | esac |
| 462 | } |
| 463 | |
Chris Webb | df5df20 | 2012-06-26 22:55:23 +0100 | [diff] [blame] | 464 | do_pick () { |
| 465 | if test "$(git rev-parse HEAD)" = "$squash_onto" |
| 466 | then |
| 467 | # Set the correct commit message and author info on the |
| 468 | # sentinel root before cherry-picking the original changes |
| 469 | # without committing (-n). Finally, update the sentinel again |
| 470 | # to include these changes. If the cherry-pick results in a |
| 471 | # conflict, this means our behaviour is similar to a standard |
| 472 | # failed cherry-pick during rebase, with a dirty index to |
| 473 | # resolve before manually running git commit --amend then git |
| 474 | # rebase --continue. |
| 475 | git commit --allow-empty --allow-empty-message --amend \ |
| 476 | --no-post-rewrite -n -q -C $1 && |
| 477 | pick_one -n $1 && |
| 478 | git commit --allow-empty --allow-empty-message \ |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 479 | --amend --no-post-rewrite -n -q -C $1 \ |
| 480 | ${gpg_sign_opt:+"$gpg_sign_opt"} || |
Chris Webb | df5df20 | 2012-06-26 22:55:23 +0100 | [diff] [blame] | 481 | die_with_patch $1 "Could not apply $1... $2" |
| 482 | else |
| 483 | pick_one $1 || |
| 484 | die_with_patch $1 "Could not apply $1... $2" |
| 485 | fi |
| 486 | } |
| 487 | |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 488 | do_next () { |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 489 | rm -f "$msg" "$author_script" "$amend" || exit |
| 490 | read -r command sha1 rest < "$todo" |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 491 | case "$command" in |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 492 | "$comment_char"*|''|noop) |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 493 | mark_action_done |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 494 | ;; |
Johannes Schindelin | f8babc4 | 2007-09-29 03:32:11 +0100 | [diff] [blame] | 495 | pick|p) |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 496 | comment_for_reflog pick |
| 497 | |
| 498 | mark_action_done |
Chris Webb | df5df20 | 2012-06-26 22:55:23 +0100 | [diff] [blame] | 499 | do_pick $sha1 "$rest" |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 500 | record_in_rewritten $sha1 |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 501 | ;; |
Björn Gustavsson | 6741aa6 | 2009-10-07 08:13:23 +0200 | [diff] [blame] | 502 | reword|r) |
| 503 | comment_for_reflog reword |
| 504 | |
| 505 | mark_action_done |
Chris Webb | df5df20 | 2012-06-26 22:55:23 +0100 | [diff] [blame] | 506 | do_pick $sha1 "$rest" |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 507 | git commit --amend --no-post-rewrite ${gpg_sign_opt:+"$gpg_sign_opt"} || { |
Andrew Wong | 0becb3e | 2011-11-30 10:52:51 -0500 | [diff] [blame] | 508 | warn "Could not amend commit after successfully picking $sha1... $rest" |
| 509 | warn "This is most likely due to an empty commit message, or the pre-commit hook" |
| 510 | warn "failed. If the pre-commit hook failed, you may need to resolve the issue before" |
| 511 | warn "you are able to reword the commit." |
| 512 | exit_with_patch $sha1 1 |
| 513 | } |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 514 | record_in_rewritten $sha1 |
Björn Gustavsson | 6741aa6 | 2009-10-07 08:13:23 +0200 | [diff] [blame] | 515 | ;; |
Johannes Schindelin | f8babc4 | 2007-09-29 03:32:11 +0100 | [diff] [blame] | 516 | edit|e) |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 517 | comment_for_reflog edit |
| 518 | |
| 519 | mark_action_done |
Chris Webb | df5df20 | 2012-06-26 22:55:23 +0100 | [diff] [blame] | 520 | do_pick $sha1 "$rest" |
Johannes Sixt | a8ccc20 | 2008-07-23 09:46:35 +0200 | [diff] [blame] | 521 | warn "Stopped at $sha1... $rest" |
Andrew Wong | 0becb3e | 2011-11-30 10:52:51 -0500 | [diff] [blame] | 522 | exit_with_patch $sha1 0 |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 523 | ;; |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 524 | squash|s|fixup|f) |
| 525 | case "$command" in |
| 526 | squash|s) |
| 527 | squash_style=squash |
| 528 | ;; |
| 529 | fixup|f) |
| 530 | squash_style=fixup |
| 531 | ;; |
| 532 | esac |
| 533 | comment_for_reflog $squash_style |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 534 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 535 | test -f "$done" && has_action "$done" || |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 536 | die "Cannot '$squash_style' without a previous commit" |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 537 | |
| 538 | mark_action_done |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 539 | update_squash_messages $squash_style $sha1 |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 540 | author_script_content=$(get_author_ident_from_commit HEAD) |
| 541 | echo "$author_script_content" > "$author_script" |
| 542 | eval "$author_script_content" |
Chris Webb | 2147f84 | 2012-07-24 13:17:03 +0100 | [diff] [blame] | 543 | if ! pick_one -n $sha1 |
| 544 | then |
| 545 | git rev-parse --verify HEAD >"$amend" |
| 546 | die_failed_squash $sha1 "$rest" |
| 547 | fi |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 548 | case "$(peek_next_command)" in |
Michael Haggerty | 0205e72 | 2009-12-07 10:20:59 +0100 | [diff] [blame] | 549 | squash|s|fixup|f) |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 550 | # This is an intermediate commit; its message will only be |
| 551 | # used in case of trouble. So use the long version: |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 552 | do_with_author output git commit --amend --no-verify -F "$squash_msg" \ |
| 553 | ${gpg_sign_opt:+"$gpg_sign_opt"} || |
Michael Haggerty | 6bdcd0d | 2010-01-14 06:54:57 +0100 | [diff] [blame] | 554 | die_failed_squash $sha1 "$rest" |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 555 | ;; |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 556 | *) |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 557 | # This is the final command of this squash/fixup group |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 558 | if test -f "$fixup_msg" |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 559 | then |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 560 | do_with_author git commit --amend --no-verify -F "$fixup_msg" \ |
| 561 | ${gpg_sign_opt:+"$gpg_sign_opt"} || |
Michael Haggerty | 6bdcd0d | 2010-01-14 06:54:57 +0100 | [diff] [blame] | 562 | die_failed_squash $sha1 "$rest" |
| 563 | else |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 564 | cp "$squash_msg" "$GIT_DIR"/SQUASH_MSG || exit |
Michael Haggerty | 6bdcd0d | 2010-01-14 06:54:57 +0100 | [diff] [blame] | 565 | rm -f "$GIT_DIR"/MERGE_MSG |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 566 | do_with_author git commit --amend --no-verify -F "$GIT_DIR"/SQUASH_MSG -e \ |
| 567 | ${gpg_sign_opt:+"$gpg_sign_opt"} || |
Michael Haggerty | 6bdcd0d | 2010-01-14 06:54:57 +0100 | [diff] [blame] | 568 | die_failed_squash $sha1 "$rest" |
Michael Haggerty | a25eb13 | 2010-01-14 06:54:55 +0100 | [diff] [blame] | 569 | fi |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 570 | rm -f "$squash_msg" "$fixup_msg" |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 571 | ;; |
Johannes Schindelin | 6368f3f | 2007-07-21 18:09:41 +0100 | [diff] [blame] | 572 | esac |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 573 | record_in_rewritten $sha1 |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 574 | ;; |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 575 | x|"exec") |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 576 | read -r command rest < "$todo" |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 577 | mark_action_done |
| 578 | printf 'Executing: %s\n' "$rest" |
| 579 | # "exec" command doesn't take a sha1 in the todo-list. |
| 580 | # => can't just use $sha1 here. |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 581 | git rev-parse --verify HEAD > "$state_dir"/stopped-sha |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 582 | ${SHELL:-@SHELL_PATH@} -c "$rest" # Actual execution |
| 583 | status=$? |
Junio C Hamano | 1686519 | 2011-08-24 11:54:50 -0700 | [diff] [blame] | 584 | # Run in subshell because require_clean_work_tree can die. |
| 585 | dirty=f |
| 586 | (require_clean_work_tree "rebase" 2>/dev/null) || dirty=t |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 587 | if test "$status" -ne 0 |
| 588 | then |
| 589 | warn "Execution failed: $rest" |
Junio C Hamano | 1686519 | 2011-08-24 11:54:50 -0700 | [diff] [blame] | 590 | test "$dirty" = f || |
| 591 | warn "and made changes to the index and/or the working tree" |
| 592 | |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 593 | warn "You can fix the problem, and then run" |
| 594 | warn |
| 595 | warn " git rebase --continue" |
| 596 | warn |
Johannes Sixt | ecfe1ea | 2012-09-18 13:15:26 +0200 | [diff] [blame] | 597 | if test $status -eq 127 # command not found |
| 598 | then |
| 599 | status=1 |
| 600 | fi |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 601 | exit "$status" |
Junio C Hamano | 1686519 | 2011-08-24 11:54:50 -0700 | [diff] [blame] | 602 | elif test "$dirty" = t |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 603 | then |
Junio C Hamano | 1686519 | 2011-08-24 11:54:50 -0700 | [diff] [blame] | 604 | warn "Execution succeeded: $rest" |
| 605 | warn "but left changes to the index and/or the working tree" |
Matthieu Moy | cd035b1 | 2010-08-10 17:17:51 +0200 | [diff] [blame] | 606 | warn "Commit or stash your changes, and then run" |
| 607 | warn |
| 608 | warn " git rebase --continue" |
| 609 | warn |
| 610 | exit 1 |
| 611 | fi |
| 612 | ;; |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 613 | *) |
| 614 | warn "Unknown command: $command $sha1 $rest" |
Johannes Sixt | 9c8e101 | 2012-09-19 08:43:54 +0200 | [diff] [blame] | 615 | fixtodo="Please fix this using 'git rebase --edit-todo'." |
Jan Krüger | f1be316 | 2009-10-27 15:58:14 +0100 | [diff] [blame] | 616 | if git rev-parse --verify -q "$sha1" >/dev/null |
| 617 | then |
Johannes Sixt | 9c8e101 | 2012-09-19 08:43:54 +0200 | [diff] [blame] | 618 | die_with_patch $sha1 "$fixtodo" |
Jan Krüger | f1be316 | 2009-10-27 15:58:14 +0100 | [diff] [blame] | 619 | else |
Johannes Sixt | 9c8e101 | 2012-09-19 08:43:54 +0200 | [diff] [blame] | 620 | die "$fixtodo" |
Jan Krüger | f1be316 | 2009-10-27 15:58:14 +0100 | [diff] [blame] | 621 | fi |
Johannes Schindelin | 376ccb8 | 2007-09-25 16:42:51 +0100 | [diff] [blame] | 622 | ;; |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 623 | esac |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 624 | test -s "$todo" && return |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 625 | |
Johannes Schindelin | 68a163c | 2007-06-25 18:58:28 +0100 | [diff] [blame] | 626 | comment_for_reflog finish && |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 627 | newhead=$(git rev-parse HEAD) && |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 628 | case $head_name in |
Johannes Schindelin | 73697a0 | 2007-09-25 16:43:15 +0100 | [diff] [blame] | 629 | refs/*) |
Michael J Gruber | 1af221e | 2012-08-10 08:51:19 +0200 | [diff] [blame] | 630 | message="$GIT_REFLOG_ACTION: $head_name onto $onto" && |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 631 | git update-ref -m "$message" $head_name $newhead $orig_head && |
Jeff King | 53f2ffa | 2011-05-27 16:16:14 -0400 | [diff] [blame] | 632 | git symbolic-ref \ |
| 633 | -m "$GIT_REFLOG_ACTION: returning to $head_name" \ |
| 634 | HEAD $head_name |
Johannes Schindelin | 73697a0 | 2007-09-25 16:43:15 +0100 | [diff] [blame] | 635 | ;; |
| 636 | esac && { |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 637 | test ! -f "$state_dir"/verbose || |
Martin von Zweigbergk | 2959c28 | 2011-02-06 13:43:52 -0500 | [diff] [blame] | 638 | git diff-tree --stat $orig_head..HEAD |
Johannes Schindelin | 3df0a85 | 2007-07-08 03:02:13 +0100 | [diff] [blame] | 639 | } && |
Thomas Rast | eb2151b | 2010-03-12 18:04:33 +0100 | [diff] [blame] | 640 | { |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 641 | test -s "$rewritten_list" && |
| 642 | git notes copy --for-rewrite=rebase < "$rewritten_list" || |
Thomas Rast | eb2151b | 2010-03-12 18:04:33 +0100 | [diff] [blame] | 643 | true # we don't care if this copying failed |
| 644 | } && |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 645 | if test -x "$GIT_DIR"/hooks/post-rewrite && |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 646 | test -s "$rewritten_list"; then |
| 647 | "$GIT_DIR"/hooks/post-rewrite rebase < "$rewritten_list" |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 648 | true # we don't care if this hook failed |
| 649 | fi && |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 650 | warn "Successfully rebased and updated $head_name." |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 651 | |
Ramkumar Ramachandra | 15d4bf2 | 2013-05-12 17:26:39 +0530 | [diff] [blame] | 652 | return 1 # not failure; just to break the do_rest loop |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 653 | } |
| 654 | |
Ramkumar Ramachandra | 15d4bf2 | 2013-05-12 17:26:39 +0530 | [diff] [blame] | 655 | # can only return 0, when the infinite loop breaks |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 656 | do_rest () { |
| 657 | while : |
| 658 | do |
Ramkumar Ramachandra | 15d4bf2 | 2013-05-12 17:26:39 +0530 | [diff] [blame] | 659 | do_next || break |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 660 | done |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 661 | } |
| 662 | |
Johannes Schindelin | 0e757e3 | 2009-03-03 10:55:31 +0100 | [diff] [blame] | 663 | # skip picking commits whose parents are unchanged |
| 664 | skip_unnecessary_picks () { |
| 665 | fd=3 |
Brandon Casey | 2d6ca6e | 2010-08-13 15:47:34 -0500 | [diff] [blame] | 666 | while read -r command rest |
Johannes Schindelin | 0e757e3 | 2009-03-03 10:55:31 +0100 | [diff] [blame] | 667 | do |
| 668 | # fd=3 means we skip the command |
Brandon Casey | 2d6ca6e | 2010-08-13 15:47:34 -0500 | [diff] [blame] | 669 | case "$fd,$command" in |
| 670 | 3,pick|3,p) |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 671 | # pick a commit whose parent is current $onto -> skip |
Chris Johnsen | 14d8729 | 2010-09-17 16:42:51 -0500 | [diff] [blame] | 672 | sha1=${rest%% *} |
Brandon Casey | 2d6ca6e | 2010-08-13 15:47:34 -0500 | [diff] [blame] | 673 | case "$(git rev-parse --verify --quiet "$sha1"^)" in |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 674 | "$onto"*) |
| 675 | onto=$sha1 |
Brandon Casey | 2d6ca6e | 2010-08-13 15:47:34 -0500 | [diff] [blame] | 676 | ;; |
| 677 | *) |
| 678 | fd=1 |
| 679 | ;; |
| 680 | esac |
Johannes Schindelin | 0e757e3 | 2009-03-03 10:55:31 +0100 | [diff] [blame] | 681 | ;; |
Eric Sunshine | 7bca7af | 2013-08-16 17:44:07 -0400 | [diff] [blame] | 682 | 3,"$comment_char"*|3,) |
Johannes Schindelin | 0e757e3 | 2009-03-03 10:55:31 +0100 | [diff] [blame] | 683 | # copy comments |
| 684 | ;; |
| 685 | *) |
| 686 | fd=1 |
| 687 | ;; |
| 688 | esac |
Brandon Casey | d1c3b10 | 2010-08-13 15:47:35 -0500 | [diff] [blame] | 689 | printf '%s\n' "$command${rest:+ }$rest" >&$fd |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 690 | done <"$todo" >"$todo.new" 3>>"$done" && |
| 691 | mv -f "$todo".new "$todo" && |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 692 | case "$(peek_next_command)" in |
| 693 | squash|s|fixup|f) |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 694 | record_in_rewritten "$onto" |
Thomas Rast | b079fee | 2010-03-12 18:04:30 +0100 | [diff] [blame] | 695 | ;; |
| 696 | esac || |
Johannes Schindelin | 0e757e3 | 2009-03-03 10:55:31 +0100 | [diff] [blame] | 697 | die "Could not skip unnecessary pick commands" |
| 698 | } |
| 699 | |
Junio C Hamano | 75c6976 | 2013-08-23 20:10:42 -0400 | [diff] [blame] | 700 | transform_todo_ids () { |
| 701 | while read -r command rest |
| 702 | do |
| 703 | case "$command" in |
| 704 | "$comment_char"* | exec) |
| 705 | # Be careful for oddball commands like 'exec' |
| 706 | # that do not have a SHA-1 at the beginning of $rest. |
| 707 | ;; |
| 708 | *) |
| 709 | sha1=$(git rev-parse --verify --quiet "$@" ${rest%% *}) && |
| 710 | rest="$sha1 ${rest#* }" |
| 711 | ;; |
| 712 | esac |
| 713 | printf '%s\n' "$command${rest:+ }$rest" |
| 714 | done <"$todo" >"$todo.new" && |
| 715 | mv -f "$todo.new" "$todo" |
| 716 | } |
| 717 | |
| 718 | expand_todo_ids() { |
| 719 | transform_todo_ids |
| 720 | } |
| 721 | |
| 722 | collapse_todo_ids() { |
Kirill A. Shutemov | 5689503 | 2013-09-28 18:53:05 +0300 | [diff] [blame] | 723 | transform_todo_ids --short |
Junio C Hamano | 75c6976 | 2013-08-23 20:10:42 -0400 | [diff] [blame] | 724 | } |
| 725 | |
Nanako Shiraishi | f59baa5 | 2009-12-08 12:13:14 +0900 | [diff] [blame] | 726 | # Rearrange the todo list that has both "pick sha1 msg" and |
| 727 | # "pick sha1 fixup!/squash! msg" appears in it so that the latter |
| 728 | # comes immediately after the former, and change "pick" to |
| 729 | # "fixup"/"squash". |
| 730 | rearrange_squash () { |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 731 | # extract fixup!/squash! lines and resolve any referenced sha1's |
| 732 | while read -r pick sha1 message |
| 733 | do |
| 734 | case "$message" in |
| 735 | "squash! "*|"fixup! "*) |
| 736 | action="${message%%!*}" |
Andrew Pimlott | 22c5b13 | 2013-06-27 12:26:31 -0700 | [diff] [blame] | 737 | rest=$message |
| 738 | prefix= |
| 739 | # skip all squash! or fixup! (but save for later) |
| 740 | while : |
| 741 | do |
| 742 | case "$rest" in |
| 743 | "squash! "*|"fixup! "*) |
| 744 | prefix="$prefix${rest%%!*}," |
| 745 | rest="${rest#*! }" |
| 746 | ;; |
| 747 | *) |
| 748 | break |
| 749 | ;; |
| 750 | esac |
| 751 | done |
Uwe Storbeck | 47be066 | 2014-03-15 00:56:43 +0100 | [diff] [blame] | 752 | printf '%s %s %s %s\n' "$sha1" "$action" "$prefix" "$rest" |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 753 | # if it's a single word, try to resolve to a full sha1 and |
| 754 | # emit a second copy. This allows us to match on both message |
| 755 | # and on sha1 prefix |
| 756 | if test "${rest#* }" = "$rest"; then |
| 757 | fullsha="$(git rev-parse -q --verify "$rest" 2>/dev/null)" |
| 758 | if test -n "$fullsha"; then |
| 759 | # prefix the action to uniquely identify this line as |
| 760 | # intended for full sha1 match |
Andrew Pimlott | 22c5b13 | 2013-06-27 12:26:31 -0700 | [diff] [blame] | 761 | echo "$sha1 +$action $prefix $fullsha" |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 762 | fi |
| 763 | fi |
| 764 | esac |
| 765 | done >"$1.sq" <"$1" |
Nanako Shiraishi | f59baa5 | 2009-12-08 12:13:14 +0900 | [diff] [blame] | 766 | test -s "$1.sq" || return |
| 767 | |
| 768 | used= |
Junio C Hamano | 57f2b6b | 2010-07-05 23:08:36 -0700 | [diff] [blame] | 769 | while read -r pick sha1 message |
Nanako Shiraishi | f59baa5 | 2009-12-08 12:13:14 +0900 | [diff] [blame] | 770 | do |
| 771 | case " $used" in |
| 772 | *" $sha1 "*) continue ;; |
| 773 | esac |
Brandon Casey | 938791c | 2010-07-22 14:15:11 -0500 | [diff] [blame] | 774 | printf '%s\n' "$pick $sha1 $message" |
Kevin Ballard | d3d7a42 | 2010-11-04 15:36:31 -0700 | [diff] [blame] | 775 | used="$used$sha1 " |
Andrew Pimlott | 22c5b13 | 2013-06-27 12:26:31 -0700 | [diff] [blame] | 776 | while read -r squash action msg_prefix msg_content |
Nanako Shiraishi | f59baa5 | 2009-12-08 12:13:14 +0900 | [diff] [blame] | 777 | do |
Kevin Ballard | d3d7a42 | 2010-11-04 15:36:31 -0700 | [diff] [blame] | 778 | case " $used" in |
| 779 | *" $squash "*) continue ;; |
| 780 | esac |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 781 | emit=0 |
| 782 | case "$action" in |
| 783 | +*) |
| 784 | action="${action#+}" |
| 785 | # full sha1 prefix test |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 786 | case "$msg_content" in "$sha1"*) emit=1;; esac ;; |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 787 | *) |
| 788 | # message prefix test |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 789 | case "$message" in "$msg_content"*) emit=1;; esac ;; |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 790 | esac |
| 791 | if test $emit = 1; then |
Andrew Pimlott | 22c5b13 | 2013-06-27 12:26:31 -0700 | [diff] [blame] | 792 | real_prefix=$(echo "$msg_prefix" | sed "s/,/! /g") |
| 793 | printf '%s\n' "$action $squash ${real_prefix}$msg_content" |
Nanako Shiraishi | f59baa5 | 2009-12-08 12:13:14 +0900 | [diff] [blame] | 794 | used="$used$squash " |
Kevin Ballard | 68d5d03 | 2010-11-04 15:36:32 -0700 | [diff] [blame] | 795 | fi |
Nanako Shiraishi | f59baa5 | 2009-12-08 12:13:14 +0900 | [diff] [blame] | 796 | done <"$1.sq" |
| 797 | done >"$1.rearranged" <"$1" |
| 798 | cat "$1.rearranged" >"$1" |
| 799 | rm -f "$1.sq" "$1.rearranged" |
| 800 | } |
| 801 | |
Lucien Kong | c214538 | 2012-06-12 10:05:12 +0200 | [diff] [blame] | 802 | # Add commands after a pick or after a squash/fixup serie |
| 803 | # in the todo list. |
| 804 | add_exec_commands () { |
| 805 | { |
| 806 | first=t |
| 807 | while read -r insn rest |
| 808 | do |
| 809 | case $insn in |
| 810 | pick) |
| 811 | test -n "$first" || |
| 812 | printf "%s" "$cmd" |
| 813 | ;; |
| 814 | esac |
| 815 | printf "%s %s\n" "$insn" "$rest" |
| 816 | first= |
| 817 | done |
| 818 | printf "%s" "$cmd" |
| 819 | } <"$1" >"$1.new" && |
| 820 | mv "$1.new" "$1" |
| 821 | } |
| 822 | |
Kyle J. McKay | 9f50d32 | 2014-04-11 01:28:17 -0700 | [diff] [blame] | 823 | # The whole contents of this file is run by dot-sourcing it from |
| 824 | # inside a shell function. It used to be that "return"s we see |
| 825 | # below were not inside any function, and expected to return |
| 826 | # to the function that dot-sourced us. |
| 827 | # |
| 828 | # However, FreeBSD /bin/sh misbehaves on such a construct and |
| 829 | # continues to run the statements that follow such a "return". |
| 830 | # As a work-around, we introduce an extra layer of a function |
| 831 | # here, and immediately call it after defining it. |
| 832 | git_rebase__interactive () { |
| 833 | |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 834 | case "$action" in |
| 835 | continue) |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 836 | # do we have anything to commit? |
John Keeping | a6754cd | 2012-04-07 11:20:53 +0100 | [diff] [blame] | 837 | if git diff-index --cached --quiet HEAD -- |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 838 | then |
| 839 | : Nothing to commit -- skip this |
| 840 | else |
Matthieu Moy | ffaaed8 | 2011-08-24 16:01:48 +0200 | [diff] [blame] | 841 | if ! test -f "$author_script" |
| 842 | then |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 843 | gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} |
Matthieu Moy | ffaaed8 | 2011-08-24 16:01:48 +0200 | [diff] [blame] | 844 | die "You have staged changes in your working tree. If these changes are meant to be |
| 845 | squashed into the previous commit, run: |
| 846 | |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 847 | git commit --amend $gpg_sign_opt_quoted |
Matthieu Moy | ffaaed8 | 2011-08-24 16:01:48 +0200 | [diff] [blame] | 848 | |
| 849 | If they are meant to go into a new commit, run: |
| 850 | |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 851 | git commit $gpg_sign_opt_quoted |
Matthieu Moy | ffaaed8 | 2011-08-24 16:01:48 +0200 | [diff] [blame] | 852 | |
| 853 | In both case, once you're done, continue with: |
| 854 | |
| 855 | git rebase --continue |
| 856 | " |
| 857 | fi |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 858 | . "$author_script" || |
Matthieu Moy | ffaaed8 | 2011-08-24 16:01:48 +0200 | [diff] [blame] | 859 | die "Error trying to find the author identity to amend commit" |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 860 | if test -f "$amend" |
Shawn O. Pearce | 0327062 | 2007-12-20 02:12:12 -0500 | [diff] [blame] | 861 | then |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 862 | current_head=$(git rev-parse --verify HEAD) |
| 863 | test "$current_head" = $(cat "$amend") || |
| 864 | die "\ |
Dmitry Potapov | c14c3c8 | 2008-09-09 16:05:26 +0400 | [diff] [blame] | 865 | You have uncommitted changes in your working tree. Please, commit them |
| 866 | first and then run 'git rebase --continue' again." |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 867 | do_with_author git commit --amend --no-verify -F "$msg" -e \ |
| 868 | ${gpg_sign_opt:+"$gpg_sign_opt"} || |
Chris Webb | 2147f84 | 2012-07-24 13:17:03 +0100 | [diff] [blame] | 869 | die "Could not commit staged changes." |
| 870 | else |
Nicolas Vigier | 3ee5e54 | 2014-02-10 01:03:37 +0000 | [diff] [blame] | 871 | do_with_author git commit --no-verify -F "$msg" -e \ |
| 872 | ${gpg_sign_opt:+"$gpg_sign_opt"} || |
Chris Webb | 2147f84 | 2012-07-24 13:17:03 +0100 | [diff] [blame] | 873 | die "Could not commit staged changes." |
Shawn O. Pearce | 0327062 | 2007-12-20 02:12:12 -0500 | [diff] [blame] | 874 | fi |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 875 | fi |
Johannes Schindelin | 18640d9 | 2007-07-08 03:01:29 +0100 | [diff] [blame] | 876 | |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 877 | record_in_rewritten "$(cat "$state_dir"/stopped-sha)" |
Thomas Rast | 0acb62f | 2010-03-28 21:36:00 +0200 | [diff] [blame] | 878 | |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 879 | require_clean_work_tree "rebase" |
| 880 | do_rest |
Ramkumar Ramachandra | 15d4bf2 | 2013-05-12 17:26:39 +0530 | [diff] [blame] | 881 | return 0 |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 882 | ;; |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 883 | skip) |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 884 | git rerere clear |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 885 | |
Martin von Zweigbergk | 2959c28 | 2011-02-06 13:43:52 -0500 | [diff] [blame] | 886 | do_rest |
Ramkumar Ramachandra | 15d4bf2 | 2013-05-12 17:26:39 +0530 | [diff] [blame] | 887 | return 0 |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 888 | ;; |
Andrew Wong | eb9a7cb | 2012-09-17 21:28:09 -0400 | [diff] [blame] | 889 | edit-todo) |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 890 | git stripspace --strip-comments <"$todo" >"$todo".new |
Andrew Wong | eb9a7cb | 2012-09-17 21:28:09 -0400 | [diff] [blame] | 891 | mv -f "$todo".new "$todo" |
Junio C Hamano | 75c6976 | 2013-08-23 20:10:42 -0400 | [diff] [blame] | 892 | collapse_todo_ids |
Andrew Wong | eb9a7cb | 2012-09-17 21:28:09 -0400 | [diff] [blame] | 893 | append_todo_help |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 894 | git stripspace --comment-lines >>"$todo" <<\EOF |
| 895 | |
| 896 | You are editing the todo file of an ongoing interactive rebase. |
| 897 | To continue rebase after editing, run: |
| 898 | git rebase --continue |
| 899 | |
Andrew Wong | eb9a7cb | 2012-09-17 21:28:09 -0400 | [diff] [blame] | 900 | EOF |
| 901 | |
| 902 | git_sequence_editor "$todo" || |
| 903 | die "Could not execute editor" |
Junio C Hamano | 75c6976 | 2013-08-23 20:10:42 -0400 | [diff] [blame] | 904 | expand_todo_ids |
Andrew Wong | eb9a7cb | 2012-09-17 21:28:09 -0400 | [diff] [blame] | 905 | |
| 906 | exit |
| 907 | ;; |
Martin von Zweigbergk | cf432ca | 2011-02-06 13:43:39 -0500 | [diff] [blame] | 908 | esac |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 909 | |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 910 | git var GIT_COMMITTER_IDENT >/dev/null || |
| 911 | die "You need to set your committer info first" |
Thomas Rast | d8fab02 | 2009-01-02 23:28:26 +0100 | [diff] [blame] | 912 | |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 913 | comment_for_reflog start |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 914 | |
Martin von Zweigbergk | 71786f5 | 2011-02-06 13:43:42 -0500 | [diff] [blame] | 915 | if test ! -z "$switch_to" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 916 | then |
Ramkumar Ramachandra | 26cd160 | 2013-06-16 14:15:13 +0530 | [diff] [blame] | 917 | GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to" |
Martin von Zweigbergk | 71786f5 | 2011-02-06 13:43:42 -0500 | [diff] [blame] | 918 | output git checkout "$switch_to" -- || |
Ramkumar Ramachandra | 26cd160 | 2013-06-16 14:15:13 +0530 | [diff] [blame] | 919 | die "Could not checkout $switch_to" |
| 920 | |
| 921 | comment_for_reflog start |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 922 | fi |
Matt Kraai | 5166810 | 2007-09-25 18:30:13 -0700 | [diff] [blame] | 923 | |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 924 | orig_head=$(git rev-parse --verify HEAD) || die "No HEAD?" |
Ramkumar Ramachandra | 1224f3d | 2013-05-12 17:26:36 +0530 | [diff] [blame] | 925 | mkdir -p "$state_dir" || die "Could not create temporary $state_dir" |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 926 | |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 927 | : > "$state_dir"/interactive || die "Could not mark as interactive" |
Martin von Zweigbergk | 84df456 | 2011-02-06 13:43:53 -0500 | [diff] [blame] | 928 | write_basic_state |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 929 | if test t = "$preserve_merges" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 930 | then |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 931 | if test -z "$rebase_root" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 932 | then |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 933 | mkdir "$rewritten" && |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 934 | for c in $(git merge-base --all $orig_head $upstream) |
Stephen Haberman | acc8559 | 2008-10-15 02:44:38 -0500 | [diff] [blame] | 935 | do |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 936 | echo $onto > "$rewritten"/$c || |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 937 | die "Could not init rewritten commits" |
| 938 | done |
| 939 | else |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 940 | mkdir "$rewritten" && |
| 941 | echo $onto > "$rewritten"/root || |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 942 | die "Could not init rewritten commits" |
| 943 | fi |
| 944 | # No cherry-pick because our first pass is to determine |
| 945 | # parents to rewrite and skipping dropped commits would |
| 946 | # prematurely end our probe |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 947 | merges_option= |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 948 | else |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 949 | merges_option="--no-merges --cherry-pick" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 950 | fi |
| 951 | |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 952 | shorthead=$(git rev-parse --short $orig_head) |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 953 | shortonto=$(git rev-parse --short $onto) |
| 954 | if test -z "$rebase_root" |
| 955 | # this is now equivalent to ! -z "$upstream" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 956 | then |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 957 | shortupstream=$(git rev-parse --short $upstream) |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 958 | revisions=$upstream...$orig_head |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 959 | shortrevisions=$shortupstream..$shorthead |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 960 | else |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 961 | revisions=$onto...$orig_head |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 962 | shortrevisions=$shorthead |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 963 | fi |
Kirill A. Shutemov | edb72d5 | 2015-01-22 13:50:15 +0200 | [diff] [blame] | 964 | git rev-list $merges_option --pretty=oneline --reverse --left-right --topo-order \ |
John Keeping | 1e0dacd | 2014-07-16 20:23:49 +0100 | [diff] [blame] | 965 | $revisions ${restrict_revision+^$restrict_revision} | \ |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 966 | sed -n "s/^>//p" | |
Kirill A. Shutemov | edb72d5 | 2015-01-22 13:50:15 +0200 | [diff] [blame] | 967 | while read -r sha1 rest |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 968 | do |
Neil Horman | 90e1818 | 2012-04-20 10:36:17 -0400 | [diff] [blame] | 969 | |
Kirill A. Shutemov | edb72d5 | 2015-01-22 13:50:15 +0200 | [diff] [blame] | 970 | 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] | 971 | then |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 972 | comment_out="$comment_char " |
Neil Horman | 90e1818 | 2012-04-20 10:36:17 -0400 | [diff] [blame] | 973 | else |
| 974 | comment_out= |
| 975 | fi |
| 976 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 977 | if test t != "$preserve_merges" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 978 | then |
Kirill A. Shutemov | edb72d5 | 2015-01-22 13:50:15 +0200 | [diff] [blame] | 979 | printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 980 | else |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 981 | if test -z "$rebase_root" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 982 | then |
| 983 | preserve=t |
| 984 | for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-) |
| 985 | do |
Andrew Wong | 12bf828 | 2011-06-18 18:12:01 -0400 | [diff] [blame] | 986 | if test -f "$rewritten"/$p |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 987 | then |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 988 | preserve=f |
| 989 | fi |
Stephen Haberman | acc8559 | 2008-10-15 02:44:38 -0500 | [diff] [blame] | 990 | done |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 991 | else |
| 992 | preserve=f |
Stephen Haberman | acc8559 | 2008-10-15 02:44:38 -0500 | [diff] [blame] | 993 | fi |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 994 | if test f = "$preserve" |
| 995 | then |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 996 | touch "$rewritten"/$sha1 |
Kirill A. Shutemov | edb72d5 | 2015-01-22 13:50:15 +0200 | [diff] [blame] | 997 | printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 998 | fi |
| 999 | fi |
| 1000 | done |
Thomas Rast | d911d14 | 2009-01-02 23:28:28 +0100 | [diff] [blame] | 1001 | |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1002 | # Watch for commits that been dropped by --cherry-pick |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1003 | if test t = "$preserve_merges" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1004 | then |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1005 | mkdir "$dropped" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1006 | # Save all non-cherry-picked changes |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1007 | git rev-list $revisions --left-right --cherry-pick | \ |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 1008 | sed -n "s/^>//p" > "$state_dir"/not-cherry-picks |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1009 | # Now all commits and note which ones are missing in |
| 1010 | # not-cherry-picks and hence being dropped |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1011 | git rev-list $revisions | |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1012 | while read rev |
| 1013 | do |
Elia Pinto | e425f6a | 2014-06-06 07:55:52 -0700 | [diff] [blame] | 1014 | if test -f "$rewritten"/$rev && test "$(sane_grep "$rev" "$state_dir"/not-cherry-picks)" = "" |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1015 | then |
| 1016 | # Use -f2 because if rev-list is telling us this commit is |
| 1017 | # not worthwhile, we don't want to track its multiple heads, |
| 1018 | # just the history of its first-parent for others that will |
| 1019 | # be rebasing on top of it |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1020 | 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] | 1021 | sha1=$(git rev-list -1 $rev) |
| 1022 | 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] | 1023 | rm "$rewritten"/$rev |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1024 | fi |
| 1025 | done |
| 1026 | fi |
| 1027 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1028 | test -s "$todo" || echo noop >> "$todo" |
| 1029 | test -n "$autosquash" && rearrange_squash "$todo" |
Lucien Kong | c214538 | 2012-06-12 10:05:12 +0200 | [diff] [blame] | 1030 | test -n "$cmd" && add_exec_commands "$todo" |
| 1031 | |
Onno Kortmann | 97f05f4 | 2014-12-10 19:16:44 +0100 | [diff] [blame] | 1032 | todocount=$(git stripspace --strip-comments <"$todo" | wc -l) |
| 1033 | |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 1034 | cat >>"$todo" <<EOF |
Johannes Schindelin | 6047a23 | 2007-11-22 12:30:10 +0000 | [diff] [blame] | 1035 | |
Onno Kortmann | 97f05f4 | 2014-12-10 19:16:44 +0100 | [diff] [blame] | 1036 | $comment_char Rebase $shortrevisions onto $shortonto ($todocount TODO item(s)) |
Andrew Wong | fcc5ef1 | 2012-09-17 21:28:08 -0400 | [diff] [blame] | 1037 | EOF |
| 1038 | append_todo_help |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 1039 | git stripspace --comment-lines >>"$todo" <<\EOF |
| 1040 | |
| 1041 | However, if you remove everything, the rebase will be aborted. |
| 1042 | |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 1043 | EOF |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 1044 | |
Neil Horman | 90e1818 | 2012-04-20 10:36:17 -0400 | [diff] [blame] | 1045 | if test -z "$keep_empty" |
| 1046 | then |
John Keeping | 180bad3 | 2013-02-11 23:08:04 +0000 | [diff] [blame] | 1047 | printf '%s\n' "$comment_char Note that empty commits are commented out" >>"$todo" |
Neil Horman | 90e1818 | 2012-04-20 10:36:17 -0400 | [diff] [blame] | 1048 | fi |
| 1049 | |
| 1050 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1051 | has_action "$todo" || |
Ramkumar Ramachandra | e4244eb | 2014-05-19 18:05:20 -0400 | [diff] [blame] | 1052 | return 2 |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 1053 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1054 | cp "$todo" "$todo".backup |
Kirill A. Shutemov | edb72d5 | 2015-01-22 13:50:15 +0200 | [diff] [blame] | 1055 | collapse_todo_ids |
Peter Oberndorfer | 821881d | 2011-10-17 22:26:23 +0200 | [diff] [blame] | 1056 | git_sequence_editor "$todo" || |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1057 | die_abort "Could not execute editor" |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 1058 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1059 | has_action "$todo" || |
Ramkumar Ramachandra | e4244eb | 2014-05-19 18:05:20 -0400 | [diff] [blame] | 1060 | return 2 |
Johannes Schindelin | c54b781 | 2007-06-25 18:56:55 +0100 | [diff] [blame] | 1061 | |
Junio C Hamano | 75c6976 | 2013-08-23 20:10:42 -0400 | [diff] [blame] | 1062 | expand_todo_ids |
| 1063 | |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1064 | test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks |
Johannes Schindelin | 0e757e3 | 2009-03-03 10:55:31 +0100 | [diff] [blame] | 1065 | |
Ramkumar Ramachandra | 26cd160 | 2013-06-16 14:15:13 +0530 | [diff] [blame] | 1066 | GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name" |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 1067 | output git checkout $onto || die_abort "could not detach HEAD" |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 1068 | git update-ref ORIG_HEAD $orig_head |
Martin von Zweigbergk | 3426232 | 2011-02-06 13:43:35 -0500 | [diff] [blame] | 1069 | do_rest |
Kyle J. McKay | 9f50d32 | 2014-04-11 01:28:17 -0700 | [diff] [blame] | 1070 | |
| 1071 | } |
| 1072 | # ... and then we call the whole thing. |
| 1073 | git_rebase__interactive |