blob: 5c2c4e5276d17f257b255e85db112557d9d7fc61 [file] [log] [blame]
Junio C Hamano59e6b232005-06-25 02:23:43 -07001#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano.
4#
5
Junio C Hamano533b7032007-01-12 12:52:03 -08006SUBDIRECTORY_OK=Yes
Martin von Zweigbergk45e2acf2011-02-28 20:59:26 -05007OPTIONS_KEEPDASHDASH=
Nicolas Vigierb6e9e732014-02-10 01:03:36 +00008OPTIONS_STUCKLONG=t
Martin von Zweigbergk45e2acf2011-02-28 20:59:26 -05009OPTIONS_SPEC="\
Lucien Kongc2145382012-06-12 10:05:12 +020010git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] [<upstream>] [<branch>]
Junio C Hamano0cd993a2012-07-15 21:38:41 -070011git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] --root [<branch>]
Kaartic Sivaraam82cb7752017-11-20 20:56:52 +053012git rebase --continue | --abort | --skip | --edit-todo
Martin von Zweigbergk45e2acf2011-02-28 20:59:26 -050013--
14 Available options are
15v,verbose! display a diffstat of what changed upstream
16q,quiet! be quiet. implies --no-stat
John Keeping619e3602015-09-10 23:30:51 +010017autostash automatically stash/stash pop before and after
John Keepingad8261d2013-12-09 23:16:16 +000018fork-point use 'merge-base --fork-point' to refine upstream
Martin von Zweigbergk45e2acf2011-02-28 20:59:26 -050019onto=! rebase onto given branch instead of upstream
Johannes Schindelin7543f6f2018-04-25 14:29:40 +020020r,rebase-merges? try to rebase merges instead of skipping them
Martin von Zweigbergk45e2acf2011-02-28 20:59:26 -050021p,preserve-merges! try to recreate merges instead of ignoring them
22s,strategy=! use the given merge strategy
Elijah Newrend4e80622018-06-25 09:12:53 -070023X,strategy-option=! pass the argument through to the merge strategy
Martin von Zweigbergk45e2acf2011-02-28 20:59:26 -050024no-ff! cherry-pick all commits, even if unchanged
Elijah Newrend4e80622018-06-25 09:12:53 -070025f,force-rebase! cherry-pick all commits, even if unchanged
Martin von Zweigbergk45e2acf2011-02-28 20:59:26 -050026m,merge! use merging strategies to rebase
27i,interactive! let the user edit the list of commits to rebase
Lucien Kongc2145382012-06-12 10:05:12 +020028x,exec=! add exec lines after each commit of the editable list
Neil Horman90e18182012-04-20 10:36:17 -040029k,keep-empty preserve empty commits during rebase
Genki Skya6c612b2018-02-04 15:08:13 -050030allow-empty-message allow rebasing commits with empty messages
Martin von Zweigbergk45e2acf2011-02-28 20:59:26 -050031stat! display a diffstat of what changed upstream
32n,no-stat! do not show diffstat of what changed upstream
33verify allow pre-rebase hook to run
34rerere-autoupdate allow rerere to update index with resolved conflicts
35root! rebase all reachable commits up to the root(s)
36autosquash move commits that begin with squash!/fixup! under -i
Elijah Newrend4e80622018-06-25 09:12:53 -070037signoff add a Signed-off-by: line to each commit
Martin von Zweigbergk45e2acf2011-02-28 20:59:26 -050038committer-date-is-author-date! passed to 'git am'
39ignore-date! passed to 'git am'
40whitespace=! passed to 'git apply'
41ignore-whitespace! passed to 'git apply'
42C=! passed to 'git apply'
Nicolas Vigier3ee5e542014-02-10 01:03:37 +000043S,gpg-sign? GPG-sign commits
Martin von Zweigbergk45e2acf2011-02-28 20:59:26 -050044 Actions:
Martin von Zweigbergk5960bc92011-07-13 23:47:06 -040045continue! continue
46abort! abort and check out the original branch
47skip! skip current patch and continue
Andrew Wongeb9a7cb2012-09-17 21:28:09 -040048edit-todo! edit the todo list during an interactive rebase
Nguyễn Thái Ngọc Duy95121772016-11-12 09:00:41 +070049quit! abort but keep HEAD where it is
Nguyễn Thái Ngọc Duy66335292018-02-11 16:43:27 +070050show-current-patch! show the patch file being applied or merged
Johannes Schindelind421afa2018-12-10 11:04:58 -080051reschedule-failed-exec automatically reschedule failed exec commands
Martin von Zweigbergk45e2acf2011-02-28 20:59:26 -050052"
Junio C Hamanoae2b0f12005-11-24 00:12:11 -080053. git-sh-setup
Shawn O. Pearcef9474132006-12-28 02:34:48 -050054set_reflog_action rebase
Jeff King035b5bf2011-10-13 11:59:24 -040055require_work_tree_exists
Junio C Hamano533b7032007-01-12 12:52:03 -080056cd_to_toplevel
Junio C Hamano4282c4f2005-08-07 15:51:09 -070057
Junio C Hamano61dfa1b2009-11-20 03:02:44 -080058LF='
59'
Martin von Zweigbergk6bb4e482011-02-06 13:43:37 -050060ok_to_skip_pre_rebase=
Pratik Karkic7b64aa2018-08-07 01:16:10 +054561
Phillip Woodbb2ac4f2018-03-20 10:03:13 +000062squash_onto=
Martin von Zweigbergk6bb4e482011-02-06 13:43:37 -050063unset onto
John Keeping1e0dacd2014-07-16 20:23:49 +010064unset restrict_revision
Lucien Kongc2145382012-06-12 10:05:12 +020065cmd=
Martin von Zweigbergk9765b6a2011-02-06 13:43:38 -050066strategy=
Mike Lundy93ce1902010-07-29 00:04:29 +020067strategy_opts=
Eric Wong58634db2006-06-21 03:04:41 -070068do_merge=
Martin von Zweigbergk69a636a2011-02-06 13:43:30 -050069merge_dir="$GIT_DIR"/rebase-merge
70apply_dir="$GIT_DIR"/rebase-apply
Robert Shearmanb7587892006-10-03 17:29:31 +010071verbose=
Martin von Zweigbergk9474a022010-11-09 21:59:00 +010072diffstat=
73test "$(git config --bool rebase.stat)" = true && diffstat=t
Ramkumar Ramachandra58794772013-05-12 17:26:41 +053074autostash="$(git config --bool rebase.autostash || echo false)"
John Keepingad8261d2013-12-09 23:16:16 +000075fork_point=auto
Michael S. Tsirkin67dad682007-02-08 15:57:08 +020076git_am_opt=
Kevin Willford9eaa8582017-08-10 14:32:56 -040077git_format_patch_opt=
Thomas Rast190f5322009-01-05 18:35:16 +010078rebase_root=
Sverre Rabbelierb2f82e02009-02-13 23:48:01 +010079force_rebase=
Junio C Hamanocb6020b2009-12-04 00:20:48 -080080allow_rerere_autoupdate=
Martin von Zweigbergk99de0642011-02-06 13:43:34 -050081# Non-empty if a rebase was in progress when 'git rebase' was invoked
82in_progress=
83# One of {am, merge, interactive}
84type=
85# One of {"$GIT_DIR"/rebase-apply, "$GIT_DIR"/rebase-merge}
86state_dir=
Martin von Zweigbergk34262322011-02-06 13:43:35 -050087# One of {'', continue, skip, abort}, as parsed from command line
88action=
Johannes Schindelin8f6aed72018-04-25 14:29:04 +020089rebase_merges=
Johannes Schindelin7543f6f2018-04-25 14:29:40 +020090rebase_cousins=
Martin von Zweigbergkcf432ca2011-02-06 13:43:39 -050091preserve_merges=
92autosquash=
Neil Horman90e18182012-04-20 10:36:17 -040093keep_empty=
Elijah Newrenb00bf1c2018-06-27 00:23:19 -070094allow_empty_message=--allow-empty-message
Phillip Wooda852ec72018-03-20 11:10:55 +000095signoff=
Johannes Schindelind421afa2018-12-10 11:04:58 -080096reschedule_failed_exec=
Martin von Zweigbergkcf432ca2011-02-06 13:43:39 -050097test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
Junio C Hamano66948562016-05-02 14:58:45 -070098case "$(git config --bool commit.gpgsign)" in
99true) gpg_sign_opt=-S ;;
100*) gpg_sign_opt= ;;
101esac
Johannes Schindelin969de3f2018-12-10 11:04:59 -0800102test "$(git config --bool rebase.reschedulefailedexec)" = "true" &&
103reschedule_failed_exec=--reschedule-failed-exec
Pratik Karkic7b64aa2018-08-07 01:16:10 +0545104. git-rebase--common
Eric Wong58634db2006-06-21 03:04:41 -0700105
Martin von Zweigbergkfa99c1e2011-02-06 13:43:47 -0500106read_basic_state () {
Ramkumar Ramachandradc8ca912013-06-13 21:36:11 +0530107 test -f "$state_dir/head-name" &&
108 test -f "$state_dir/onto" &&
Martin von Zweigbergk02ac45f2011-02-06 13:43:31 -0500109 head_name=$(cat "$state_dir"/head-name) &&
110 onto=$(cat "$state_dir"/onto) &&
Martin von Zweigbergk84df4562011-02-06 13:43:53 -0500111 # We always write to orig-head, but interactive rebase used to write to
112 # head. Fall back to reading from head to cover for the case that the
113 # user upgraded git with an ongoing interactive rebase.
114 if test -f "$state_dir"/orig-head
Martin von Zweigbergk2959c282011-02-06 13:43:52 -0500115 then
Martin von Zweigbergk2959c282011-02-06 13:43:52 -0500116 orig_head=$(cat "$state_dir"/orig-head)
Martin von Zweigbergk84df4562011-02-06 13:43:53 -0500117 else
118 orig_head=$(cat "$state_dir"/head)
Martin von Zweigbergk2959c282011-02-06 13:43:52 -0500119 fi &&
Elijah Newren899b49c2018-12-11 08:11:36 -0800120 test -f "$state_dir"/quiet && GIT_QUIET=t
Martin von Zweigbergk7b37a7c2011-02-06 13:43:54 -0500121 test -f "$state_dir"/verbose && verbose=t
Martin von Zweigbergk80ff4792011-02-06 13:43:55 -0500122 test -f "$state_dir"/strategy && strategy="$(cat "$state_dir"/strategy)"
123 test -f "$state_dir"/strategy_opts &&
124 strategy_opts="$(cat "$state_dir"/strategy_opts)"
Martin von Zweigbergkb3e48472011-02-06 13:43:56 -0500125 test -f "$state_dir"/allow_rerere_autoupdate &&
126 allow_rerere_autoupdate="$(cat "$state_dir"/allow_rerere_autoupdate)"
Nicolas Vigier3ee5e542014-02-10 01:03:37 +0000127 test -f "$state_dir"/gpg_sign_opt &&
128 gpg_sign_opt="$(cat "$state_dir"/gpg_sign_opt)"
Phillip Wooda852ec72018-03-20 11:10:55 +0000129 test -f "$state_dir"/signoff && {
130 signoff="$(cat "$state_dir"/signoff)"
131 force_rebase=t
132 }
Johannes Schindelind421afa2018-12-10 11:04:58 -0800133 test -f "$state_dir"/reschedule-failed-exec &&
134 reschedule_failed_exec=t
Martin von Zweigbergk02ac45f2011-02-06 13:43:31 -0500135}
136
Ramkumar Ramachandrae4244eb2014-05-19 18:05:20 -0400137finish_rebase () {
Nguyễn Thái Ngọc Duyfbd7a232018-02-11 16:43:28 +0700138 rm -f "$(git rev-parse --git-path REBASE_HEAD)"
Ramkumar Ramachandrae4244eb2014-05-19 18:05:20 -0400139 apply_autostash &&
Jeff King8c24f5b2016-01-13 13:47:18 -0500140 { git gc --auto || true; } &&
Ramkumar Ramachandra58794772013-05-12 17:26:41 +0530141 rm -rf "$state_dir"
142}
143
Alban Gruin0af129b2018-09-27 23:56:08 +0200144run_interactive () {
145 GIT_CHERRY_PICK_HELP="$resolvemsg"
146 export GIT_CHERRY_PICK_HELP
147
148 test -n "$keep_empty" && keep_empty="--keep-empty"
149 test -n "$rebase_merges" && rebase_merges="--rebase-merges"
150 test -n "$rebase_cousins" && rebase_cousins="--rebase-cousins"
151 test -n "$autosquash" && autosquash="--autosquash"
152 test -n "$verbose" && verbose="--verbose"
153 test -n "$force_rebase" && force_rebase="--no-ff"
154 test -n "$restrict_revision" && \
155 restrict_revision="--restrict-revision=^$restrict_revision"
156 test -n "$upstream" && upstream="--upstream=$upstream"
157 test -n "$onto" && onto="--onto=$onto"
158 test -n "$squash_onto" && squash_onto="--squash-onto=$squash_onto"
159 test -n "$onto_name" && onto_name="--onto-name=$onto_name"
160 test -n "$head_name" && head_name="--head-name=$head_name"
161 test -n "$strategy" && strategy="--strategy=$strategy"
162 test -n "$strategy_opts" && strategy_opts="--strategy-opts=$strategy_opts"
163 test -n "$switch_to" && switch_to="--switch-to=$switch_to"
164 test -n "$cmd" && cmd="--cmd=$cmd"
165 test -n "$action" && action="--$action"
166
Alban Gruincf808202018-09-27 23:56:09 +0200167 exec git rebase--interactive "$action" "$keep_empty" "$rebase_merges" "$rebase_cousins" \
Alban Gruin0af129b2018-09-27 23:56:08 +0200168 "$upstream" "$onto" "$squash_onto" "$restrict_revision" \
169 "$allow_empty_message" "$autosquash" "$verbose" \
170 "$force_rebase" "$onto_name" "$head_name" "$strategy" \
171 "$strategy_opts" "$cmd" "$switch_to" \
Johannes Schindelind421afa2018-12-10 11:04:58 -0800172 "$allow_rerere_autoupdate" "$gpg_sign_opt" "$signoff" \
173 "$reschedule_failed_exec"
Alban Gruin0af129b2018-09-27 23:56:08 +0200174}
175
Kyle J. McKay8cd65962014-04-11 01:28:18 -0700176run_specific_rebase () {
Andreas Ericssonf8cca012008-09-29 22:28:57 +0200177 if [ "$interactive_rebase" = implied ]; then
Phillip Wood891d4a02019-01-28 10:27:56 +0000178 GIT_SEQUENCE_EDITOR=:
179 export GIT_SEQUENCE_EDITOR
Vincent van Ravesteijn8a6dae12012-05-24 13:57:26 +0000180 autosquash=
Andreas Ericssonf8cca012008-09-29 22:28:57 +0200181 fi
Alban Gruin6d98d0c2018-05-28 14:34:21 +0200182
Alban Gruin0af129b2018-09-27 23:56:08 +0200183 if test -n "$interactive_rebase" -a -z "$preserve_merges"
Alban Gruin6d98d0c2018-05-28 14:34:21 +0200184 then
Alban Gruin0af129b2018-09-27 23:56:08 +0200185 run_interactive
Alban Gruin6d98d0c2018-05-28 14:34:21 +0200186 else
Alban Gruin0af129b2018-09-27 23:56:08 +0200187 . git-rebase--$type
188
189 if test -z "$preserve_merges"
190 then
191 git_rebase__$type
192 else
193 git_rebase__preserve_merges
194 fi
Alban Gruin6d98d0c2018-05-28 14:34:21 +0200195 fi
196
Ramkumar Ramachandraf5f758a2013-05-12 17:26:37 +0530197 ret=$?
198 if test $ret -eq 0
199 then
Ramkumar Ramachandra58794772013-05-12 17:26:41 +0530200 finish_rebase
Alban Gruinb97e1872018-08-28 14:10:36 +0200201 elif test $ret -eq 2 # special exit status for rebase -p
Ramkumar Ramachandrae4244eb2014-05-19 18:05:20 -0400202 then
203 apply_autostash &&
204 rm -rf "$state_dir" &&
205 die "Nothing to do"
Ramkumar Ramachandraf5f758a2013-05-12 17:26:37 +0530206 fi
207 exit $ret
Johannes Schindelin1b1dce42007-06-25 01:11:14 +0100208}
209
Nanako Shiraishid70b4a82008-10-06 14:14:24 +0900210run_pre_rebase_hook () {
Martin von Zweigbergk6bb4e482011-02-06 13:43:37 -0500211 if test -z "$ok_to_skip_pre_rebase" &&
Nguyễn Thái Ngọc Duyb849b952014-11-30 15:24:38 +0700212 test -x "$(git rev-parse --git-path hooks/pre-rebase)"
Nanako Shiraishid70b4a82008-10-06 14:14:24 +0900213 then
Nguyễn Thái Ngọc Duyb849b952014-11-30 15:24:38 +0700214 "$(git rev-parse --git-path hooks/pre-rebase)" ${1+"$@"} ||
Jiang Xinc7108bf2012-07-25 22:53:08 +0800215 die "$(gettext "The pre-rebase hook refused to rebase.")"
Nanako Shiraishid70b4a82008-10-06 14:14:24 +0900216 fi
217}
218
Martin von Zweigbergk69a636a2011-02-06 13:43:30 -0500219test -f "$apply_dir"/applying &&
Kaartic Sivaraam82cb7752017-11-20 20:56:52 +0530220 die "$(gettext "It looks like 'git am' is in progress. Cannot rebase.")"
Stephan Beyer9b752a62008-08-17 06:25:43 +0200221
Martin von Zweigbergk99de0642011-02-06 13:43:34 -0500222if test -d "$apply_dir"
223then
224 type=am
225 state_dir="$apply_dir"
226elif test -d "$merge_dir"
227then
Elijah Newren68aa4952018-12-11 08:11:39 -0800228 type=interactive
Alban Gruin6d98d0c2018-05-28 14:34:21 +0200229 if test -d "$merge_dir"/rewritten
230 then
231 type=preserve-merges
232 interactive_rebase=explicit
233 preserve_merges=t
234 elif test -f "$merge_dir"/interactive
Martin von Zweigbergk99de0642011-02-06 13:43:34 -0500235 then
Martin von Zweigbergk99de0642011-02-06 13:43:34 -0500236 interactive_rebase=explicit
Martin von Zweigbergk99de0642011-02-06 13:43:34 -0500237 fi
238 state_dir="$merge_dir"
239fi
240test -n "$type" && in_progress=t
241
Martin von Zweigbergk95135b02011-02-06 13:43:36 -0500242total_argc=$#
David Kastrup822f7c72007-09-23 22:42:08 +0200243while test $# != 0
Junio C Hamanoe646c9c2006-02-14 14:42:05 -0800244do
245 case "$1" in
Nanako Shiraishic4427652008-10-06 14:14:29 +0900246 --no-verify)
Martin von Zweigbergk6bb4e482011-02-06 13:43:37 -0500247 ok_to_skip_pre_rebase=yes
Nanako Shiraishic4427652008-10-06 14:14:29 +0900248 ;;
Martin von Zweigbergk7baf9c42010-11-22 21:21:01 +0100249 --verify)
Martin von Zweigbergk6bb4e482011-02-06 13:43:37 -0500250 ok_to_skip_pre_rebase=
Martin von Zweigbergk7baf9c42010-11-22 21:21:01 +0100251 ;;
Nguyễn Thái Ngọc Duy66335292018-02-11 16:43:27 +0700252 --continue|--skip|--abort|--quit|--edit-todo|--show-current-patch)
Martin von Zweigbergk45e2acf2011-02-28 20:59:26 -0500253 test $total_argc -eq 2 || usage
Martin von Zweigbergk34262322011-02-06 13:43:35 -0500254 action=${1##--}
sean031321c2006-04-26 10:49:38 -0400255 ;;
Nicolas Vigierb6e9e732014-02-10 01:03:36 +0000256 --onto=*)
257 onto="${1#--onto=}"
Junio C Hamanoe646c9c2006-02-14 14:42:05 -0800258 ;;
Nicolas Vigierb6e9e732014-02-10 01:03:36 +0000259 --exec=*)
260 cmd="${cmd}exec ${1#--exec=}${LF}"
Stefan Beller78ec2402016-03-18 14:26:17 -0700261 test -z "$interactive_rebase" && interactive_rebase=implied
Lucien Kongc2145382012-06-12 10:05:12 +0200262 ;;
Nicolas Vigierb6e9e732014-02-10 01:03:36 +0000263 --interactive)
Martin von Zweigbergkcf432ca2011-02-06 13:43:39 -0500264 interactive_rebase=explicit
265 ;;
Nicolas Vigierb6e9e732014-02-10 01:03:36 +0000266 --keep-empty)
Neil Horman90e18182012-04-20 10:36:17 -0400267 keep_empty=yes
268 ;;
Genki Skya6c612b2018-02-04 15:08:13 -0500269 --allow-empty-message)
270 allow_empty_message=--allow-empty-message
271 ;;
Phillip Wood3d946162018-03-20 10:03:15 +0000272 --no-keep-empty)
273 keep_empty=
274 ;;
Johannes Schindelin8f6aed72018-04-25 14:29:04 +0200275 --rebase-merges)
276 rebase_merges=t
277 test -z "$interactive_rebase" && interactive_rebase=implied
278 ;;
Johannes Schindelin7543f6f2018-04-25 14:29:40 +0200279 --rebase-merges=*)
280 rebase_merges=t
281 case "${1#*=}" in
282 rebase-cousins) rebase_cousins=t;;
283 no-rebase-cousins) rebase_cousins=;;
284 *) die "Unknown mode: $1";;
285 esac
286 test -z "$interactive_rebase" && interactive_rebase=implied
287 ;;
Nicolas Vigierb6e9e732014-02-10 01:03:36 +0000288 --preserve-merges)
Martin von Zweigbergkcf432ca2011-02-06 13:43:39 -0500289 preserve_merges=t
290 test -z "$interactive_rebase" && interactive_rebase=implied
291 ;;
292 --autosquash)
293 autosquash=t
294 ;;
295 --no-autosquash)
296 autosquash=
297 ;;
John Keepingad8261d2013-12-09 23:16:16 +0000298 --fork-point)
299 fork_point=t
300 ;;
301 --no-fork-point)
302 fork_point=
303 ;;
Nicolas Vigierb6e9e732014-02-10 01:03:36 +0000304 --merge)
Eric Wong58634db2006-06-21 03:04:41 -0700305 do_merge=t
306 ;;
Nicolas Vigierb6e9e732014-02-10 01:03:36 +0000307 --strategy-option=*)
Elijah Newren00600412018-06-27 08:48:04 -0700308 strategy_opts="$strategy_opts $(git rev-parse --sq-quote "--${1#--strategy-option=}" | sed -e s/^.//)"
Mike Lundy93ce1902010-07-29 00:04:29 +0200309 do_merge=t
Martin von Zweigbergk9765b6a2011-02-06 13:43:38 -0500310 test -z "$strategy" && strategy=recursive
Mike Lundy93ce1902010-07-29 00:04:29 +0200311 ;;
Nicolas Vigierb6e9e732014-02-10 01:03:36 +0000312 --strategy=*)
313 strategy="${1#--strategy=}"
Eric Wong58634db2006-06-21 03:04:41 -0700314 do_merge=t
315 ;;
Nicolas Vigierb6e9e732014-02-10 01:03:36 +0000316 --no-stat)
Tor Arne Vestbøa9c38212009-03-01 23:11:38 +0100317 diffstat=
318 ;;
319 --stat)
320 diffstat=t
321 ;;
Ramkumar Ramachandra58794772013-05-12 17:26:41 +0530322 --autostash)
323 autostash=true
324 ;;
John Keeping619e3602015-09-10 23:30:51 +0100325 --no-autostash)
326 autostash=false
327 ;;
Nicolas Vigierb6e9e732014-02-10 01:03:36 +0000328 --verbose)
Robert Shearmanb7587892006-10-03 17:29:31 +0100329 verbose=t
Tor Arne Vestbøa9c38212009-03-01 23:11:38 +0100330 diffstat=t
Stephen Boyd0e987a12009-06-16 15:33:01 -0700331 GIT_QUIET=
332 ;;
Nicolas Vigierb6e9e732014-02-10 01:03:36 +0000333 --quiet)
Stephen Boyd0e987a12009-06-16 15:33:01 -0700334 GIT_QUIET=t
335 git_am_opt="$git_am_opt -q"
336 verbose=
337 diffstat=
Robert Shearmanb7587892006-10-03 17:29:31 +0100338 ;;
Nicolas Vigierb6e9e732014-02-10 01:03:36 +0000339 --whitespace=*)
340 git_am_opt="$git_am_opt --whitespace=${1#--whitespace=}"
341 case "${1#--whitespace=}" in
Martin von Zweigbergk45e2acf2011-02-28 20:59:26 -0500342 fix|strip)
Sverre Rabbelierb2f82e02009-02-13 23:48:01 +0100343 force_rebase=t
344 ;;
Johannes Schindelin7e097e22018-11-20 12:02:01 -0800345 warn|nowarn|error|error-all)
346 ;; # okay, known whitespace option
347 *)
348 die "fatal: Invalid whitespace option: '${1#*=}'"
349 ;;
Sverre Rabbelierb2f82e02009-02-13 23:48:01 +0100350 esac
J. Bruce Fields059f4462007-09-07 10:20:50 -0400351 ;;
Giuseppe Bilotta86c91f92009-08-04 13:16:49 +0200352 --ignore-whitespace)
353 git_am_opt="$git_am_opt $1"
354 ;;
Phillip Wooda852ec72018-03-20 11:10:55 +0000355 --signoff)
356 signoff=--signoff
357 ;;
358 --no-signoff)
359 signoff=
360 ;;
361 --committer-date-is-author-date|--ignore-date)
Michele Ballabio570ccad2009-03-18 21:53:49 +0100362 git_am_opt="$git_am_opt $1"
363 force_rebase=t
364 ;;
Johannes Schindelin7e097e22018-11-20 12:02:01 -0800365 -C*[!0-9]*)
366 die "fatal: switch \`C' expects a numerical value"
367 ;;
Nicolas Vigierb6e9e732014-02-10 01:03:36 +0000368 -C*)
369 git_am_opt="$git_am_opt $1"
Michael S. Tsirkin67dad682007-02-08 15:57:08 +0200370 ;;
Thomas Rast190f5322009-01-05 18:35:16 +0100371 --root)
372 rebase_root=t
373 ;;
Nicolas Vigierb6e9e732014-02-10 01:03:36 +0000374 --force-rebase|--no-ff)
Sverre Rabbelierb2f82e02009-02-13 23:48:01 +0100375 force_rebase=t
376 ;;
Junio C Hamanocb6020b2009-12-04 00:20:48 -0800377 --rerere-autoupdate|--no-rerere-autoupdate)
378 allow_rerere_autoupdate="$1"
379 ;;
Nicolas Vigier3ee5e542014-02-10 01:03:37 +0000380 --gpg-sign)
381 gpg_sign_opt=-S
382 ;;
383 --gpg-sign=*)
384 gpg_sign_opt="-S${1#--gpg-sign=}"
385 ;;
Johannes Schindelind421afa2018-12-10 11:04:58 -0800386 --reschedule-failed-exec)
387 reschedule_failed_exec=--reschedule-failed-exec
388 ;;
389 --no-reschedule-failed-exec)
390 reschedule_failed_exec=
391 ;;
Martin von Zweigbergk45e2acf2011-02-28 20:59:26 -0500392 --)
393 shift
Junio C Hamanoe646c9c2006-02-14 14:42:05 -0800394 break
395 ;;
Brandon Casey697bc882017-09-17 15:28:17 -0700396 *)
397 usage
398 ;;
Junio C Hamanoe646c9c2006-02-14 14:42:05 -0800399 esac
400 shift
401done
Jay Soffian51b2ead2009-02-18 08:44:02 -0500402test $# -gt 2 && usage
Junio C Hamano2db8aae2005-12-14 03:11:37 -0800403
Martin von Zweigbergkcf432ca2011-02-06 13:43:39 -0500404if test -n "$action"
405then
Jiang Xinc7108bf2012-07-25 22:53:08 +0800406 test -z "$in_progress" && die "$(gettext "No rebase in progress?")"
Martin von Zweigbergk2959c282011-02-06 13:43:52 -0500407 # Only interactive rebase uses detailed reflog messages
Alban Gruin6d98d0c2018-05-28 14:34:21 +0200408 if test -n "$interactive_rebase" && test "$GIT_REFLOG_ACTION" = rebase
Martin von Zweigbergk2959c282011-02-06 13:43:52 -0500409 then
410 GIT_REFLOG_ACTION="rebase -i ($action)"
411 export GIT_REFLOG_ACTION
412 fi
Martin von Zweigbergkcf432ca2011-02-06 13:43:39 -0500413fi
Martin von Zweigbergk34262322011-02-06 13:43:35 -0500414
Alban Gruin6d98d0c2018-05-28 14:34:21 +0200415if test "$action" = "edit-todo" && test -z "$interactive_rebase"
Andrew Wongeb9a7cb2012-09-17 21:28:09 -0400416then
417 die "$(gettext "The --edit-todo action can only be used during interactive rebase.")"
418fi
419
Martin von Zweigbergk34262322011-02-06 13:43:35 -0500420case "$action" in
421continue)
Martin von Zweigbergk2959c282011-02-06 13:43:52 -0500422 # Sanity check
423 git rev-parse --verify HEAD >/dev/null ||
Jiang Xinc7108bf2012-07-25 22:53:08 +0800424 die "$(gettext "Cannot read HEAD")"
Martin von Zweigbergk34262322011-02-06 13:43:35 -0500425 git update-index --ignore-submodules --refresh &&
426 git diff-files --quiet --ignore-submodules || {
Jiang Xinc7108bf2012-07-25 22:53:08 +0800427 echo "$(gettext "You must edit all merge conflicts and then
428mark them as resolved using git add")"
Martin von Zweigbergk34262322011-02-06 13:43:35 -0500429 exit 1
430 }
Martin von Zweigbergkfa99c1e2011-02-06 13:43:47 -0500431 read_basic_state
432 run_specific_rebase
Martin von Zweigbergk34262322011-02-06 13:43:35 -0500433 ;;
434skip)
Martin von Zweigbergk4974c2c2011-02-06 13:43:51 -0500435 output git reset --hard HEAD || exit $?
Martin von Zweigbergkfa99c1e2011-02-06 13:43:47 -0500436 read_basic_state
437 run_specific_rebase
Martin von Zweigbergk34262322011-02-06 13:43:35 -0500438 ;;
439abort)
440 git rerere clear
Martin von Zweigbergkfa99c1e2011-02-06 13:43:47 -0500441 read_basic_state
Martin von Zweigbergk34262322011-02-06 13:43:35 -0500442 case "$head_name" in
443 refs/*)
Csaba Henkea696192011-05-27 16:13:02 -0400444 git symbolic-ref -m "rebase: aborting" HEAD $head_name ||
Jiang Xinc7108bf2012-07-25 22:53:08 +0800445 die "$(eval_gettext "Could not move back to \$head_name")"
Martin von Zweigbergk34262322011-02-06 13:43:35 -0500446 ;;
447 esac
Martin von Zweigbergk4974c2c2011-02-06 13:43:51 -0500448 output git reset --hard $orig_head
Ramkumar Ramachandra58794772013-05-12 17:26:41 +0530449 finish_rebase
Martin von Zweigbergk34262322011-02-06 13:43:35 -0500450 exit
451 ;;
Nguyễn Thái Ngọc Duy95121772016-11-12 09:00:41 +0700452quit)
453 exec rm -rf "$state_dir"
454 ;;
Andrew Wongeb9a7cb2012-09-17 21:28:09 -0400455edit-todo)
456 run_specific_rebase
457 ;;
Nguyễn Thái Ngọc Duy66335292018-02-11 16:43:27 +0700458show-current-patch)
459 run_specific_rebase
460 die "BUG: run_specific_rebase is not supposed to return here"
461 ;;
Martin von Zweigbergk34262322011-02-06 13:43:35 -0500462esac
463
Martin von Zweigbergk99de0642011-02-06 13:43:34 -0500464# Make sure no rebase is in progress
465if test -n "$in_progress"
Jonathan Niederbffd7502010-05-31 17:51:32 -0500466then
Jiang Xinc7108bf2012-07-25 22:53:08 +0800467 state_dir_base=${state_dir##*/}
468 cmd_live_rebase="git rebase (--continue | --abort | --skip)"
469 cmd_clear_stale_rebase="rm -fr \"$state_dir\""
470 die "
471$(eval_gettext 'It seems that there is already a $state_dir_base directory, and
Ralf Thielowe39beac2012-08-01 19:09:09 +0200472I wonder if you are in the middle of another rebase. If that is the
Martin von Zweigbergk99de0642011-02-06 13:43:34 -0500473case, please try
Jiang Xinc7108bf2012-07-25 22:53:08 +0800474 $cmd_live_rebase
Martin von Zweigbergk99de0642011-02-06 13:43:34 -0500475If that is not the case, please
Jiang Xinc7108bf2012-07-25 22:53:08 +0800476 $cmd_clear_stale_rebase
Stephan Beyer9b752a62008-08-17 06:25:43 +0200477and run me again. I am stopping in case you still have something
Jiang Xinc7108bf2012-07-25 22:53:08 +0800478valuable there.')"
Junio C Hamano7f4bd5d2005-11-28 13:00:31 -0800479fi
480
Chris Webbdf5df202012-06-26 22:55:23 +0100481if test -n "$rebase_root" && test -z "$onto"
482then
483 test -z "$interactive_rebase" && interactive_rebase=implied
484fi
485
Phillip Woodda27a6f2018-03-20 11:10:57 +0000486if test -n "$keep_empty"
487then
488 test -z "$interactive_rebase" && interactive_rebase=implied
489fi
490
Elijah Newren68aa4952018-12-11 08:11:39 -0800491actually_interactive=
Martin von Zweigbergkcf432ca2011-02-06 13:43:39 -0500492if test -n "$interactive_rebase"
493then
Alban Gruin6d98d0c2018-05-28 14:34:21 +0200494 if test -z "$preserve_merges"
495 then
496 type=interactive
497 else
498 type=preserve-merges
499 fi
Elijah Newren68aa4952018-12-11 08:11:39 -0800500 actually_interactive=t
Martin von Zweigbergkcf432ca2011-02-06 13:43:39 -0500501 state_dir="$merge_dir"
502elif test -n "$do_merge"
503then
Elijah Newren68aa4952018-12-11 08:11:39 -0800504 interactive_rebase=implied
505 type=interactive
Martin von Zweigbergkcf432ca2011-02-06 13:43:39 -0500506 state_dir="$merge_dir"
507else
508 type=am
509 state_dir="$apply_dir"
510fi
511
Kevin Willford9eaa8582017-08-10 14:32:56 -0400512if test -t 2 && test -z "$GIT_QUIET"
513then
514 git_format_patch_opt="$git_format_patch_opt --progress"
515fi
516
Elijah Newren7b76ac62018-12-11 08:11:37 -0800517incompatible_opts=$(echo " $git_am_opt " | \
518 sed -e 's/ -q / /g' -e 's/^ \(.*\) $/\1/')
519if test -n "$incompatible_opts"
520then
Elijah Newren68aa4952018-12-11 08:11:39 -0800521 if test -n "$actually_interactive" || test "$do_merge"
Elijah Newrenc840e1a2018-06-27 00:23:14 -0700522 then
Elijah Newren68aa4952018-12-11 08:11:39 -0800523 die "$(gettext "fatal: cannot combine am options with either interactive or merge options")"
Elijah Newrenc840e1a2018-06-27 00:23:14 -0700524 fi
525fi
526
Phillip Wooda852ec72018-03-20 11:10:55 +0000527if test -n "$signoff"
528then
Phillip Woodb79966a2018-03-20 11:10:56 +0000529 test -n "$preserve_merges" &&
Elijah Newrenc913c592018-12-11 08:11:32 -0800530 die "$(gettext "fatal: cannot combine '--signoff' with '--preserve-merges'")"
Phillip Wooda852ec72018-03-20 11:10:55 +0000531 git_am_opt="$git_am_opt $signoff"
532 force_rebase=t
533fi
534
Elijah Newrenc840e1a2018-06-27 00:23:14 -0700535if test -n "$preserve_merges"
536then
537 # Note: incompatibility with --signoff handled in signoff block above
538 # Note: incompatibility with --interactive is just a strong warning;
539 # git-rebase.txt caveats with "unless you know what you are doing"
540 test -n "$rebase_merges" &&
Elijah Newrenc913c592018-12-11 08:11:32 -0800541 die "$(gettext "fatal: cannot combine '--preserve-merges' with '--rebase-merges'")"
Johannes Schindelind421afa2018-12-10 11:04:58 -0800542
543 test -n "$reschedule_failed_exec" &&
544 die "$(gettext "error: cannot combine '--preserve-merges' with '--reschedule-failed-exec'")"
Elijah Newrenc840e1a2018-06-27 00:23:14 -0700545fi
546
547if test -n "$rebase_merges"
548then
549 test -n "$strategy_opts" &&
Elijah Newrenc913c592018-12-11 08:11:32 -0800550 die "$(gettext "fatal: cannot combine '--rebase-merges' with '--strategy-option'")"
Elijah Newrenc840e1a2018-06-27 00:23:14 -0700551 test -n "$strategy" &&
Elijah Newrenc913c592018-12-11 08:11:32 -0800552 die "$(gettext "fatal: cannot combine '--rebase-merges' with '--strategy'")"
Elijah Newrenc840e1a2018-06-27 00:23:14 -0700553fi
554
Thomas Rast190f5322009-01-05 18:35:16 +0100555if test -z "$rebase_root"
556then
Martin von Zweigbergk15a147e2011-02-09 20:54:02 -0500557 case "$#" in
558 0)
559 if ! upstream_name=$(git rev-parse --symbolic-full-name \
560 --verify -q @{upstream} 2>/dev/null)
561 then
562 . git-parse-remote
563 error_on_missing_default_upstream "rebase" "rebase" \
Vasco Almeidac36d8ee2016-06-17 20:20:59 +0000564 "against" "git rebase $(gettext '<branch>')"
Martin von Zweigbergk15a147e2011-02-09 20:54:02 -0500565 fi
John Keepingad8261d2013-12-09 23:16:16 +0000566
567 test "$fork_point" = auto && fork_point=t
Martin von Zweigbergk15a147e2011-02-09 20:54:02 -0500568 ;;
569 *) upstream_name="$1"
Brian Gesiak4f407402014-03-19 20:02:15 +0900570 if test "$upstream_name" = "-"
571 then
572 upstream_name="@{-1}"
573 fi
Martin von Zweigbergk15a147e2011-02-09 20:54:02 -0500574 shift
575 ;;
576 esac
Ramkumar Ramachandra2e6e2762013-06-14 18:47:52 +0530577 upstream=$(peel_committish "${upstream_name}") ||
Kaartic Sivaraamca7de7b2017-12-16 14:33:18 +0530578 die "$(eval_gettext "invalid upstream '\$upstream_name'")"
Thomas Rast190f5322009-01-05 18:35:16 +0100579 upstream_arg="$upstream_name"
580else
Chris Webbdf5df202012-06-26 22:55:23 +0100581 if test -z "$onto"
582 then
Elia Pinto728fc792014-04-23 06:44:00 -0700583 empty_tree=$(git hash-object -t tree /dev/null)
584 onto=$(git commit-tree $empty_tree </dev/null)
Chris Webbdf5df202012-06-26 22:55:23 +0100585 squash_onto="$onto"
586 fi
Thomas Rast190f5322009-01-05 18:35:16 +0100587 unset upstream_name
588 unset upstream
Martin von Zweigbergkf2b6a192012-06-26 07:51:55 -0700589 test $# -gt 1 && usage
Martin von Zweigbergk46df82d2011-02-06 13:43:48 -0500590 upstream_arg=--root
Thomas Rast190f5322009-01-05 18:35:16 +0100591fi
Lukas Sandström32d99542005-12-15 00:36:35 +0100592
Junio C Hamanoa1bf91e2007-03-22 02:54:59 -0700593# Make sure the branch to rebase onto is valid.
Martin von Zweigbergk6bb4e482011-02-06 13:43:37 -0500594onto_name=${onto-"$upstream_name"}
Nanako Shiraishi9f21e972010-01-07 20:05:02 +0900595case "$onto_name" in
596*...*)
597 if left=${onto_name%...*} right=${onto_name#*...} &&
598 onto=$(git merge-base --all ${left:-HEAD} ${right:-HEAD})
599 then
600 case "$onto" in
601 ?*"$LF"?*)
Jiang Xinc7108bf2012-07-25 22:53:08 +0800602 die "$(eval_gettext "\$onto_name: there are more than one merge bases")"
Nanako Shiraishi9f21e972010-01-07 20:05:02 +0900603 ;;
604 '')
Jiang Xinc7108bf2012-07-25 22:53:08 +0800605 die "$(eval_gettext "\$onto_name: there is no merge base")"
Nanako Shiraishi9f21e972010-01-07 20:05:02 +0900606 ;;
607 esac
608 else
Jiang Xinc7108bf2012-07-25 22:53:08 +0800609 die "$(eval_gettext "\$onto_name: there is no merge base")"
Nanako Shiraishi9f21e972010-01-07 20:05:02 +0900610 fi
611 ;;
612*)
Ramkumar Ramachandra2e6e2762013-06-14 18:47:52 +0530613 onto=$(peel_committish "$onto_name") ||
Jiang Xinc7108bf2012-07-25 22:53:08 +0800614 die "$(eval_gettext "Does not point to a valid commit: \$onto_name")"
Nanako Shiraishi9f21e972010-01-07 20:05:02 +0900615 ;;
616esac
Junio C Hamanoa1bf91e2007-03-22 02:54:59 -0700617
Junio C Hamano0cb06642008-03-15 13:17:42 -0700618# If the branch to rebase is given, that is the branch we will rebase
Kaartic Sivaraam3a9156a2017-12-16 14:33:17 +0530619# $branch_name -- branch/commit being rebased, or HEAD (already detached)
Junio C Hamano0cb06642008-03-15 13:17:42 -0700620# $orig_head -- commit object name of tip of the branch before rebasing
621# $head_name -- refs/heads/<that-branch> or "detached HEAD"
622switch_to=
Junio C Hamano7f59dbb2005-11-14 00:41:53 -0800623case "$#" in
Thomas Rast190f5322009-01-05 18:35:16 +01006241)
Junio C Hamano0cb06642008-03-15 13:17:42 -0700625 # Is it "rebase other $branchname" or "rebase other $commit"?
Thomas Rast190f5322009-01-05 18:35:16 +0100626 branch_name="$1"
627 switch_to="$1"
Junio C Hamano0cb06642008-03-15 13:17:42 -0700628
Kaartic Sivaraam3a9156a2017-12-16 14:33:17 +0530629 # Is it a local branch?
630 if git show-ref --verify --quiet -- "refs/heads/$branch_name" &&
631 orig_head=$(git rev-parse -q --verify "refs/heads/$branch_name")
Junio C Hamanobcf31612007-01-20 19:11:29 -0800632 then
Kaartic Sivaraam3a9156a2017-12-16 14:33:17 +0530633 head_name="refs/heads/$branch_name"
634 # If not is it a valid ref (branch or commit)?
635 elif orig_head=$(git rev-parse -q --verify "$branch_name")
Junio C Hamano0cb06642008-03-15 13:17:42 -0700636 then
637 head_name="detached HEAD"
Kaartic Sivaraam3a9156a2017-12-16 14:33:17 +0530638
Junio C Hamanobcf31612007-01-20 19:11:29 -0800639 else
Kaartic Sivaraamca7de7b2017-12-16 14:33:18 +0530640 die "$(eval_gettext "fatal: no such branch/commit '\$branch_name'")"
Junio C Hamanobcf31612007-01-20 19:11:29 -0800641 fi
Junio C Hamanoe646c9c2006-02-14 14:42:05 -0800642 ;;
Martin von Zweigbergkf2b6a192012-06-26 07:51:55 -07006430)
Junio C Hamano0cb06642008-03-15 13:17:42 -0700644 # Do not need to switch branches, we are already on it.
Elia Pinto728fc792014-04-23 06:44:00 -0700645 if branch_name=$(git symbolic-ref -q HEAD)
Junio C Hamano0cb06642008-03-15 13:17:42 -0700646 then
647 head_name=$branch_name
Elia Pinto728fc792014-04-23 06:44:00 -0700648 branch_name=$(expr "z$branch_name" : 'zrefs/heads/\(.*\)')
Junio C Hamano0cb06642008-03-15 13:17:42 -0700649 else
650 head_name="detached HEAD"
Kaartic Sivaraam3a9156a2017-12-16 14:33:17 +0530651 branch_name=HEAD
Junio C Hamano0cb06642008-03-15 13:17:42 -0700652 fi
Phil Hordea709802013-04-23 18:51:14 -0400653 orig_head=$(git rev-parse --verify HEAD) || exit
Junio C Hamano0cb06642008-03-15 13:17:42 -0700654 ;;
Martin von Zweigbergkf2b6a192012-06-26 07:51:55 -0700655*)
656 die "BUG: unexpected number of arguments left to parse"
657 ;;
Junio C Hamano7f59dbb2005-11-14 00:41:53 -0800658esac
Junio C Hamano99a92f92005-08-17 15:19:57 -0700659
John Keepingad8261d2013-12-09 23:16:16 +0000660if test "$fork_point" = t
661then
John Keepingbb3f4582014-01-09 19:47:34 +0000662 new_upstream=$(git merge-base --fork-point "$upstream_name" \
663 "${switch_to:-HEAD}")
John Keepingad8261d2013-12-09 23:16:16 +0000664 if test -n "$new_upstream"
665 then
John Keeping1e0dacd2014-07-16 20:23:49 +0100666 restrict_revision=$new_upstream
John Keepingad8261d2013-12-09 23:16:16 +0000667 fi
668fi
669
Ramkumar Ramachandra58794772013-05-12 17:26:41 +0530670if test "$autostash" = true && ! (require_clean_work_tree) 2>/dev/null
671then
672 stash_sha1=$(git stash create "autostash") ||
673 die "$(gettext 'Cannot autostash')"
674
675 mkdir -p "$state_dir" &&
676 echo $stash_sha1 >"$state_dir/autostash" &&
677 stash_abbrev=$(git rev-parse --short $stash_sha1) &&
678 echo "$(eval_gettext 'Created autostash: $stash_abbrev')" &&
679 git reset --hard
680fi
681
Jiang Xinc7108bf2012-07-25 22:53:08 +0800682require_clean_work_tree "rebase" "$(gettext "Please commit or stash them.")"
Martin von Zweigbergk8f9bfb62011-02-06 13:43:41 -0500683
Martin von Zweigbergkcb82a052011-02-06 13:43:46 -0500684# Now we are rebasing commits $upstream..$orig_head (or with --root,
685# everything leading up to $orig_head) on top of $onto
Junio C Hamanoe646c9c2006-02-14 14:42:05 -0800686
Johannes Sixt1308c172007-07-04 22:09:10 +0200687# Check if we are already based on $onto with linear history,
Martin von Zweigbergkcc1453e2011-02-06 13:43:44 -0500688# but this should be done only when upstream and onto are the same
689# and if this is not an interactive rebase.
Martin von Zweigbergkcb82a052011-02-06 13:43:46 -0500690mb=$(git merge-base "$onto" "$orig_head")
Elijah Newren68aa4952018-12-11 08:11:39 -0800691if test -z "$actually_interactive" && test "$upstream" = "$onto" &&
John Keeping1e0dacd2014-07-16 20:23:49 +0100692 test "$mb" = "$onto" && test -z "$restrict_revision" &&
Johannes Sixt1308c172007-07-04 22:09:10 +0200693 # linear history?
Martin von Zweigbergkcb82a052011-02-06 13:43:46 -0500694 ! (git rev-list --parents "$onto".."$orig_head" | sane_grep " .* ") > /dev/null
Junio C Hamano7f4bd5d2005-11-28 13:00:31 -0800695then
Sverre Rabbelierb2f82e02009-02-13 23:48:01 +0100696 if test -z "$force_rebase"
697 then
698 # Lazily switch to the target branch if needed...
Ramkumar Ramachandra4b03df22013-06-16 14:15:12 +0530699 test -z "$switch_to" ||
700 GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to" \
Jeff King22946a92015-04-28 01:17:37 -0400701 git checkout -q "$switch_to" --
Kaartic Sivaraam08e66702017-12-16 14:33:19 +0530702 if test "$branch_name" = "HEAD" &&
703 ! git symbolic-ref -q HEAD
704 then
705 say "$(eval_gettext "HEAD is up to date.")"
706 else
707 say "$(eval_gettext "Current branch \$branch_name is up to date.")"
708 fi
Ramkumar Ramachandra96e2b992013-06-13 21:36:13 +0530709 finish_rebase
Sverre Rabbelierb2f82e02009-02-13 23:48:01 +0100710 exit 0
711 else
Kaartic Sivaraam08e66702017-12-16 14:33:19 +0530712 if test "$branch_name" = "HEAD" &&
713 ! git symbolic-ref -q HEAD
714 then
715 say "$(eval_gettext "HEAD is up to date, rebase forced.")"
716 else
717 say "$(eval_gettext "Current branch \$branch_name is up to date, rebase forced.")"
718 fi
Sverre Rabbelierb2f82e02009-02-13 23:48:01 +0100719 fi
Junio C Hamano7f4bd5d2005-11-28 13:00:31 -0800720fi
721
Martin von Zweigbergk8f9bfb62011-02-06 13:43:41 -0500722# If a hook exists, give it a chance to interrupt
723run_pre_rebase_hook "$upstream_arg" "$@"
724
Tor Arne Vestbøa9c38212009-03-01 23:11:38 +0100725if test -n "$diffstat"
726then
727 if test -n "$verbose"
728 then
Johannes Schindelin8797f0f2018-11-29 05:01:54 -0800729 if test -z "$mb"
730 then
731 echo "$(eval_gettext "Changes to \$onto:")"
732 else
733 echo "$(eval_gettext "Changes from \$mb to \$onto:")"
734 fi
Tor Arne Vestbøa9c38212009-03-01 23:11:38 +0100735 fi
Johannes Schindelin8797f0f2018-11-29 05:01:54 -0800736 mb_tree="${mb:-$(git hash-object -t tree /dev/null)}"
Tor Arne Vestbøa9c38212009-03-01 23:11:38 +0100737 # We want color (if set), but no pager
Johannes Schindelin8797f0f2018-11-29 05:01:54 -0800738 GIT_PAGER='' git diff --stat --summary "$mb_tree" "$onto"
Tor Arne Vestbøa9c38212009-03-01 23:11:38 +0100739fi
740
Elijah Newren68aa4952018-12-11 08:11:39 -0800741if test -z "$actually_interactive" && test "$mb" = "$orig_head"
742then
743 say "$(eval_gettext "Fast-forwarded \$branch_name to \$onto_name.")"
744 GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name" \
745 git checkout -q "$onto^0" || die "could not detach HEAD"
746 # If the $onto is a proper descendant of the tip of the branch, then
747 # we just fast-forwarded.
748 git update-ref ORIG_HEAD $orig_head
749 move_to_original_branch
750 finish_rebase
751 exit 0
752fi
753
Alban Gruin6d98d0c2018-05-28 14:34:21 +0200754test -n "$interactive_rebase" && run_specific_rebase
Martin von Zweigbergkf4107d92011-02-06 13:43:45 -0500755
756# Detach HEAD and reset the tree
Jiang Xinc7108bf2012-07-25 22:53:08 +0800757say "$(gettext "First, rewinding head to replay your work on top of it...")"
Ramkumar Ramachandra4b03df22013-06-16 14:15:12 +0530758
759GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name" \
760 git checkout -q "$onto^0" || die "could not detach HEAD"
Martin von Zweigbergkcb82a052011-02-06 13:43:46 -0500761git update-ref ORIG_HEAD $orig_head
Martin von Zweigbergkf4107d92011-02-06 13:43:45 -0500762
Thomas Rast190f5322009-01-05 18:35:16 +0100763if test -n "$rebase_root"
764then
765 revisions="$onto..$orig_head"
766else
John Keeping1e0dacd2014-07-16 20:23:49 +0100767 revisions="${restrict_revision-$upstream}..$orig_head"
Thomas Rast190f5322009-01-05 18:35:16 +0100768fi
769
Martin von Zweigbergkfa99c1e2011-02-06 13:43:47 -0500770run_specific_rebase