Skip to content
Newer
Older
100755 545 lines (512 sloc) 13.3 KB
59e6b23 [PATCH] git-rebase-script: rebase local commits to new upstream head.
Junio C Hamano authored
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Junio C Hamano.
4 #
5
533b703 Allow whole-tree operations to be started from a subdirectory
Junio C Hamano authored
6 SUBDIRECTORY_OK=Yes
45e2acf rebase: define options in OPTIONS_SPEC
Martin von Zweigbergk authored
7 OPTIONS_KEEPDASHDASH=
8 OPTIONS_SPEC="\
c214538 rebase -i: teach "--exec <cmd>"
Lucien Kong authored
9 git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] [<upstream>] [<branch>]
0cd993a @gitster Merge branch 'cw/rebase-i-root'
authored
10 git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] --root [<branch>]
eb9a7cb @andrewkww rebase -i: Teach "--edit-todo" action
andrewkww authored
11 git-rebase --continue | --abort | --skip | --edit-todo
45e2acf rebase: define options in OPTIONS_SPEC
Martin von Zweigbergk authored
12 --
13 Available options are
14 v,verbose! display a diffstat of what changed upstream
15 q,quiet! be quiet. implies --no-stat
16 onto=! rebase onto given branch instead of upstream
17 p,preserve-merges! try to recreate merges instead of ignoring them
18 s,strategy=! use the given merge strategy
19 no-ff! cherry-pick all commits, even if unchanged
20 m,merge! use merging strategies to rebase
21 i,interactive! let the user edit the list of commits to rebase
c214538 rebase -i: teach "--exec <cmd>"
Lucien Kong authored
22 x,exec=! add exec lines after each commit of the editable list
90e1818 git-rebase: add keep_empty flag
Neil Horman authored
23 k,keep-empty preserve empty commits during rebase
45e2acf rebase: define options in OPTIONS_SPEC
Martin von Zweigbergk authored
24 f,force-rebase! force rebase even if branch is up to date
25 X,strategy-option=! pass the argument through to the merge strategy
26 stat! display a diffstat of what changed upstream
27 n,no-stat! do not show diffstat of what changed upstream
28 verify allow pre-rebase hook to run
29 rerere-autoupdate allow rerere to update index with resolved conflicts
30 root! rebase all reachable commits up to the root(s)
31 autosquash move commits that begin with squash!/fixup! under -i
32 committer-date-is-author-date! passed to 'git am'
33 ignore-date! passed to 'git am'
34 whitespace=! passed to 'git apply'
35 ignore-whitespace! passed to 'git apply'
36 C=! passed to 'git apply'
37 Actions:
5960bc9 rebase: clarify "restore the original branch"
Martin von Zweigbergk authored
38 continue! continue
39 abort! abort and check out the original branch
40 skip! skip current patch and continue
eb9a7cb @andrewkww rebase -i: Teach "--edit-todo" action
andrewkww authored
41 edit-todo! edit the todo list during an interactive rebase
45e2acf rebase: define options in OPTIONS_SPEC
Martin von Zweigbergk authored
42 "
ae2b0f1 git-sh-setup: die if outside git repository.
Junio C Hamano authored
43 . git-sh-setup
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
44 . git-sh-i18n
f947413 @spearce Use GIT_REFLOG_ACTION environment variable instead.
spearce authored
45 set_reflog_action rebase
035b5bf @peff pull,rebase: handle GIT_WORK_TREE better
peff authored
46 require_work_tree_exists
533b703 Allow whole-tree operations to be started from a subdirectory
Junio C Hamano authored
47 cd_to_toplevel
4282c4f Teach format-patch, rebase and cherry a..b format
Junio C Hamano authored
48
61dfa1b @gitster "rebase --onto A...B" replays history on the merge base between A and B
authored
49 LF='
50 '
6bb4e48 rebase: align variable names
Martin von Zweigbergk authored
51 ok_to_skip_pre_rebase=
52 resolvemsg="
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
53 $(gettext 'When you have resolved this problem, run "git rebase --continue".
54 If you prefer to skip this patch, run "git rebase --skip" instead.
55 To check out the original branch and stop rebasing, run "git rebase --abort".')
cc12005 @loops Make git rebase interactive help match documentation.
loops authored
56 "
6bb4e48 rebase: align variable names
Martin von Zweigbergk authored
57 unset onto
c214538 rebase -i: teach "--exec <cmd>"
Lucien Kong authored
58 cmd=
9765b6a rebase: align variable content
Martin von Zweigbergk authored
59 strategy=
93ce190 @novas0x2a rebase: support -X to pass through strategy options
novas0x2a authored
60 strategy_opts=
58634db rebase: Allow merge strategies to be used when rebasing
Eric Wong authored
61 do_merge=
69a636a rebase: clearer names for directory variables
Martin von Zweigbergk authored
62 merge_dir="$GIT_DIR"/rebase-merge
63 apply_dir="$GIT_DIR"/rebase-apply
b758789 git-rebase: Add a -v option to show a diffstat of the changes upstrea…
Robert Shearman authored
64 verbose=
9474a02 rebase: only show stat if configured to true
Martin von Zweigbergk authored
65 diffstat=
66 test "$(git config --bool rebase.stat)" = true && diffstat=t
67dad68 add -C[NUM] to git-am
Michael S. Tsirkin authored
67 git_am_opt=
190f532 @trast rebase: learn to rebase root commit
trast authored
68 rebase_root=
b2f82e0 @SRabbelier Teach rebase to rebase even if upstream is up to date
SRabbelier authored
69 force_rebase=
cb6020b @gitster Teach --[no-]rerere-autoupdate option to merge, revert and friends
authored
70 allow_rerere_autoupdate=
99de064 rebase: improve detection of rebase in progress
Martin von Zweigbergk authored
71 # Non-empty if a rebase was in progress when 'git rebase' was invoked
72 in_progress=
73 # One of {am, merge, interactive}
74 type=
75 # One of {"$GIT_DIR"/rebase-apply, "$GIT_DIR"/rebase-merge}
76 state_dir=
3426232 rebase: act on command line outside parsing loop
Martin von Zweigbergk authored
77 # One of {'', continue, skip, abort}, as parsed from command line
78 action=
cf432ca rebase: factor out command line option processing
Martin von Zweigbergk authored
79 preserve_merges=
80 autosquash=
90e1818 git-rebase: add keep_empty flag
Neil Horman authored
81 keep_empty=
cf432ca rebase: factor out command line option processing
Martin von Zweigbergk authored
82 test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
58634db rebase: Allow merge strategies to be used when rebasing
Eric Wong authored
83
fa99c1e rebase: extract merge code to new source file
Martin von Zweigbergk authored
84 read_basic_state () {
02ac45f rebase: refactor reading of state
Martin von Zweigbergk authored
85 head_name=$(cat "$state_dir"/head-name) &&
86 onto=$(cat "$state_dir"/onto) &&
84df456 rebase: extract code for writing basic state
Martin von Zweigbergk authored
87 # We always write to orig-head, but interactive rebase used to write to
88 # head. Fall back to reading from head to cover for the case that the
89 # user upgraded git with an ongoing interactive rebase.
90 if test -f "$state_dir"/orig-head
2959c28 rebase: factor out sub command handling
Martin von Zweigbergk authored
91 then
92 orig_head=$(cat "$state_dir"/orig-head)
84df456 rebase: extract code for writing basic state
Martin von Zweigbergk authored
93 else
94 orig_head=$(cat "$state_dir"/head)
2959c28 rebase: factor out sub command handling
Martin von Zweigbergk authored
95 fi &&
7b37a7c rebase: remember verbose option
Martin von Zweigbergk authored
96 GIT_QUIET=$(cat "$state_dir"/quiet) &&
97 test -f "$state_dir"/verbose && verbose=t
80ff479 rebase: remember strategy and strategy options
Martin von Zweigbergk authored
98 test -f "$state_dir"/strategy && strategy="$(cat "$state_dir"/strategy)"
99 test -f "$state_dir"/strategy_opts &&
100 strategy_opts="$(cat "$state_dir"/strategy_opts)"
b3e4847 rebase -m: remember allow_rerere_autoupdate option
Martin von Zweigbergk authored
101 test -f "$state_dir"/allow_rerere_autoupdate &&
102 allow_rerere_autoupdate="$(cat "$state_dir"/allow_rerere_autoupdate)"
02ac45f rebase: refactor reading of state
Martin von Zweigbergk authored
103 }
104
84df456 rebase: extract code for writing basic state
Martin von Zweigbergk authored
105 write_basic_state () {
106 echo "$head_name" > "$state_dir"/head-name &&
107 echo "$onto" > "$state_dir"/onto &&
108 echo "$orig_head" > "$state_dir"/orig-head &&
7b37a7c rebase: remember verbose option
Martin von Zweigbergk authored
109 echo "$GIT_QUIET" > "$state_dir"/quiet &&
110 test t = "$verbose" && : > "$state_dir"/verbose
80ff479 rebase: remember strategy and strategy options
Martin von Zweigbergk authored
111 test -n "$strategy" && echo "$strategy" > "$state_dir"/strategy
112 test -n "$strategy_opts" && echo "$strategy_opts" > \
113 "$state_dir"/strategy_opts
b3e4847 rebase -m: remember allow_rerere_autoupdate option
Martin von Zweigbergk authored
114 test -n "$allow_rerere_autoupdate" && echo "$allow_rerere_autoupdate" > \
115 "$state_dir"/allow_rerere_autoupdate
84df456 rebase: extract code for writing basic state
Martin von Zweigbergk authored
116 }
117
4974c2c rebase: make -v a tiny bit more verbose
Martin von Zweigbergk authored
118 output () {
119 case "$verbose" in
120 '')
121 output=$("$@" 2>&1 )
122 status=$?
123 test $status != 0 && printf "%s\n" "$output"
124 return $status
125 ;;
126 *)
127 "$@"
128 ;;
129 esac
130 }
131
6fd2f5e @dscho rebase: operate on a detached HEAD
dscho authored
132 move_to_original_branch () {
133 case "$head_name" in
134 refs/*)
135 message="rebase finished: $head_name onto $onto"
136 git update-ref -m "$message" \
137 $head_name $(git rev-parse HEAD) $orig_head &&
53f2ffa @peff rebase: write a reflog entry when finishing
peff authored
138 git symbolic-ref \
139 -m "rebase finished: returning to $head_name" \
140 HEAD $head_name ||
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
141 die "$(gettext "Could not move back to $head_name")"
6fd2f5e @dscho rebase: operate on a detached HEAD
dscho authored
142 ;;
143 esac
144 }
145
fa99c1e rebase: extract merge code to new source file
Martin von Zweigbergk authored
146 run_specific_rebase () {
f8cca01 @ageric rebase: Support preserving merges in non-interactive mode
ageric authored
147 if [ "$interactive_rebase" = implied ]; then
148 GIT_EDITOR=:
149 export GIT_EDITOR
8a6dae1 @vfr-nl Do not autosquash in case of an implied interactive rebase
vfr-nl authored
150 autosquash=
f8cca01 @ageric rebase: Support preserving merges in non-interactive mode
ageric authored
151 fi
46df82d rebase: extract am code to new source file
Martin von Zweigbergk authored
152 . git-rebase--$type
1b1dce4 @dscho Teach rebase an interactive mode
dscho authored
153 }
154
d70b4a8 Teach rebase -i to honor pre-rebase hook
Nanako Shiraishi authored
155 run_pre_rebase_hook () {
6bb4e48 rebase: align variable names
Martin von Zweigbergk authored
156 if test -z "$ok_to_skip_pre_rebase" &&
c442765 rebase --no-verify
Nanako Shiraishi authored
157 test -x "$GIT_DIR/hooks/pre-rebase"
d70b4a8 Teach rebase -i to honor pre-rebase hook
Nanako Shiraishi authored
158 then
bc2bbc4 @bebarino pull, rebase: simplify to use die()
bebarino authored
159 "$GIT_DIR/hooks/pre-rebase" ${1+"$@"} ||
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
160 die "$(gettext "The pre-rebase hook refused to rebase.")"
d70b4a8 Teach rebase -i to honor pre-rebase hook
Nanako Shiraishi authored
161 fi
162 }
163
69a636a rebase: clearer names for directory variables
Martin von Zweigbergk authored
164 test -f "$apply_dir"/applying &&
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
165 die "$(gettext "It looks like git-am is in progress. Cannot rebase.")"
9b752a6 @sbeyer Improve error output of git-rebase
sbeyer authored
166
99de064 rebase: improve detection of rebase in progress
Martin von Zweigbergk authored
167 if test -d "$apply_dir"
168 then
169 type=am
170 state_dir="$apply_dir"
171 elif test -d "$merge_dir"
172 then
173 if test -f "$merge_dir"/interactive
174 then
175 type=interactive
176 interactive_rebase=explicit
177 else
178 type=merge
179 fi
180 state_dir="$merge_dir"
181 fi
182 test -n "$type" && in_progress=t
183
95135b0 rebase: stricter check of standalone sub command
Martin von Zweigbergk authored
184 total_argc=$#
822f7c7 Supplant the "while case ... break ;; esac" idiom
David Kastrup authored
185 while test $# != 0
e646c9c rebase: allow rebasing onto different base.
Junio C Hamano authored
186 do
187 case "$1" in
c442765 rebase --no-verify
Nanako Shiraishi authored
188 --no-verify)
6bb4e48 rebase: align variable names
Martin von Zweigbergk authored
189 ok_to_skip_pre_rebase=yes
c442765 rebase --no-verify
Nanako Shiraishi authored
190 ;;
7baf9c4 rebase: support --verify
Martin von Zweigbergk authored
191 --verify)
6bb4e48 rebase: align variable names
Martin von Zweigbergk authored
192 ok_to_skip_pre_rebase=
7baf9c4 rebase: support --verify
Martin von Zweigbergk authored
193 ;;
eb9a7cb @andrewkww rebase -i: Teach "--edit-todo" action
andrewkww authored
194 --continue|--skip|--abort|--edit-todo)
45e2acf rebase: define options in OPTIONS_SPEC
Martin von Zweigbergk authored
195 test $total_argc -eq 2 || usage
3426232 rebase: act on command line outside parsing loop
Martin von Zweigbergk authored
196 action=${1##--}
031321c @loops Add --continue and --abort options to git-rebase.
loops authored
197 ;;
e646c9c rebase: allow rebasing onto different base.
Junio C Hamano authored
198 --onto)
199 test 2 -le "$#" || usage
6bb4e48 rebase: align variable names
Martin von Zweigbergk authored
200 onto="$2"
e646c9c rebase: allow rebasing onto different base.
Junio C Hamano authored
201 shift
202 ;;
c214538 rebase -i: teach "--exec <cmd>"
Lucien Kong authored
203 -x)
204 test 2 -le "$#" || usage
205 cmd="${cmd}exec $2${LF}"
206 shift
207 ;;
45e2acf rebase: define options in OPTIONS_SPEC
Martin von Zweigbergk authored
208 -i)
cf432ca rebase: factor out command line option processing
Martin von Zweigbergk authored
209 interactive_rebase=explicit
210 ;;
90e1818 git-rebase: add keep_empty flag
Neil Horman authored
211 -k)
212 keep_empty=yes
213 ;;
45e2acf rebase: define options in OPTIONS_SPEC
Martin von Zweigbergk authored
214 -p)
cf432ca rebase: factor out command line option processing
Martin von Zweigbergk authored
215 preserve_merges=t
216 test -z "$interactive_rebase" && interactive_rebase=implied
217 ;;
218 --autosquash)
219 autosquash=t
220 ;;
221 --no-autosquash)
222 autosquash=
223 ;;
45e2acf rebase: define options in OPTIONS_SPEC
Martin von Zweigbergk authored
224 -M|-m)
58634db rebase: Allow merge strategies to be used when rebasing
Eric Wong authored
225 do_merge=t
226 ;;
45e2acf rebase: define options in OPTIONS_SPEC
Martin von Zweigbergk authored
227 -X)
228 shift
229 strategy_opts="$strategy_opts $(git rev-parse --sq-quote "--$1")"
93ce190 @novas0x2a rebase: support -X to pass through strategy options
novas0x2a authored
230 do_merge=t
9765b6a rebase: align variable content
Martin von Zweigbergk authored
231 test -z "$strategy" && strategy=recursive
93ce190 @novas0x2a rebase: support -X to pass through strategy options
novas0x2a authored
232 ;;
45e2acf rebase: define options in OPTIONS_SPEC
Martin von Zweigbergk authored
233 -s)
234 shift
235 strategy="$1"
58634db rebase: Allow merge strategies to be used when rebasing
Eric Wong authored
236 do_merge=t
237 ;;
45e2acf rebase: define options in OPTIONS_SPEC
Martin von Zweigbergk authored
238 -n)
a9c3821 @torarnv git-rebase: Add --stat and --no-stat for producing diffstat on rebase
torarnv authored
239 diffstat=
240 ;;
241 --stat)
242 diffstat=t
243 ;;
45e2acf rebase: define options in OPTIONS_SPEC
Martin von Zweigbergk authored
244 -v)
b758789 git-rebase: Add a -v option to show a diffstat of the changes upstrea…
Robert Shearman authored
245 verbose=t
a9c3821 @torarnv git-rebase: Add --stat and --no-stat for producing diffstat on rebase
torarnv authored
246 diffstat=t
0e987a1 @bebarino am, rebase: teach quiet option
bebarino authored
247 GIT_QUIET=
248 ;;
45e2acf rebase: define options in OPTIONS_SPEC
Martin von Zweigbergk authored
249 -q)
0e987a1 @bebarino am, rebase: teach quiet option
bebarino authored
250 GIT_QUIET=t
251 git_am_opt="$git_am_opt -q"
252 verbose=
253 diffstat=
b758789 git-rebase: Add a -v option to show a diffstat of the changes upstrea…
Robert Shearman authored
254 ;;
45e2acf rebase: define options in OPTIONS_SPEC
Martin von Zweigbergk authored
255 --whitespace)
256 shift
257 git_am_opt="$git_am_opt --whitespace=$1"
b2f82e0 @SRabbelier Teach rebase to rebase even if upstream is up to date
SRabbelier authored
258 case "$1" in
45e2acf rebase: define options in OPTIONS_SPEC
Martin von Zweigbergk authored
259 fix|strip)
b2f82e0 @SRabbelier Teach rebase to rebase even if upstream is up to date
SRabbelier authored
260 force_rebase=t
261 ;;
262 esac
059f446 git-rebase: support --whitespace=<option>
J. Bruce Fields authored
263 ;;
86c91f9 @Oblomov git apply: option to ignore whitespace differences
Oblomov authored
264 --ignore-whitespace)
265 git_am_opt="$git_am_opt $1"
266 ;;
570ccad @chunga rebase: add options passed to git-am
chunga authored
267 --committer-date-is-author-date|--ignore-date)
268 git_am_opt="$git_am_opt $1"
269 force_rebase=t
270 ;;
45e2acf rebase: define options in OPTIONS_SPEC
Martin von Zweigbergk authored
271 -C)
272 shift
273 git_am_opt="$git_am_opt -C$1"
67dad68 add -C[NUM] to git-am
Michael S. Tsirkin authored
274 ;;
190f532 @trast rebase: learn to rebase root commit
trast authored
275 --root)
276 rebase_root=t
277 ;;
45e2acf rebase: define options in OPTIONS_SPEC
Martin von Zweigbergk authored
278 -f|--no-ff)
b2f82e0 @SRabbelier Teach rebase to rebase even if upstream is up to date
SRabbelier authored
279 force_rebase=t
280 ;;
cb6020b @gitster Teach --[no-]rerere-autoupdate option to merge, revert and friends
authored
281 --rerere-autoupdate|--no-rerere-autoupdate)
282 allow_rerere_autoupdate="$1"
283 ;;
45e2acf rebase: define options in OPTIONS_SPEC
Martin von Zweigbergk authored
284 --)
285 shift
e646c9c rebase: allow rebasing onto different base.
Junio C Hamano authored
286 break
287 ;;
288 esac
289 shift
290 done
51b2ead @jaysoffian disallow providing multiple upstream branches to rebase, pull --rebase
jaysoffian authored
291 test $# -gt 2 && usage
2db8aae rebase: do not get confused in fast-forward situation.
Junio C Hamano authored
292
c214538 rebase -i: teach "--exec <cmd>"
Lucien Kong authored
293 if test -n "$cmd" &&
294 test "$interactive_rebase" != explicit
295 then
465d6a0 @jiangxin i18n: Rewrite gettext messages start with dash
jiangxin authored
296 die "$(gettext "The --exec option must be used with the --interactive option")"
c214538 rebase -i: teach "--exec <cmd>"
Lucien Kong authored
297 fi
298
cf432ca rebase: factor out command line option processing
Martin von Zweigbergk authored
299 if test -n "$action"
300 then
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
301 test -z "$in_progress" && die "$(gettext "No rebase in progress?")"
2959c28 rebase: factor out sub command handling
Martin von Zweigbergk authored
302 # Only interactive rebase uses detailed reflog messages
303 if test "$type" = interactive && test "$GIT_REFLOG_ACTION" = rebase
304 then
305 GIT_REFLOG_ACTION="rebase -i ($action)"
306 export GIT_REFLOG_ACTION
307 fi
cf432ca rebase: factor out command line option processing
Martin von Zweigbergk authored
308 fi
3426232 rebase: act on command line outside parsing loop
Martin von Zweigbergk authored
309
eb9a7cb @andrewkww rebase -i: Teach "--edit-todo" action
andrewkww authored
310 if test "$action" = "edit-todo" && test "$type" != "interactive"
311 then
312 die "$(gettext "The --edit-todo action can only be used during interactive rebase.")"
313 fi
314
3426232 rebase: act on command line outside parsing loop
Martin von Zweigbergk authored
315 case "$action" in
316 continue)
2959c28 rebase: factor out sub command handling
Martin von Zweigbergk authored
317 # Sanity check
318 git rev-parse --verify HEAD >/dev/null ||
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
319 die "$(gettext "Cannot read HEAD")"
3426232 rebase: act on command line outside parsing loop
Martin von Zweigbergk authored
320 git update-index --ignore-submodules --refresh &&
321 git diff-files --quiet --ignore-submodules || {
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
322 echo "$(gettext "You must edit all merge conflicts and then
323 mark them as resolved using git add")"
3426232 rebase: act on command line outside parsing loop
Martin von Zweigbergk authored
324 exit 1
325 }
fa99c1e rebase: extract merge code to new source file
Martin von Zweigbergk authored
326 read_basic_state
327 run_specific_rebase
3426232 rebase: act on command line outside parsing loop
Martin von Zweigbergk authored
328 ;;
329 skip)
4974c2c rebase: make -v a tiny bit more verbose
Martin von Zweigbergk authored
330 output git reset --hard HEAD || exit $?
fa99c1e rebase: extract merge code to new source file
Martin von Zweigbergk authored
331 read_basic_state
332 run_specific_rebase
3426232 rebase: act on command line outside parsing loop
Martin von Zweigbergk authored
333 ;;
334 abort)
335 git rerere clear
fa99c1e rebase: extract merge code to new source file
Martin von Zweigbergk authored
336 read_basic_state
3426232 rebase: act on command line outside parsing loop
Martin von Zweigbergk authored
337 case "$head_name" in
338 refs/*)
ea69619 @csabahenk rebase: create HEAD reflog entry when aborting
csabahenk authored
339 git symbolic-ref -m "rebase: aborting" HEAD $head_name ||
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
340 die "$(eval_gettext "Could not move back to \$head_name")"
3426232 rebase: act on command line outside parsing loop
Martin von Zweigbergk authored
341 ;;
342 esac
4974c2c rebase: make -v a tiny bit more verbose
Martin von Zweigbergk authored
343 output git reset --hard $orig_head
3426232 rebase: act on command line outside parsing loop
Martin von Zweigbergk authored
344 rm -r "$state_dir"
345 exit
346 ;;
eb9a7cb @andrewkww rebase -i: Teach "--edit-todo" action
andrewkww authored
347 edit-todo)
348 run_specific_rebase
349 ;;
3426232 rebase: act on command line outside parsing loop
Martin von Zweigbergk authored
350 esac
351
99de064 rebase: improve detection of rebase in progress
Martin von Zweigbergk authored
352 # Make sure no rebase is in progress
353 if test -n "$in_progress"
7f4bd5d rebase: one safety net, one bugfix and one optimization.
Junio C Hamano authored
354 then
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
355 state_dir_base=${state_dir##*/}
356 cmd_live_rebase="git rebase (--continue | --abort | --skip)"
357 cmd_clear_stale_rebase="rm -fr \"$state_dir\""
358 die "
359 $(eval_gettext 'It seems that there is already a $state_dir_base directory, and
e39beac @ralfth git-rebase.sh: fix typo in an error message
ralfth authored
360 I wonder if you are in the middle of another rebase. If that is the
99de064 rebase: improve detection of rebase in progress
Martin von Zweigbergk authored
361 case, please try
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
362 $cmd_live_rebase
99de064 rebase: improve detection of rebase in progress
Martin von Zweigbergk authored
363 If that is not the case, please
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
364 $cmd_clear_stale_rebase
9b752a6 @sbeyer Improve error output of git-rebase
sbeyer authored
365 and run me again. I am stopping in case you still have something
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
366 valuable there.')"
7f4bd5d rebase: one safety net, one bugfix and one optimization.
Junio C Hamano authored
367 fi
368
df5df20 @arachsys rebase -i: support --root without --onto
arachsys authored
369 if test -n "$rebase_root" && test -z "$onto"
370 then
371 test -z "$interactive_rebase" && interactive_rebase=implied
372 fi
373
cf432ca rebase: factor out command line option processing
Martin von Zweigbergk authored
374 if test -n "$interactive_rebase"
375 then
376 type=interactive
377 state_dir="$merge_dir"
378 elif test -n "$do_merge"
379 then
380 type=merge
381 state_dir="$merge_dir"
382 else
383 type=am
384 state_dir="$apply_dir"
385 fi
386
190f532 @trast rebase: learn to rebase root commit
trast authored
387 if test -z "$rebase_root"
388 then
15a147e rebase: use @{upstream} if no upstream specified
Martin von Zweigbergk authored
389 case "$#" in
390 0)
391 if ! upstream_name=$(git rev-parse --symbolic-full-name \
392 --verify -q @{upstream} 2>/dev/null)
393 then
394 . git-parse-remote
395 error_on_missing_default_upstream "rebase" "rebase" \
3c02396 @carlosmn Make git-{pull,rebase} message without tracking information friendlier
carlosmn authored
396 "against" "git rebase <branch>"
15a147e rebase: use @{upstream} if no upstream specified
Martin von Zweigbergk authored
397 fi
398 ;;
399 *) upstream_name="$1"
400 shift
401 ;;
402 esac
190f532 @trast rebase: learn to rebase root commit
trast authored
403 upstream=`git rev-parse --verify "${upstream_name}^0"` ||
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
404 die "$(eval_gettext "invalid upstream \$upstream_name")"
190f532 @trast rebase: learn to rebase root commit
trast authored
405 upstream_arg="$upstream_name"
406 else
df5df20 @arachsys rebase -i: support --root without --onto
arachsys authored
407 if test -z "$onto"
408 then
409 empty_tree=`git hash-object -t tree /dev/null`
410 onto=`git commit-tree $empty_tree </dev/null`
411 squash_onto="$onto"
412 fi
190f532 @trast rebase: learn to rebase root commit
trast authored
413 unset upstream_name
414 unset upstream
f2b6a19 rebase --root: print usage on too many args
Martin von Zweigbergk authored
415 test $# -gt 1 && usage
46df82d rebase: extract am code to new source file
Martin von Zweigbergk authored
416 upstream_arg=--root
190f532 @trast rebase: learn to rebase root commit
trast authored
417 fi
32d9954 Bugfixes for git-rebase
Lukas Sandström authored
418
a1bf91e git-rebase: make 'rebase HEAD branch' work as expected.
Junio C Hamano authored
419 # Make sure the branch to rebase onto is valid.
6bb4e48 rebase: align variable names
Martin von Zweigbergk authored
420 onto_name=${onto-"$upstream_name"}
9f21e97 rebase: fix --onto A...B parsing and add tests
Nanako Shiraishi authored
421 case "$onto_name" in
422 *...*)
423 if left=${onto_name%...*} right=${onto_name#*...} &&
424 onto=$(git merge-base --all ${left:-HEAD} ${right:-HEAD})
425 then
426 case "$onto" in
427 ?*"$LF"?*)
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
428 die "$(eval_gettext "\$onto_name: there are more than one merge bases")"
9f21e97 rebase: fix --onto A...B parsing and add tests
Nanako Shiraishi authored
429 ;;
430 '')
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
431 die "$(eval_gettext "\$onto_name: there is no merge base")"
9f21e97 rebase: fix --onto A...B parsing and add tests
Nanako Shiraishi authored
432 ;;
433 esac
434 else
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
435 die "$(eval_gettext "\$onto_name: there is no merge base")"
9f21e97 rebase: fix --onto A...B parsing and add tests
Nanako Shiraishi authored
436 fi
437 ;;
438 *)
71786f5 rebase: factor out reference parsing
Martin von Zweigbergk authored
439 onto=$(git rev-parse --verify "${onto_name}^0") ||
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
440 die "$(eval_gettext "Does not point to a valid commit: \$onto_name")"
9f21e97 rebase: fix --onto A...B parsing and add tests
Nanako Shiraishi authored
441 ;;
442 esac
a1bf91e git-rebase: make 'rebase HEAD branch' work as expected.
Junio C Hamano authored
443
0cb0664 @gitster rebase [--onto O] A B: omit needless checkout
authored
444 # If the branch to rebase is given, that is the branch we will rebase
445 # $branch_name -- branch being rebased, or HEAD (already detached)
446 # $orig_head -- commit object name of tip of the branch before rebasing
447 # $head_name -- refs/heads/<that-branch> or "detached HEAD"
448 switch_to=
59e6b23 [PATCH] git-rebase-script: rebase local commits to new upstream head.
Junio C Hamano authored
449 case "$#" in
190f532 @trast rebase: learn to rebase root commit
trast authored
450 1)
0cb0664 @gitster rebase [--onto O] A B: omit needless checkout
authored
451 # Is it "rebase other $branchname" or "rebase other $commit"?
190f532 @trast rebase: learn to rebase root commit
trast authored
452 branch_name="$1"
453 switch_to="$1"
0cb0664 @gitster rebase [--onto O] A B: omit needless checkout
authored
454
190f532 @trast rebase: learn to rebase root commit
trast authored
455 if git show-ref --verify --quiet -- "refs/heads/$1" &&
cb82a05 rebase: remove $branch as synonym for $orig_head
Martin von Zweigbergk authored
456 orig_head=$(git rev-parse -q --verify "refs/heads/$1")
0cb0664 @gitster rebase [--onto O] A B: omit needless checkout
authored
457 then
190f532 @trast rebase: learn to rebase root commit
trast authored
458 head_name="refs/heads/$1"
cb82a05 rebase: remove $branch as synonym for $orig_head
Martin von Zweigbergk authored
459 elif orig_head=$(git rev-parse -q --verify "$1")
0cb0664 @gitster rebase [--onto O] A B: omit needless checkout
authored
460 then
461 head_name="detached HEAD"
462 else
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
463 die "$(eval_gettext "fatal: no such branch: \$branch_name")"
0cb0664 @gitster rebase [--onto O] A B: omit needless checkout
authored
464 fi
e646c9c rebase: allow rebasing onto different base.
Junio C Hamano authored
465 ;;
f2b6a19 rebase --root: print usage on too many args
Martin von Zweigbergk authored
466 0)
0cb0664 @gitster rebase [--onto O] A B: omit needless checkout
authored
467 # Do not need to switch branches, we are already on it.
bcf3161 git-rebase: allow rebasing a detached HEAD.
Junio C Hamano authored
468 if branch_name=`git symbolic-ref -q HEAD`
469 then
0cb0664 @gitster rebase [--onto O] A B: omit needless checkout
authored
470 head_name=$branch_name
bcf3161 git-rebase: allow rebasing a detached HEAD.
Junio C Hamano authored
471 branch_name=`expr "z$branch_name" : 'zrefs/heads/\(.*\)'`
472 else
0cb0664 @gitster rebase [--onto O] A B: omit needless checkout
authored
473 head_name="detached HEAD"
bcf3161 git-rebase: allow rebasing a detached HEAD.
Junio C Hamano authored
474 branch_name=HEAD ;# detached
475 fi
cb82a05 rebase: remove $branch as synonym for $orig_head
Martin von Zweigbergk authored
476 orig_head=$(git rev-parse --verify "${branch_name}^0") || exit
e646c9c rebase: allow rebasing onto different base.
Junio C Hamano authored
477 ;;
f2b6a19 rebase --root: print usage on too many args
Martin von Zweigbergk authored
478 *)
479 die "BUG: unexpected number of arguments left to parse"
480 ;;
59e6b23 [PATCH] git-rebase-script: rebase local commits to new upstream head.
Junio C Hamano authored
481 esac
482
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
483 require_clean_work_tree "rebase" "$(gettext "Please commit or stash them.")"
8f9bfb6 rebase: reorder validation steps
Martin von Zweigbergk authored
484
cb82a05 rebase: remove $branch as synonym for $orig_head
Martin von Zweigbergk authored
485 # Now we are rebasing commits $upstream..$orig_head (or with --root,
486 # everything leading up to $orig_head) on top of $onto
e646c9c rebase: allow rebasing onto different base.
Junio C Hamano authored
487
1308c17 Allow rebase to run if upstream is completely merged
Johannes Sixt authored
488 # Check if we are already based on $onto with linear history,
cc1453e rebase: factor out call to pre-rebase hook
Martin von Zweigbergk authored
489 # but this should be done only when upstream and onto are the same
490 # and if this is not an interactive rebase.
cb82a05 rebase: remove $branch as synonym for $orig_head
Martin von Zweigbergk authored
491 mb=$(git merge-base "$onto" "$orig_head")
cc1453e rebase: factor out call to pre-rebase hook
Martin von Zweigbergk authored
492 if test "$type" != interactive && test "$upstream" = "$onto" &&
493 test "$mb" = "$onto" &&
1308c17 Allow rebase to run if upstream is completely merged
Johannes Sixt authored
494 # linear history?
cb82a05 rebase: remove $branch as synonym for $orig_head
Martin von Zweigbergk authored
495 ! (git rev-list --parents "$onto".."$orig_head" | sane_grep " .* ") > /dev/null
7f4bd5d rebase: one safety net, one bugfix and one optimization.
Junio C Hamano authored
496 then
b2f82e0 @SRabbelier Teach rebase to rebase even if upstream is up to date
SRabbelier authored
497 if test -z "$force_rebase"
498 then
499 # Lazily switch to the target branch if needed...
3b21a43 @peff rebase: use explicit "--" with checkout
peff authored
500 test -z "$switch_to" || git checkout "$switch_to" --
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
501 say "$(eval_gettext "Current branch \$branch_name is up to date.")"
b2f82e0 @SRabbelier Teach rebase to rebase even if upstream is up to date
SRabbelier authored
502 exit 0
503 else
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
504 say "$(eval_gettext "Current branch \$branch_name is up to date, rebase forced.")"
b2f82e0 @SRabbelier Teach rebase to rebase even if upstream is up to date
SRabbelier authored
505 fi
7f4bd5d rebase: one safety net, one bugfix and one optimization.
Junio C Hamano authored
506 fi
507
8f9bfb6 rebase: reorder validation steps
Martin von Zweigbergk authored
508 # If a hook exists, give it a chance to interrupt
509 run_pre_rebase_hook "$upstream_arg" "$@"
510
a9c3821 @torarnv git-rebase: Add --stat and --no-stat for producing diffstat on rebase
torarnv authored
511 if test -n "$diffstat"
512 then
513 if test -n "$verbose"
514 then
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
515 echo "$(eval_gettext "Changes from \$mb to \$onto:")"
a9c3821 @torarnv git-rebase: Add --stat and --no-stat for producing diffstat on rebase
torarnv authored
516 fi
517 # We want color (if set), but no pager
518 GIT_PAGER='' git diff --stat --summary "$mb" "$onto"
519 fi
520
fa99c1e rebase: extract merge code to new source file
Martin von Zweigbergk authored
521 test "$type" = interactive && run_specific_rebase
f4107d9 rebase -i: support --stat
Martin von Zweigbergk authored
522
523 # Detach HEAD and reset the tree
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
524 say "$(gettext "First, rewinding head to replay your work on top of it...")"
f4107d9 rebase -i: support --stat
Martin von Zweigbergk authored
525 git checkout -q "$onto^0" || die "could not detach HEAD"
cb82a05 rebase: remove $branch as synonym for $orig_head
Martin von Zweigbergk authored
526 git update-ref ORIG_HEAD $orig_head
f4107d9 rebase -i: support --stat
Martin von Zweigbergk authored
527
e646c9c rebase: allow rebasing onto different base.
Junio C Hamano authored
528 # If the $onto is a proper descendant of the tip of the branch, then
a75d7b5 @felipec Use 'fast-forward' all over the place
felipec authored
529 # we just fast-forwarded.
cb82a05 rebase: remove $branch as synonym for $orig_head
Martin von Zweigbergk authored
530 if test "$mb" = "$orig_head"
32d9954 Bugfixes for git-rebase
Lukas Sandström authored
531 then
c7108bf @jiangxin i18n: rebase: mark messages for translation
jiangxin authored
532 say "$(eval_gettext "Fast-forwarded \$branch_name to \$onto_name.")"
6fd2f5e @dscho rebase: operate on a detached HEAD
dscho authored
533 move_to_original_branch
32d9954 Bugfixes for git-rebase
Lukas Sandström authored
534 exit 0
535 fi
536
190f532 @trast rebase: learn to rebase root commit
trast authored
537 if test -n "$rebase_root"
538 then
539 revisions="$onto..$orig_head"
540 else
541 revisions="$upstream..$orig_head"
542 fi
543
fa99c1e rebase: extract merge code to new source file
Martin von Zweigbergk authored
544 run_specific_rebase
Something went wrong with that request. Please try again.