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.
5 # Copyright (c) 2006 Johannes E. Schindelin
7 # The original idea comes from Eric W. Biederman, in
8 # https://public-inbox.org/git/m1odwkyuf5.fsf_-_@ebiederm.dsl.xmission.com/
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
13 # file and written to the tail of $done.
14 todo
="$state_dir"/git-rebase-todo
16 GIT_CHERRY_PICK_HELP
="$resolvemsg"
17 export GIT_CHERRY_PICK_HELP
19 comment_char
=$
(git config
--get core.commentchar
2>/dev
/null
)
20 case "$comment_char" in
27 comment_char
=$
(echo "$comment_char" | cut
-c1)
31 orig_reflog_action
="$GIT_REFLOG_ACTION"
33 comment_for_reflog
() {
34 case "$orig_reflog_action" in
36 GIT_REFLOG_ACTION
="rebase -i ($1)"
37 export GIT_REFLOG_ACTION
45 p, pick <commit> = use commit
46 r, reword <commit> = use commit, but edit the commit message
47 e, edit <commit> = use commit, but stop for amending
48 s, squash <commit> = use commit, but meld into previous commit
49 f, fixup <commit> = like \"squash\", but discard this commit's log message
50 x, exec <command> = run command (the rest of the line) using shell
51 d, drop <commit> = remove commit
52 l, label <label> = label current HEAD with a name
53 t, reset <label> = reset HEAD to a label
54 m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
55 . create a merge commit using the original merge commit's
56 . message (or the oneline, if no original merge commit was
57 . specified). Use -c <commit> to reword the commit message.
59 These lines can be re-ordered; they are executed from top to bottom.
60 " | git stripspace
--comment-lines >>"$todo"
62 if test $
(get_missing_commit_check_level
) = error
65 Do not remove any line. Use 'drop' explicitly to remove a commit.
66 " | git stripspace
--comment-lines >>"$todo"
69 If you remove a line here THAT COMMIT WILL BE LOST.
70 " | git stripspace
--comment-lines >>"$todo"
81 test -n "$(git stripspace --strip-comments <"$1")"
84 git_sequence_editor
() {
85 if test -z "$GIT_SEQUENCE_EDITOR"
87 GIT_SEQUENCE_EDITOR
="$(git config sequence.editor)"
88 if [ -z "$GIT_SEQUENCE_EDITOR" ]
90 GIT_SEQUENCE_EDITOR
="$(git var GIT_EDITOR)" ||
return $?
94 eval "$GIT_SEQUENCE_EDITOR" '"$@"'
98 git rebase--helper
--expand-ids
101 collapse_todo_ids
() {
102 git rebase--helper
--shorten-ids
105 # Switch to the branch in $into and notify it in the reflog
107 GIT_REFLOG_ACTION
="$GIT_REFLOG_ACTION: checkout $onto_name"
108 output git checkout
$onto || die_abort
"$(gettext "could not detach HEAD
")"
109 git update-ref ORIG_HEAD
$orig_head
112 get_missing_commit_check_level
() {
113 check_level
=$
(git config
--get rebase.missingCommitsCheck
)
114 check_level
=${check_level:-ignore}
115 # Don't be case sensitive
116 printf '%s' "$check_level" |
tr 'A-Z' 'a-z'
119 # Initiate an action. If the cannot be any
120 # further action it may exec a command
121 # or exit and not return.
123 # TODO: Consider a cleaner return model so it
124 # never exits and always return 0 if process
127 # Parameter 1 is the action to initiate.
129 # Returns 0 if the action was able to complete
130 # and if 1 if further processing is required.
134 exec git rebase--helper
${force_rebase:+--no-ff} $allow_empty_message \
139 exec git rebase--helper
${force_rebase:+--no-ff} $allow_empty_message \
143 git stripspace
--strip-comments <"$todo" >"$todo".new
144 mv -f "$todo".new
"$todo"
148 You are editing the todo file of an ongoing interactive rebase.
149 To continue rebase after editing, run:
150 git rebase --continue
152 " | git stripspace
--comment-lines >>"$todo"
154 git_sequence_editor
"$todo" ||
155 die
"$(gettext "Could not execute editor
")"
161 exec git show REBASE_HEAD
--
169 setup_reflog_action
() {
170 comment_for_reflog start
172 if test ! -z "$switch_to"
174 GIT_REFLOG_ACTION
="$GIT_REFLOG_ACTION: checkout $switch_to"
175 output git checkout
"$switch_to" -- ||
176 die
"$(eval_gettext "Could not checkout \
$switch_to")"
178 comment_for_reflog start
182 init_basic_state
() {
183 orig_head
=$
(git rev-parse
--verify HEAD
) || die
"$(gettext "No HEAD?
")"
184 mkdir
-p "$state_dir" || die
"$(eval_gettext "Could not create temporary \
$state_dir")"
185 rm -f "$(git rev-parse --git-path REBASE_HEAD)"
187 : > "$state_dir"/interactive || die
"$(gettext "Could not mark as interactive
")"
191 init_revisions_and_shortrevisions
() {
192 shorthead
=$
(git rev-parse
--short $orig_head)
193 shortonto
=$
(git rev-parse
--short $onto)
194 if test -z "$rebase_root"
195 # this is now equivalent to ! -z "$upstream"
197 shortupstream
=$
(git rev-parse
--short $upstream)
198 revisions
=$upstream...
$orig_head
199 shortrevisions
=$shortupstream..
$shorthead
201 revisions
=$onto...
$orig_head
202 shortrevisions
=$shorthead
203 test -z "$squash_onto" ||
204 echo "$squash_onto" >"$state_dir"/squash-onto
209 test -s "$todo" ||
echo noop
>> "$todo"
210 test -z "$autosquash" || git rebase--helper
--rearrange-squash ||
exit
211 test -n "$cmd" && git rebase--helper
--add-exec-commands "$cmd"
213 todocount
=$
(git stripspace
--strip-comments <"$todo" |
wc -l)
214 todocount
=${todocount##* }
218 $comment_char $(eval_ngettext \
219 "Rebase \$shortrevisions onto \$shortonto (\$todocount command)" \
220 "Rebase \$shortrevisions onto \$shortonto (\$todocount commands)" \
225 However, if you remove everything, the rebase will be aborted.
227 " | git stripspace
--comment-lines >>"$todo"
229 if test -z "$keep_empty"
231 printf '%s\n' "$comment_char $(gettext "Note that empty commits are commented out
")" >>"$todo"
235 has_action
"$todo" ||
238 cp "$todo" "$todo".backup
240 git_sequence_editor
"$todo" ||
241 die_abort
"$(gettext "Could not execute editor
")"
243 has_action
"$todo" ||
246 git rebase--helper
--check-todo-list ||
{
254 test -n "$force_rebase" ||
255 onto
="$(git rebase--helper --skip-unnecessary-picks)" ||
256 die
"Could not skip unnecessary pick commands"
259 require_clean_work_tree
"rebase"
260 exec git rebase--helper
${force_rebase:+--no-ff} $allow_empty_message \
264 git_rebase__interactive
() {
265 initiate_action
"$action"
267 if test $ret = 0; then
274 init_revisions_and_shortrevisions
276 git rebase--helper
--make-script ${keep_empty:+--keep-empty} \
277 ${rebase_merges:+--rebase-merges} \
278 ${rebase_cousins:+--rebase-cousins} \
279 $revisions ${restrict_revision+^$restrict_revision} >"$todo" ||
280 die
"$(gettext "Could not generate todo list
")"