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
49 test -n "$(git stripspace --strip-comments <"$1")"
52 git_sequence_editor
() {
53 if test -z "$GIT_SEQUENCE_EDITOR"
55 GIT_SEQUENCE_EDITOR
="$(git config sequence.editor)"
56 if [ -z "$GIT_SEQUENCE_EDITOR" ]
58 GIT_SEQUENCE_EDITOR
="$(git var GIT_EDITOR)" ||
return $?
62 eval "$GIT_SEQUENCE_EDITOR" '"$@"'
66 git rebase--helper
--expand-ids
70 git rebase--helper
--shorten-ids
73 # Switch to the branch in $into and notify it in the reflog
75 GIT_REFLOG_ACTION
="$GIT_REFLOG_ACTION: checkout $onto_name"
76 output git checkout
$onto || die_abort
"$(gettext "could not detach HEAD
")"
77 git update-ref ORIG_HEAD
$orig_head
80 get_missing_commit_check_level
() {
81 check_level
=$
(git config
--get rebase.missingCommitsCheck
)
82 check_level
=${check_level:-ignore}
83 # Don't be case sensitive
84 printf '%s' "$check_level" |
tr 'A-Z' 'a-z'
87 # Initiate an action. If the cannot be any
88 # further action it may exec a command
89 # or exit and not return.
91 # TODO: Consider a cleaner return model so it
92 # never exits and always return 0 if process
95 # Parameter 1 is the action to initiate.
97 # Returns 0 if the action was able to complete
98 # and if 1 if further processing is required.
102 exec git rebase--helper
${force_rebase:+--no-ff} $allow_empty_message \
107 exec git rebase--helper
${force_rebase:+--no-ff} $allow_empty_message \
111 exec git rebase--helper
--edit-todo
114 exec git show REBASE_HEAD
--
122 setup_reflog_action
() {
123 comment_for_reflog start
125 if test ! -z "$switch_to"
127 GIT_REFLOG_ACTION
="$GIT_REFLOG_ACTION: checkout $switch_to"
128 output git checkout
"$switch_to" -- ||
129 die
"$(eval_gettext "Could not checkout \
$switch_to")"
131 comment_for_reflog start
135 init_basic_state
() {
136 orig_head
=$
(git rev-parse
--verify HEAD
) || die
"$(gettext "No HEAD?
")"
137 mkdir
-p "$state_dir" || die
"$(eval_gettext "Could not create temporary \
$state_dir")"
138 rm -f "$(git rev-parse --git-path REBASE_HEAD)"
140 : > "$state_dir"/interactive || die
"$(gettext "Could not mark as interactive
")"
144 init_revisions_and_shortrevisions
() {
145 shorthead
=$
(git rev-parse
--short $orig_head)
146 shortonto
=$
(git rev-parse
--short $onto)
147 if test -z "$rebase_root"
148 # this is now equivalent to ! -z "$upstream"
150 shortupstream
=$
(git rev-parse
--short $upstream)
151 revisions
=$upstream...
$orig_head
152 shortrevisions
=$shortupstream..
$shorthead
154 revisions
=$onto...
$orig_head
155 shortrevisions
=$shorthead
156 test -z "$squash_onto" ||
157 echo "$squash_onto" >"$state_dir"/squash-onto
162 test -s "$todo" ||
echo noop
>> "$todo"
163 test -z "$autosquash" || git rebase--helper
--rearrange-squash ||
exit
164 test -n "$cmd" && git rebase--helper
--add-exec-commands "$cmd"
166 todocount
=$
(git stripspace
--strip-comments <"$todo" |
wc -l)
167 todocount
=${todocount##* }
171 $comment_char $(eval_ngettext \
172 "Rebase \$shortrevisions onto \$shortonto (\$todocount command)" \
173 "Rebase \$shortrevisions onto \$shortonto (\$todocount commands)" \
176 git rebase--helper
--append-todo-help ${keep_empty:+--keep-empty}
178 has_action
"$todo" ||
181 cp "$todo" "$todo".backup
183 git_sequence_editor
"$todo" ||
184 die_abort
"$(gettext "Could not execute editor
")"
186 has_action
"$todo" ||
189 git rebase--helper
--check-todo-list ||
{
197 test -n "$force_rebase" ||
198 onto
="$(git rebase--helper --skip-unnecessary-picks)" ||
199 die
"Could not skip unnecessary pick commands"
202 require_clean_work_tree
"rebase"
203 exec git rebase--helper
${force_rebase:+--no-ff} $allow_empty_message \
207 git_rebase__interactive
() {
208 initiate_action
"$action"
210 if test $ret = 0; then
217 init_revisions_and_shortrevisions
219 git rebase--helper
--make-script ${keep_empty:+--keep-empty} \
220 ${rebase_merges:+--rebase-merges} \
221 ${rebase_cousins:+--rebase-cousins} \
222 $revisions ${restrict_revision+^$restrict_revision} >"$todo" ||
223 die
"$(gettext "Could not generate todo list
")"