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)
38 test -n "$(git stripspace --strip-comments <"$1")"
41 git_sequence_editor () {
42 if test -z "$GIT_SEQUENCE_EDITOR"
44 GIT_SEQUENCE_EDITOR="$(git config sequence.editor)"
45 if [ -z "$GIT_SEQUENCE_EDITOR" ]
47 GIT_SEQUENCE_EDITOR="$(git var GIT_EDITOR)" || return $?
51 eval "$GIT_SEQUENCE_EDITOR" '"$@"'
55 git rebase--helper --expand-ids
59 git rebase--helper --shorten-ids
62 get_missing_commit_check_level () {
63 check_level=$(git config --get rebase.missingCommitsCheck)
64 check_level=${check_level:-ignore}
65 # Don't be case sensitive
66 printf '%s' "$check_level" | tr 'A-Z' 'a-z'
69 # Initiate an action. If the cannot be any
70 # further action it may exec a command
71 # or exit and not return.
73 # TODO: Consider a cleaner return model so it
74 # never exits and always return 0 if process
77 # Parameter 1 is the action to initiate.
79 # Returns 0 if the action was able to complete
80 # and if 1 if further processing is required.
84 exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
89 exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
93 exec git rebase--helper --edit-todo
96 exec git show REBASE_HEAD --
104 init_basic_state () {
105 orig_head=$(git rev-parse --verify HEAD) || die "$(gettext "No HEAD?")"
106 mkdir -p "$state_dir" || die "$(eval_gettext "Could not create temporary \$state_dir")"
107 rm -f "$(git rev-parse --git-path REBASE_HEAD)"
109 : > "$state_dir"/interactive || die "$(gettext "Could not mark as interactive")"
113 init_revisions_and_shortrevisions () {
114 shorthead=$(git rev-parse --short $orig_head)
115 shortonto=$(git rev-parse --short $onto)
116 if test -z "$rebase_root"
117 # this is now equivalent to ! -z "$upstream"
119 shortupstream=$(git rev-parse --short $upstream)
120 revisions=$upstream...$orig_head
121 shortrevisions=$shortupstream..$shorthead
123 revisions=$onto...$orig_head
124 shortrevisions=$shorthead
125 test -z "$squash_onto" ||
126 echo "$squash_onto" >"$state_dir"/squash-onto
131 test -s "$todo" || echo noop >> "$todo"
132 test -z "$autosquash" || git rebase--helper --rearrange-squash || exit
133 test -n "$cmd" && git rebase--helper --add-exec-commands "$cmd"
135 todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
136 todocount=${todocount##* }
140 $comment_char $(eval_ngettext \
141 "Rebase \$shortrevisions onto \$shortonto (\$todocount command)" \
142 "Rebase \$shortrevisions onto \$shortonto (\$todocount commands)" \
145 git rebase--helper --append-todo-help ${keep_empty:+--keep-empty}
147 has_action "$todo" ||
150 cp "$todo" "$todo".backup
152 git_sequence_editor "$todo" ||
153 die_abort "$(gettext "Could not execute editor")"
155 has_action "$todo" ||
158 git rebase--helper --check-todo-list || {
160 git rebase--helper --checkout-onto "$onto_name" "$onto" \
161 "$orig_head" ${verbose:+--verbose}
167 test -n "$force_rebase" ||
168 onto="$(git rebase--helper --skip-unnecessary-picks)" ||
169 die "Could not skip unnecessary pick commands"
171 git rebase--helper --checkout-onto "$onto_name" "$onto" "$orig_head" \
172 ${verbose:+--verbose}
173 require_clean_work_tree "rebase"
174 exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
178 git_rebase__interactive () {
179 initiate_action "$action"
181 if test $ret = 0; then
185 git rebase--helper --prepare-branch "$switch_to" ${verbose:+--verbose}
188 init_revisions_and_shortrevisions
190 git rebase--helper --make-script ${keep_empty:+--keep-empty} \
191 ${rebase_merges:+--rebase-merges} \
192 ${rebase_cousins:+--rebase-cousins} \
193 $revisions ${restrict_revision+^$restrict_revision} >"$todo" ||
194 die "$(gettext "Could not generate todo list")"