2013-11-26 01:03:52 +04:00
|
|
|
# This shell script fragment is sourced by git-rebase to implement
|
|
|
|
# its interactive mode. "git rebase --interactive" makes it easy
|
|
|
|
# to fix up commits in the middle of a series and rearrange commits.
|
2007-06-25 04:11:14 +04:00
|
|
|
#
|
|
|
|
# Copyright (c) 2006 Johannes E. Schindelin
|
|
|
|
#
|
|
|
|
# The original idea comes from Eric W. Biederman, in
|
2017-05-08 04:38:59 +03:00
|
|
|
# https://public-inbox.org/git/m1odwkyuf5.fsf_-_@ebiederm.dsl.xmission.com/
|
2012-06-26 18:51:54 +04:00
|
|
|
#
|
2010-01-14 08:54:45 +03:00
|
|
|
# The file containing rebase commands, comments, and empty lines.
|
|
|
|
# This file is created by "git rebase -i" then edited by the user. As
|
|
|
|
# the lines are processed, they are removed from the front of this
|
2011-02-06 21:43:37 +03:00
|
|
|
# file and written to the tail of $done.
|
2011-02-06 21:43:50 +03:00
|
|
|
todo="$state_dir"/git-rebase-todo
|
2010-01-14 08:54:45 +03:00
|
|
|
|
|
|
|
# The rebase command lines that have already been processed. A line
|
|
|
|
# is moved here when it is first handled, before any associated user
|
|
|
|
# actions.
|
2011-02-06 21:43:50 +03:00
|
|
|
done="$state_dir"/done
|
2010-01-14 08:54:45 +03:00
|
|
|
|
|
|
|
# The commit message that is planned to be used for any changes that
|
|
|
|
# need to be committed following a user interaction.
|
2011-02-06 21:43:50 +03:00
|
|
|
msg="$state_dir"/message
|
2010-01-14 08:54:45 +03:00
|
|
|
|
|
|
|
# The file into which is accumulated the suggested commit message for
|
|
|
|
# squash/fixup commands. When the first of a series of squash/fixups
|
|
|
|
# is seen, the file is created and the commit message from the
|
|
|
|
# previous commit and from the first squash/fixup commit are written
|
|
|
|
# to it. The commit message for each subsequent squash/fixup commit
|
|
|
|
# is appended to the file as it is processed.
|
|
|
|
#
|
|
|
|
# The first line of the file is of the form
|
2011-02-06 21:43:37 +03:00
|
|
|
# # This is a combination of $count commits.
|
|
|
|
# where $count is the number of commits whose messages have been
|
2010-01-14 08:54:45 +03:00
|
|
|
# written to the file so far (including the initial "pick" commit).
|
|
|
|
# Each time that a commit message is processed, this line is read and
|
|
|
|
# updated. It is deleted just before the combined commit is made.
|
2011-02-06 21:43:50 +03:00
|
|
|
squash_msg="$state_dir"/message-squash
|
2010-01-14 08:54:45 +03:00
|
|
|
|
2010-01-14 08:54:55 +03:00
|
|
|
# If the current series of squash/fixups has not yet included a squash
|
|
|
|
# command, then this file exists and holds the commit message of the
|
|
|
|
# original "pick" commit. (If the series ends without a "squash"
|
|
|
|
# command, then this can be used as the commit message of the combined
|
|
|
|
# commit without opening the editor.)
|
2011-02-06 21:43:50 +03:00
|
|
|
fixup_msg="$state_dir"/message-fixup
|
2010-01-14 08:54:55 +03:00
|
|
|
|
2011-02-06 21:43:37 +03:00
|
|
|
# $rewritten is the name of a directory containing files for each
|
|
|
|
# commit that is reachable by at least one merge base of $head and
|
|
|
|
# $upstream. They are not necessarily rewritten, but their children
|
2010-01-14 08:54:45 +03:00
|
|
|
# might be. This ensures that commits on merged, but otherwise
|
|
|
|
# unrelated side branches are left alone. (Think "X" in the man page's
|
|
|
|
# example.)
|
2011-02-06 21:43:50 +03:00
|
|
|
rewritten="$state_dir"/rewritten
|
2010-01-14 08:54:45 +03:00
|
|
|
|
2011-02-06 21:43:50 +03:00
|
|
|
dropped="$state_dir"/dropped
|
2010-01-14 08:54:46 +03:00
|
|
|
|
2013-04-25 13:28:54 +04:00
|
|
|
end="$state_dir"/end
|
|
|
|
msgnum="$state_dir"/msgnum
|
|
|
|
|
2010-01-14 08:54:46 +03:00
|
|
|
# A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
|
|
|
|
# GIT_AUTHOR_DATE that will be used for the commit that is currently
|
|
|
|
# being rebased.
|
2011-02-06 21:43:50 +03:00
|
|
|
author_script="$state_dir"/author-script
|
2010-01-14 08:54:46 +03:00
|
|
|
|
2010-01-14 08:54:47 +03:00
|
|
|
# When an "edit" rebase command is being processed, the SHA1 of the
|
|
|
|
# commit to be edited is recorded in this file. When "git rebase
|
|
|
|
# --continue" is executed, if there are any staged changes then they
|
|
|
|
# will be amended to the HEAD commit, but only provided the HEAD
|
|
|
|
# commit is still the commit to be edited. When any other rebase
|
|
|
|
# command is processed, this file is deleted.
|
2011-02-06 21:43:50 +03:00
|
|
|
amend="$state_dir"/amend
|
2010-01-14 08:54:47 +03:00
|
|
|
|
2010-03-12 20:04:30 +03:00
|
|
|
# For the post-rewrite hook, we make a list of rewritten commits and
|
|
|
|
# their new sha1s. The rewritten-pending list keeps the sha1s of
|
|
|
|
# commits that have been processed, but not committed yet,
|
|
|
|
# e.g. because they are waiting for a 'squash' command.
|
2011-02-06 21:43:50 +03:00
|
|
|
rewritten_list="$state_dir"/rewritten-list
|
|
|
|
rewritten_pending="$state_dir"/rewritten-pending
|
2011-02-06 21:43:37 +03:00
|
|
|
|
2015-10-28 17:54:48 +03:00
|
|
|
# Work around Git for Windows' Bash whose "read" does not strip CRLF
|
|
|
|
# and leaves CR at the end instead.
|
|
|
|
cr=$(printf "\015")
|
|
|
|
|
rebase -i: remember merge options beyond continue actions
If the user explicitly specified a merge strategy or strategy
options, continue to use that strategy/option after
"rebase --continue". Add a test of the corrected behavior.
If --merge is specified or implied by -s or -X, then "strategy and
"strategy_opts" are set to values from which "strategy_args" can be
derived; otherwise they are set to empty strings. Either way,
their values are propagated from one step of an interactive rebase
to the next via state files.
"do_merge", on the other hand, is *not* propagated to later steps of
an interactive rebase. Therefore, making the initialization of
"strategy_args" conditional on "do_merge" being set prevents later
steps of an interactive rebase from setting it correctly.
Luckily, we don't need the "do_merge" guard at all. If the rebase
was started without --merge, then "strategy" and "strategy_opts"
are both the empty string, which results in "strategy_args" also
being set to the empty string, which is just what we want in that
situation. So remove the "do_merge" guard and derive
"strategy_args" from "strategy" and "strategy_opts" every time.
Reported-by: Diogo de Campos <campos@esss.com.br>
Signed-off-by: Fabian Ruch <bafain@gmail.com>
Helped-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-12-11 23:30:36 +03:00
|
|
|
strategy_args=${strategy:+--strategy=$strategy}
|
2016-05-11 00:07:10 +03:00
|
|
|
test -n "$strategy_opts" &&
|
rebase -i: remember merge options beyond continue actions
If the user explicitly specified a merge strategy or strategy
options, continue to use that strategy/option after
"rebase --continue". Add a test of the corrected behavior.
If --merge is specified or implied by -s or -X, then "strategy and
"strategy_opts" are set to values from which "strategy_args" can be
derived; otherwise they are set to empty strings. Either way,
their values are propagated from one step of an interactive rebase
to the next via state files.
"do_merge", on the other hand, is *not* propagated to later steps of
an interactive rebase. Therefore, making the initialization of
"strategy_args" conditional on "do_merge" being set prevents later
steps of an interactive rebase from setting it correctly.
Luckily, we don't need the "do_merge" guard at all. If the rebase
was started without --merge, then "strategy" and "strategy_opts"
are both the empty string, which results in "strategy_args" also
being set to the empty string, which is just what we want in that
situation. So remove the "do_merge" guard and derive
"strategy_args" from "strategy" and "strategy_opts" every time.
Reported-by: Diogo de Campos <campos@esss.com.br>
Signed-off-by: Fabian Ruch <bafain@gmail.com>
Helped-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-12-11 23:30:36 +03:00
|
|
|
eval '
|
|
|
|
for strategy_opt in '"$strategy_opts"'
|
|
|
|
do
|
|
|
|
strategy_args="$strategy_args -X$(git rev-parse --sq-quote "${strategy_opt#--}")"
|
|
|
|
done
|
|
|
|
'
|
2013-07-02 12:05:48 +04:00
|
|
|
|
2011-02-06 21:43:49 +03:00
|
|
|
GIT_CHERRY_PICK_HELP="$resolvemsg"
|
2007-11-28 11:06:36 +03:00
|
|
|
export GIT_CHERRY_PICK_HELP
|
|
|
|
|
2016-11-21 17:18:29 +03:00
|
|
|
comment_char=$(git config --get core.commentchar 2>/dev/null)
|
|
|
|
case "$comment_char" in
|
|
|
|
'' | auto)
|
|
|
|
comment_char="#"
|
|
|
|
;;
|
|
|
|
?)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
comment_char=$(echo "$comment_char" | cut -c1)
|
|
|
|
;;
|
|
|
|
esac
|
2013-02-12 03:08:04 +04:00
|
|
|
|
2007-06-25 04:11:14 +04:00
|
|
|
warn () {
|
2010-07-22 23:15:11 +04:00
|
|
|
printf '%s\n' "$*" >&2
|
2007-06-25 04:11:14 +04:00
|
|
|
}
|
|
|
|
|
2010-01-14 08:54:51 +03:00
|
|
|
# Output the commit message for the specified commit.
|
|
|
|
commit_message () {
|
|
|
|
git cat-file commit "$1" | sed "1,/^$/d"
|
|
|
|
}
|
|
|
|
|
2011-02-06 21:43:37 +03:00
|
|
|
orig_reflog_action="$GIT_REFLOG_ACTION"
|
2007-06-25 04:11:14 +04:00
|
|
|
|
|
|
|
comment_for_reflog () {
|
2011-02-06 21:43:37 +03:00
|
|
|
case "$orig_reflog_action" in
|
2007-06-25 04:11:14 +04:00
|
|
|
''|rebase*)
|
|
|
|
GIT_REFLOG_ACTION="rebase -i ($1)"
|
|
|
|
export GIT_REFLOG_ACTION
|
2007-09-25 19:42:51 +04:00
|
|
|
;;
|
2007-06-25 04:11:14 +04:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2008-01-15 07:01:21 +03:00
|
|
|
last_count=
|
2007-06-25 04:11:14 +04:00
|
|
|
mark_action_done () {
|
2011-02-06 21:43:37 +03:00
|
|
|
sed -e 1q < "$todo" >> "$done"
|
|
|
|
sed -e 1d < "$todo" >> "$todo".new
|
|
|
|
mv -f "$todo".new "$todo"
|
2016-07-28 20:47:23 +03:00
|
|
|
new_count=$(( $(git stripspace --strip-comments <"$done" | wc -l) ))
|
2013-04-25 13:28:54 +04:00
|
|
|
echo $new_count >"$msgnum"
|
2013-02-12 03:08:04 +04:00
|
|
|
total=$(($new_count + $(git stripspace --strip-comments <"$todo" | wc -l)))
|
2013-04-25 13:28:54 +04:00
|
|
|
echo $total >"$end"
|
2011-02-06 21:43:37 +03:00
|
|
|
if test "$last_count" != "$new_count"
|
2008-01-15 07:01:21 +03:00
|
|
|
then
|
2011-02-06 21:43:37 +03:00
|
|
|
last_count=$new_count
|
2016-06-17 23:21:03 +03:00
|
|
|
eval_gettext "Rebasing (\$new_count/\$total)"; printf "\r"
|
2011-02-06 21:43:37 +03:00
|
|
|
test -z "$verbose" || echo
|
2008-01-15 07:01:21 +03:00
|
|
|
fi
|
2007-06-25 04:11:14 +04:00
|
|
|
}
|
|
|
|
|
2015-04-29 01:55:20 +03:00
|
|
|
# Put the last action marked done at the beginning of the todo list
|
|
|
|
# again. If there has not been an action marked done yet, leave the list of
|
|
|
|
# items on the todo list unchanged.
|
|
|
|
reschedule_last_action () {
|
|
|
|
tail -n 1 "$done" | cat - "$todo" >"$todo".new
|
|
|
|
sed -e \$d <"$done" >"$done".new
|
|
|
|
mv -f "$todo".new "$todo"
|
|
|
|
mv -f "$done".new "$done"
|
|
|
|
}
|
|
|
|
|
2012-09-18 05:28:08 +04:00
|
|
|
append_todo_help () {
|
2016-06-17 23:21:04 +03:00
|
|
|
gettext "
|
2013-02-12 03:08:04 +04:00
|
|
|
Commands:
|
2017-07-14 17:45:03 +03:00
|
|
|
p, pick = use commit
|
|
|
|
r, reword = use commit, but edit the commit message
|
|
|
|
e, edit = use commit, but stop for amending
|
|
|
|
s, squash = use commit, but meld into previous commit
|
|
|
|
f, fixup = like \"squash\", but discard this commit's log message
|
|
|
|
x, exec = run command (the rest of the line) using shell
|
|
|
|
d, drop = remove commit
|
2013-02-12 03:08:04 +04:00
|
|
|
|
|
|
|
These lines can be re-ordered; they are executed from top to bottom.
|
2016-06-17 23:21:04 +03:00
|
|
|
" | git stripspace --comment-lines >>"$todo"
|
2013-02-12 03:08:04 +04:00
|
|
|
|
2015-06-29 23:20:31 +03:00
|
|
|
if test $(get_missing_commit_check_level) = error
|
|
|
|
then
|
2016-06-17 23:21:04 +03:00
|
|
|
gettext "
|
2015-06-29 23:20:31 +03:00
|
|
|
Do not remove any line. Use 'drop' explicitly to remove a commit.
|
2016-06-17 23:21:04 +03:00
|
|
|
" | git stripspace --comment-lines >>"$todo"
|
2015-06-29 23:20:31 +03:00
|
|
|
else
|
2016-06-17 23:21:04 +03:00
|
|
|
gettext "
|
2013-02-12 03:08:04 +04:00
|
|
|
If you remove a line here THAT COMMIT WILL BE LOST.
|
2016-06-17 23:21:04 +03:00
|
|
|
" | git stripspace --comment-lines >>"$todo"
|
2015-06-29 23:20:31 +03:00
|
|
|
fi
|
2012-09-18 05:28:08 +04:00
|
|
|
}
|
|
|
|
|
2007-06-25 04:11:14 +04:00
|
|
|
make_patch () {
|
2008-12-23 00:16:51 +03:00
|
|
|
sha1_and_parents="$(git rev-list --parents -1 "$1")"
|
|
|
|
case "$sha1_and_parents" in
|
|
|
|
?*' '?*' '?*)
|
|
|
|
git diff --cc $sha1_and_parents
|
|
|
|
;;
|
|
|
|
?*' '?*)
|
|
|
|
git diff-tree -p "$1^!"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Root commit"
|
|
|
|
;;
|
2011-02-06 21:43:50 +03:00
|
|
|
esac > "$state_dir"/patch
|
2011-02-06 21:43:37 +03:00
|
|
|
test -f "$msg" ||
|
|
|
|
commit_message "$1" > "$msg"
|
|
|
|
test -f "$author_script" ||
|
|
|
|
get_author_ident_from_commit "$1" > "$author_script"
|
2007-06-25 04:11:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
die_with_patch () {
|
2011-02-06 21:43:50 +03:00
|
|
|
echo "$1" > "$state_dir"/stopped-sha
|
2007-06-25 04:11:14 +04:00
|
|
|
make_patch "$1"
|
|
|
|
die "$2"
|
|
|
|
}
|
|
|
|
|
2011-11-30 19:52:51 +04:00
|
|
|
exit_with_patch () {
|
|
|
|
echo "$1" > "$state_dir"/stopped-sha
|
|
|
|
make_patch $1
|
|
|
|
git rev-parse --verify HEAD > "$amend"
|
2014-02-10 05:03:37 +04:00
|
|
|
gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
|
2016-06-17 23:21:03 +03:00
|
|
|
warn "$(eval_gettext "\
|
|
|
|
You can amend the commit now, with
|
|
|
|
|
|
|
|
git commit --amend \$gpg_sign_opt_quoted
|
|
|
|
|
|
|
|
Once you are satisfied with your changes, run
|
|
|
|
|
|
|
|
git rebase --continue")"
|
2011-11-30 19:52:51 +04:00
|
|
|
warn
|
|
|
|
exit $2
|
|
|
|
}
|
|
|
|
|
2007-06-25 21:56:55 +04:00
|
|
|
die_abort () {
|
2016-06-29 09:21:27 +03:00
|
|
|
apply_autostash
|
2011-02-06 21:43:50 +03:00
|
|
|
rm -rf "$state_dir"
|
2007-06-25 21:56:55 +04:00
|
|
|
die "$1"
|
|
|
|
}
|
|
|
|
|
2007-09-25 19:42:51 +04:00
|
|
|
has_action () {
|
2013-02-12 03:08:04 +04:00
|
|
|
test -n "$(git stripspace --strip-comments <"$1")"
|
2007-09-25 19:42:51 +04:00
|
|
|
}
|
|
|
|
|
2012-04-20 18:36:17 +04:00
|
|
|
is_empty_commit() {
|
2016-06-17 23:21:03 +03:00
|
|
|
tree=$(git rev-parse -q --verify "$1"^{tree} 2>/dev/null) || {
|
|
|
|
sha1=$1
|
|
|
|
die "$(eval_gettext "\$sha1: not a commit that can be picked")"
|
|
|
|
}
|
|
|
|
ptree=$(git rev-parse -q --verify "$1"^^{tree} 2>/dev/null) ||
|
|
|
|
ptree=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
2012-04-20 18:36:17 +04:00
|
|
|
test "$tree" = "$ptree"
|
|
|
|
}
|
|
|
|
|
2013-01-13 00:46:01 +04:00
|
|
|
is_merge_commit()
|
|
|
|
{
|
|
|
|
git rev-parse --verify --quiet "$1"^2 >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
2010-01-14 08:54:53 +03:00
|
|
|
# Run command with GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
|
|
|
|
# GIT_AUTHOR_DATE exported from the current environment.
|
|
|
|
do_with_author () {
|
2010-01-23 00:09:24 +03:00
|
|
|
(
|
|
|
|
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
|
|
|
|
"$@"
|
|
|
|
)
|
2010-01-14 08:54:53 +03:00
|
|
|
}
|
|
|
|
|
2011-10-18 00:26:23 +04:00
|
|
|
git_sequence_editor () {
|
|
|
|
if test -z "$GIT_SEQUENCE_EDITOR"
|
|
|
|
then
|
|
|
|
GIT_SEQUENCE_EDITOR="$(git config sequence.editor)"
|
|
|
|
if [ -z "$GIT_SEQUENCE_EDITOR" ]
|
|
|
|
then
|
|
|
|
GIT_SEQUENCE_EDITOR="$(git var GIT_EDITOR)" || return $?
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
eval "$GIT_SEQUENCE_EDITOR" '"$@"'
|
|
|
|
}
|
|
|
|
|
2007-06-25 04:11:14 +04:00
|
|
|
pick_one () {
|
2010-03-06 23:34:46 +03:00
|
|
|
ff=--ff
|
2012-04-20 18:36:17 +04:00
|
|
|
|
2010-03-06 23:34:46 +03:00
|
|
|
case "$1" in -n) sha1=$2; ff= ;; *) sha1=$1 ;; esac
|
2011-02-06 21:43:37 +03:00
|
|
|
case "$force_rebase" in '') ;; ?*) ff= ;; esac
|
2016-06-17 23:21:03 +03:00
|
|
|
output git rev-parse --verify $sha1 || die "$(eval_gettext "Invalid commit name: \$sha1")"
|
2012-04-20 18:36:17 +04:00
|
|
|
|
|
|
|
if is_empty_commit "$sha1"
|
|
|
|
then
|
|
|
|
empty_args="--allow-empty"
|
|
|
|
fi
|
|
|
|
|
2011-02-06 21:43:37 +03:00
|
|
|
test -d "$rewritten" &&
|
2007-06-25 21:59:43 +04:00
|
|
|
pick_one_preserving_merges "$@" && return
|
2017-08-02 13:44:17 +03:00
|
|
|
output eval git cherry-pick $allow_rerere_autoupdate \
|
2014-02-10 05:03:37 +04:00
|
|
|
${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \
|
|
|
|
"$strategy_args" $empty_args $ff "$@"
|
2015-04-29 01:55:20 +03:00
|
|
|
|
|
|
|
# If cherry-pick dies it leaves the to-be-picked commit unrecorded. Reschedule
|
|
|
|
# previous task so this commit is not lost.
|
|
|
|
ret=$?
|
|
|
|
case "$ret" in [01]) ;; *) reschedule_last_action ;; esac
|
|
|
|
return $ret
|
2007-06-25 04:11:14 +04:00
|
|
|
}
|
|
|
|
|
2007-06-25 21:59:43 +04:00
|
|
|
pick_one_preserving_merges () {
|
2008-08-14 01:41:23 +04:00
|
|
|
fast_forward=t
|
|
|
|
case "$1" in
|
|
|
|
-n)
|
|
|
|
fast_forward=f
|
|
|
|
sha1=$2
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
sha1=$1
|
|
|
|
;;
|
|
|
|
esac
|
2007-06-25 21:59:43 +04:00
|
|
|
sha1=$(git rev-parse $sha1)
|
|
|
|
|
2011-02-06 21:43:50 +03:00
|
|
|
if test -f "$state_dir"/current-commit
|
2007-06-25 21:59:43 +04:00
|
|
|
then
|
2008-10-22 22:59:30 +04:00
|
|
|
if test "$fast_forward" = t
|
2008-10-15 11:44:36 +04:00
|
|
|
then
|
2010-07-06 09:16:15 +04:00
|
|
|
while read current_commit
|
2008-10-15 11:44:36 +04:00
|
|
|
do
|
2011-02-06 21:43:37 +03:00
|
|
|
git rev-parse HEAD > "$rewritten"/$current_commit
|
2011-02-06 21:43:50 +03:00
|
|
|
done <"$state_dir"/current-commit
|
|
|
|
rm "$state_dir"/current-commit ||
|
2016-06-17 23:21:03 +03:00
|
|
|
die "$(gettext "Cannot write current commit's replacement sha1")"
|
2008-10-15 11:44:36 +04:00
|
|
|
fi
|
2007-06-25 21:59:43 +04:00
|
|
|
fi
|
|
|
|
|
2011-02-06 21:43:50 +03:00
|
|
|
echo $sha1 >> "$state_dir"/current-commit
|
2008-08-14 01:41:24 +04:00
|
|
|
|
2007-06-25 21:59:43 +04:00
|
|
|
# rewrite parents; if none were rewritten, we can fast-forward.
|
|
|
|
new_parents=
|
2009-01-03 01:28:28 +03:00
|
|
|
pend=" $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)"
|
|
|
|
if test "$pend" = " "
|
|
|
|
then
|
|
|
|
pend=" root"
|
|
|
|
fi
|
2008-10-06 08:26:52 +04:00
|
|
|
while [ "$pend" != "" ]
|
2007-06-25 21:59:43 +04:00
|
|
|
do
|
2008-10-06 08:26:52 +04:00
|
|
|
p=$(expr "$pend" : ' \([^ ]*\)')
|
|
|
|
pend="${pend# $p}"
|
|
|
|
|
2011-02-06 21:43:37 +03:00
|
|
|
if test -f "$rewritten"/$p
|
2007-06-25 21:59:43 +04:00
|
|
|
then
|
2011-02-06 21:43:37 +03:00
|
|
|
new_p=$(cat "$rewritten"/$p)
|
2008-10-15 11:44:40 +04:00
|
|
|
|
|
|
|
# If the todo reordered commits, and our parent is marked for
|
|
|
|
# rewriting, but hasn't been gotten to yet, assume the user meant to
|
|
|
|
# drop it on top of the current HEAD
|
|
|
|
if test -z "$new_p"
|
|
|
|
then
|
|
|
|
new_p=$(git rev-parse HEAD)
|
|
|
|
fi
|
|
|
|
|
2007-06-25 21:59:43 +04:00
|
|
|
test $p != $new_p && fast_forward=f
|
|
|
|
case "$new_parents" in
|
|
|
|
*$new_p*)
|
|
|
|
;; # do nothing; that parent is already there
|
|
|
|
*)
|
|
|
|
new_parents="$new_parents $new_p"
|
2007-09-25 19:42:51 +04:00
|
|
|
;;
|
2007-06-25 21:59:43 +04:00
|
|
|
esac
|
2008-07-16 05:51:49 +04:00
|
|
|
else
|
2011-02-06 21:43:37 +03:00
|
|
|
if test -f "$dropped"/$p
|
2008-10-06 08:26:52 +04:00
|
|
|
then
|
|
|
|
fast_forward=f
|
2011-02-06 21:43:37 +03:00
|
|
|
replacement="$(cat "$dropped"/$p)"
|
2009-01-03 01:28:28 +03:00
|
|
|
test -z "$replacement" && replacement=root
|
|
|
|
pend=" $replacement$pend"
|
2008-10-06 08:26:52 +04:00
|
|
|
else
|
|
|
|
new_parents="$new_parents $p"
|
|
|
|
fi
|
2007-06-25 21:59:43 +04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
case $fast_forward in
|
|
|
|
t)
|
2016-06-17 23:21:03 +03:00
|
|
|
output warn "$(eval_gettext "Fast-forward to \$sha1")"
|
2008-08-14 01:41:23 +04:00
|
|
|
output git reset --hard $sha1 ||
|
2016-06-17 23:21:03 +03:00
|
|
|
die "$(eval_gettext "Cannot fast-forward to \$sha1")"
|
2007-06-25 21:59:43 +04:00
|
|
|
;;
|
|
|
|
f)
|
2007-09-25 19:42:51 +04:00
|
|
|
first_parent=$(expr "$new_parents" : ' \([^ ]*\)')
|
2008-10-15 11:44:37 +04:00
|
|
|
|
|
|
|
if [ "$1" != "-n" ]
|
|
|
|
then
|
|
|
|
# detach HEAD to current parent
|
|
|
|
output git checkout $first_parent 2> /dev/null ||
|
2016-06-17 23:21:03 +03:00
|
|
|
die "$(eval_gettext "Cannot move HEAD to \$first_parent")"
|
2008-10-15 11:44:37 +04:00
|
|
|
fi
|
2007-06-25 21:59:43 +04:00
|
|
|
|
|
|
|
case "$new_parents" in
|
2007-09-25 19:42:51 +04:00
|
|
|
' '*' '*)
|
2016-06-17 23:21:03 +03:00
|
|
|
test "a$1" = a-n && die "$(eval_gettext "Refusing to squash a merge: \$sha1")"
|
2008-10-15 11:44:37 +04:00
|
|
|
|
2007-06-25 21:59:43 +04:00
|
|
|
# redo merge
|
2011-02-06 21:43:37 +03:00
|
|
|
author_script_content=$(get_author_ident_from_commit $sha1)
|
|
|
|
eval "$author_script_content"
|
|
|
|
msg_content="$(commit_message $sha1)"
|
2007-10-31 05:20:32 +03:00
|
|
|
# No point in merging the first parent, that's HEAD
|
|
|
|
new_parents=${new_parents# $first_parent}
|
2013-08-21 22:48:57 +04:00
|
|
|
merge_args="--no-log --no-ff"
|
2013-07-02 12:05:48 +04:00
|
|
|
if ! do_with_author output eval \
|
2018-01-05 00:31:52 +03:00
|
|
|
git merge ${gpg_sign_opt:+$(git rev-parse \
|
|
|
|
--sq-quote "$gpg_sign_opt")} \
|
|
|
|
$allow_rerere_autoupdate "$merge_args" \
|
|
|
|
"$strategy_args" \
|
|
|
|
-m $(git rev-parse --sq-quote "$msg_content") \
|
|
|
|
"$new_parents"
|
2007-06-25 21:59:43 +04:00
|
|
|
then
|
2011-02-06 21:43:37 +03:00
|
|
|
printf "%s\n" "$msg_content" > "$GIT_DIR"/MERGE_MSG
|
2016-06-17 23:21:03 +03:00
|
|
|
die_with_patch $sha1 "$(eval_gettext "Error redoing merge \$sha1")"
|
2007-06-25 21:59:43 +04:00
|
|
|
fi
|
2011-02-06 21:43:37 +03:00
|
|
|
echo "$sha1 $(git rev-parse HEAD^0)" >> "$rewritten_list"
|
2007-06-25 21:59:43 +04:00
|
|
|
;;
|
|
|
|
*)
|
2017-08-02 13:44:17 +03:00
|
|
|
output eval git cherry-pick $allow_rerere_autoupdate \
|
2014-02-10 05:03:37 +04:00
|
|
|
${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \
|
|
|
|
"$strategy_args" "$@" ||
|
2016-06-17 23:21:03 +03:00
|
|
|
die_with_patch $sha1 "$(eval_gettext "Could not pick \$sha1")"
|
2007-09-25 19:42:51 +04:00
|
|
|
;;
|
2007-06-25 21:59:43 +04:00
|
|
|
esac
|
2007-09-25 19:42:51 +04:00
|
|
|
;;
|
2007-06-25 21:59:43 +04:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2016-06-17 23:21:05 +03:00
|
|
|
this_nth_commit_message () {
|
|
|
|
n=$1
|
2016-08-21 17:50:38 +03:00
|
|
|
eval_gettext "This is the commit message #\${n}:"
|
2016-06-17 23:21:05 +03:00
|
|
|
}
|
2016-08-21 17:50:38 +03:00
|
|
|
|
2016-06-17 23:21:05 +03:00
|
|
|
skip_nth_commit_message () {
|
|
|
|
n=$1
|
2016-08-21 17:50:38 +03:00
|
|
|
eval_gettext "The commit message #\${n} will be skipped:"
|
2007-07-21 21:09:41 +04:00
|
|
|
}
|
|
|
|
|
2010-01-14 08:54:55 +03:00
|
|
|
update_squash_messages () {
|
2011-02-06 21:43:37 +03:00
|
|
|
if test -f "$squash_msg"; then
|
|
|
|
mv "$squash_msg" "$squash_msg".bak || exit
|
|
|
|
count=$(($(sed -n \
|
rebase--interactive: count squash commits above 10 correctly
We generate the squash commit message incrementally running
a sed script once for each commit. It parses "This is
a combination of <N> commits" from the first line of the
existing message, adds one to <N>, and uses the result as
the number of our current message.
Since f2d17068fd (i18n: rebase-interactive: mark comments of
squash for translation, 2016-06-17), the first line may be
localized, and sed uses a pretty liberal regex, looking for:
/^#.*([0-9][0-9]*)/
The "[0-9][0-9]*" tries to match double digits, but it
doesn't quite work. The first ".*" is greedy, so if you
have:
This is a combination of 10 commits.
it will eat up "This is a combination of 1", leaving "0" to
match the first "[0-9]" digit, and then skipping the
optional match of "[0-9]*".
As a result, the count resets every 10 commits, and a
15-commit squash would end up as:
# This is a combination of 5 commits.
# This is the 1st commit message:
...
# This is the commit message #2:
... and so on ..
# This is the commit message #10:
...
# This is the commit message #1:
...
# This is the commit message #2:
... etc, up to 5 ...
We can fix this by making the ".*" less greedy. Instead of
depending on ".*?" working portably, we can just limit the
match to non-digit characters, which accomplishes the same
thing.
Reported-by: Brandon Tolsch <btolsch@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-01-07 11:23:19 +03:00
|
|
|
-e "1s/^$comment_char[^0-9]*\([0-9][0-9]*\).*/\1/p" \
|
2011-02-06 21:43:37 +03:00
|
|
|
-e "q" < "$squash_msg".bak)+1))
|
2010-01-14 08:54:54 +03:00
|
|
|
{
|
2016-06-17 23:21:05 +03:00
|
|
|
printf '%s\n' "$comment_char $(eval_ngettext \
|
|
|
|
"This is a combination of \$count commit." \
|
|
|
|
"This is a combination of \$count commits." \
|
|
|
|
$count)"
|
2010-01-14 08:54:54 +03:00
|
|
|
sed -e 1d -e '2,/^./{
|
|
|
|
/^$/d
|
2011-02-06 21:43:37 +03:00
|
|
|
}' <"$squash_msg".bak
|
|
|
|
} >"$squash_msg"
|
2007-07-21 21:09:41 +04:00
|
|
|
else
|
2016-12-20 20:36:23 +03:00
|
|
|
commit_message HEAD >"$fixup_msg" ||
|
|
|
|
die "$(eval_gettext "Cannot write \$fixup_msg")"
|
2011-02-06 21:43:37 +03:00
|
|
|
count=2
|
2010-01-14 08:54:54 +03:00
|
|
|
{
|
2016-06-17 23:21:05 +03:00
|
|
|
printf '%s\n' "$comment_char $(gettext "This is a combination of 2 commits.")"
|
|
|
|
printf '%s\n' "$comment_char $(gettext "This is the 1st commit message:")"
|
2010-01-14 08:54:54 +03:00
|
|
|
echo
|
2011-02-06 21:43:37 +03:00
|
|
|
cat "$fixup_msg"
|
|
|
|
} >"$squash_msg"
|
2007-07-21 21:09:41 +04:00
|
|
|
fi
|
2009-12-07 12:20:59 +03:00
|
|
|
case $1 in
|
|
|
|
squash)
|
2011-02-06 21:43:37 +03:00
|
|
|
rm -f "$fixup_msg"
|
2009-12-07 12:20:59 +03:00
|
|
|
echo
|
2016-06-17 23:21:05 +03:00
|
|
|
printf '%s\n' "$comment_char $(this_nth_commit_message $count)"
|
2009-12-07 12:20:59 +03:00
|
|
|
echo
|
2010-01-14 08:54:51 +03:00
|
|
|
commit_message $2
|
2009-12-07 12:20:59 +03:00
|
|
|
;;
|
|
|
|
fixup)
|
|
|
|
echo
|
2016-06-17 23:21:05 +03:00
|
|
|
printf '%s\n' "$comment_char $(skip_nth_commit_message $count)"
|
2009-12-07 12:20:59 +03:00
|
|
|
echo
|
2013-02-12 03:08:04 +04:00
|
|
|
# Change the space after the comment character to TAB:
|
|
|
|
commit_message $2 | git stripspace --comment-lines | sed -e 's/ / /'
|
2009-12-07 12:20:59 +03:00
|
|
|
;;
|
2011-02-06 21:43:37 +03:00
|
|
|
esac >>"$squash_msg"
|
2007-07-21 21:09:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
peek_next_command () {
|
2013-02-12 03:08:04 +04:00
|
|
|
git stripspace --strip-comments <"$todo" | sed -n -e 's/ .*//p' -e q
|
2007-07-21 21:09:41 +04:00
|
|
|
}
|
|
|
|
|
2010-01-14 08:54:57 +03:00
|
|
|
# A squash/fixup has failed. Prepare the long version of the squash
|
|
|
|
# commit message, then die_with_patch. This code path requires the
|
|
|
|
# user to edit the combined commit message for all commits that have
|
|
|
|
# been squashed/fixedup so far. So also erase the old squash
|
|
|
|
# messages, effectively causing the combined commit to be used as the
|
|
|
|
# new basis for any further squash/fixups. Args: sha1 rest
|
|
|
|
die_failed_squash() {
|
2016-06-17 23:21:03 +03:00
|
|
|
sha1=$1
|
|
|
|
rest=$2
|
2011-02-06 21:43:37 +03:00
|
|
|
mv "$squash_msg" "$msg" || exit
|
|
|
|
rm -f "$fixup_msg"
|
|
|
|
cp "$msg" "$GIT_DIR"/MERGE_MSG || exit
|
2010-01-14 08:54:57 +03:00
|
|
|
warn
|
2016-06-17 23:21:03 +03:00
|
|
|
warn "$(eval_gettext "Could not apply \$sha1... \$rest")"
|
|
|
|
die_with_patch $sha1 ""
|
2010-01-14 08:54:57 +03:00
|
|
|
}
|
|
|
|
|
2010-03-12 20:04:30 +03:00
|
|
|
flush_rewritten_pending() {
|
2011-02-06 21:43:37 +03:00
|
|
|
test -s "$rewritten_pending" || return
|
2010-03-12 20:04:30 +03:00
|
|
|
newsha1="$(git rev-parse HEAD^0)"
|
2011-02-06 21:43:37 +03:00
|
|
|
sed "s/$/ $newsha1/" < "$rewritten_pending" >> "$rewritten_list"
|
|
|
|
rm -f "$rewritten_pending"
|
2010-03-12 20:04:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
record_in_rewritten() {
|
|
|
|
oldsha1="$(git rev-parse $1)"
|
2011-02-06 21:43:37 +03:00
|
|
|
echo "$oldsha1" >> "$rewritten_pending"
|
2010-03-12 20:04:30 +03:00
|
|
|
|
|
|
|
case "$(peek_next_command)" in
|
2010-07-06 09:16:15 +04:00
|
|
|
squash|s|fixup|f)
|
2010-03-12 20:04:30 +03:00
|
|
|
;;
|
2010-07-06 09:16:15 +04:00
|
|
|
*)
|
2010-03-12 20:04:30 +03:00
|
|
|
flush_rewritten_pending
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2012-06-27 01:55:23 +04:00
|
|
|
do_pick () {
|
2016-06-17 23:21:03 +03:00
|
|
|
sha1=$1
|
|
|
|
rest=$2
|
2012-06-27 01:55:23 +04:00
|
|
|
if test "$(git rev-parse HEAD)" = "$squash_onto"
|
|
|
|
then
|
|
|
|
# Set the correct commit message and author info on the
|
|
|
|
# sentinel root before cherry-picking the original changes
|
|
|
|
# without committing (-n). Finally, update the sentinel again
|
|
|
|
# to include these changes. If the cherry-pick results in a
|
|
|
|
# conflict, this means our behaviour is similar to a standard
|
|
|
|
# failed cherry-pick during rebase, with a dirty index to
|
|
|
|
# resolve before manually running git commit --amend then git
|
|
|
|
# rebase --continue.
|
|
|
|
git commit --allow-empty --allow-empty-message --amend \
|
2016-06-17 23:21:03 +03:00
|
|
|
--no-post-rewrite -n -q -C $sha1 &&
|
|
|
|
pick_one -n $sha1 &&
|
2012-06-27 01:55:23 +04:00
|
|
|
git commit --allow-empty --allow-empty-message \
|
2016-06-17 23:21:03 +03:00
|
|
|
--amend --no-post-rewrite -n -q -C $sha1 \
|
2014-02-10 05:03:37 +04:00
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2016-06-17 23:21:03 +03:00
|
|
|
die_with_patch $sha1 "$(eval_gettext "Could not apply \$sha1... \$rest")"
|
2012-06-27 01:55:23 +04:00
|
|
|
else
|
2016-06-17 23:21:03 +03:00
|
|
|
pick_one $sha1 ||
|
|
|
|
die_with_patch $sha1 "$(eval_gettext "Could not apply \$sha1... \$rest")"
|
2012-06-27 01:55:23 +04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2007-06-25 04:11:14 +04:00
|
|
|
do_next () {
|
2015-05-22 16:15:49 +03:00
|
|
|
rm -f "$msg" "$author_script" "$amend" "$state_dir"/stopped-sha || exit
|
2011-02-06 21:43:37 +03:00
|
|
|
read -r command sha1 rest < "$todo"
|
2007-06-25 04:11:14 +04:00
|
|
|
case "$command" in
|
2015-06-29 23:20:30 +03:00
|
|
|
"$comment_char"*|''|noop|drop|d)
|
2007-06-25 04:11:14 +04:00
|
|
|
mark_action_done
|
|
|
|
;;
|
2015-10-28 17:54:48 +03:00
|
|
|
"$cr")
|
|
|
|
# Work around CR left by "read" (e.g. with Git for Windows' Bash).
|
|
|
|
mark_action_done
|
|
|
|
;;
|
2007-09-29 06:32:11 +04:00
|
|
|
pick|p)
|
2007-06-25 04:11:14 +04:00
|
|
|
comment_for_reflog pick
|
|
|
|
|
|
|
|
mark_action_done
|
2012-06-27 01:55:23 +04:00
|
|
|
do_pick $sha1 "$rest"
|
2010-03-12 20:04:30 +03:00
|
|
|
record_in_rewritten $sha1
|
2007-06-25 04:11:14 +04:00
|
|
|
;;
|
2009-10-07 10:13:23 +04:00
|
|
|
reword|r)
|
|
|
|
comment_for_reflog reword
|
|
|
|
|
|
|
|
mark_action_done
|
2012-06-27 01:55:23 +04:00
|
|
|
do_pick $sha1 "$rest"
|
2014-02-10 05:03:37 +04:00
|
|
|
git commit --amend --no-post-rewrite ${gpg_sign_opt:+"$gpg_sign_opt"} || {
|
2016-06-17 23:21:03 +03:00
|
|
|
warn "$(eval_gettext "\
|
|
|
|
Could not amend commit after successfully picking \$sha1... \$rest
|
|
|
|
This is most likely due to an empty commit message, or the pre-commit hook
|
|
|
|
failed. If the pre-commit hook failed, you may need to resolve the issue before
|
|
|
|
you are able to reword the commit.")"
|
2011-11-30 19:52:51 +04:00
|
|
|
exit_with_patch $sha1 1
|
|
|
|
}
|
2010-03-12 20:04:30 +03:00
|
|
|
record_in_rewritten $sha1
|
2009-10-07 10:13:23 +04:00
|
|
|
;;
|
2007-09-29 06:32:11 +04:00
|
|
|
edit|e)
|
2007-06-25 04:11:14 +04:00
|
|
|
comment_for_reflog edit
|
|
|
|
|
|
|
|
mark_action_done
|
2012-06-27 01:55:23 +04:00
|
|
|
do_pick $sha1 "$rest"
|
2016-03-28 19:00:00 +03:00
|
|
|
sha1_abbrev=$(git rev-parse --short $sha1)
|
2016-06-17 23:21:03 +03:00
|
|
|
warn "$(eval_gettext "Stopped at \$sha1_abbrev... \$rest")"
|
2011-11-30 19:52:51 +04:00
|
|
|
exit_with_patch $sha1 0
|
2007-06-25 04:11:14 +04:00
|
|
|
;;
|
2009-12-07 12:20:59 +03:00
|
|
|
squash|s|fixup|f)
|
|
|
|
case "$command" in
|
|
|
|
squash|s)
|
|
|
|
squash_style=squash
|
|
|
|
;;
|
|
|
|
fixup|f)
|
|
|
|
squash_style=fixup
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
comment_for_reflog $squash_style
|
2007-06-25 04:11:14 +04:00
|
|
|
|
2011-02-06 21:43:37 +03:00
|
|
|
test -f "$done" && has_action "$done" ||
|
2016-06-17 23:21:03 +03:00
|
|
|
die "$(eval_gettext "Cannot '\$squash_style' without a previous commit")"
|
2007-06-25 04:11:14 +04:00
|
|
|
|
|
|
|
mark_action_done
|
2010-01-14 08:54:55 +03:00
|
|
|
update_squash_messages $squash_style $sha1
|
2011-02-06 21:43:37 +03:00
|
|
|
author_script_content=$(get_author_ident_from_commit HEAD)
|
|
|
|
echo "$author_script_content" > "$author_script"
|
|
|
|
eval "$author_script_content"
|
2012-07-24 16:17:03 +04:00
|
|
|
if ! pick_one -n $sha1
|
|
|
|
then
|
|
|
|
git rev-parse --verify HEAD >"$amend"
|
|
|
|
die_failed_squash $sha1 "$rest"
|
|
|
|
fi
|
2007-07-21 21:09:41 +04:00
|
|
|
case "$(peek_next_command)" in
|
2009-12-07 12:20:59 +03:00
|
|
|
squash|s|fixup|f)
|
2010-01-14 08:54:55 +03:00
|
|
|
# This is an intermediate commit; its message will only be
|
|
|
|
# used in case of trouble. So use the long version:
|
2014-02-10 05:03:37 +04:00
|
|
|
do_with_author output git commit --amend --no-verify -F "$squash_msg" \
|
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2010-01-14 08:54:57 +03:00
|
|
|
die_failed_squash $sha1 "$rest"
|
2007-09-25 19:42:51 +04:00
|
|
|
;;
|
2007-07-21 21:09:41 +04:00
|
|
|
*)
|
2010-01-14 08:54:55 +03:00
|
|
|
# This is the final command of this squash/fixup group
|
2011-02-06 21:43:37 +03:00
|
|
|
if test -f "$fixup_msg"
|
2010-01-14 08:54:55 +03:00
|
|
|
then
|
2014-02-10 05:03:37 +04:00
|
|
|
do_with_author git commit --amend --no-verify -F "$fixup_msg" \
|
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2010-01-14 08:54:57 +03:00
|
|
|
die_failed_squash $sha1 "$rest"
|
|
|
|
else
|
2011-02-06 21:43:37 +03:00
|
|
|
cp "$squash_msg" "$GIT_DIR"/SQUASH_MSG || exit
|
2010-01-14 08:54:57 +03:00
|
|
|
rm -f "$GIT_DIR"/MERGE_MSG
|
2014-02-10 05:03:37 +04:00
|
|
|
do_with_author git commit --amend --no-verify -F "$GIT_DIR"/SQUASH_MSG -e \
|
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2010-01-14 08:54:57 +03:00
|
|
|
die_failed_squash $sha1 "$rest"
|
2010-01-14 08:54:55 +03:00
|
|
|
fi
|
2011-02-06 21:43:37 +03:00
|
|
|
rm -f "$squash_msg" "$fixup_msg"
|
2007-09-25 19:42:51 +04:00
|
|
|
;;
|
2007-07-21 21:09:41 +04:00
|
|
|
esac
|
2010-03-12 20:04:30 +03:00
|
|
|
record_in_rewritten $sha1
|
2007-06-25 04:11:14 +04:00
|
|
|
;;
|
2010-08-10 19:17:51 +04:00
|
|
|
x|"exec")
|
2011-02-06 21:43:37 +03:00
|
|
|
read -r command rest < "$todo"
|
2010-08-10 19:17:51 +04:00
|
|
|
mark_action_done
|
2016-06-17 23:21:03 +03:00
|
|
|
eval_gettextln "Executing: \$rest"
|
2015-11-13 09:03:19 +03:00
|
|
|
"${SHELL:-@SHELL_PATH@}" -c "$rest" # Actual execution
|
2010-08-10 19:17:51 +04:00
|
|
|
status=$?
|
2011-08-24 22:54:50 +04:00
|
|
|
# Run in subshell because require_clean_work_tree can die.
|
|
|
|
dirty=f
|
|
|
|
(require_clean_work_tree "rebase" 2>/dev/null) || dirty=t
|
2010-08-10 19:17:51 +04:00
|
|
|
if test "$status" -ne 0
|
|
|
|
then
|
2016-06-17 23:21:03 +03:00
|
|
|
warn "$(eval_gettext "Execution failed: \$rest")"
|
2011-08-24 22:54:50 +04:00
|
|
|
test "$dirty" = f ||
|
2016-06-17 23:21:03 +03:00
|
|
|
warn "$(gettext "and made changes to the index and/or the working tree")"
|
2011-08-24 22:54:50 +04:00
|
|
|
|
2016-06-17 23:21:03 +03:00
|
|
|
warn "$(gettext "\
|
|
|
|
You can fix the problem, and then run
|
|
|
|
|
|
|
|
git rebase --continue")"
|
2010-08-10 19:17:51 +04:00
|
|
|
warn
|
2012-09-18 15:15:26 +04:00
|
|
|
if test $status -eq 127 # command not found
|
|
|
|
then
|
|
|
|
status=1
|
|
|
|
fi
|
2010-08-10 19:17:51 +04:00
|
|
|
exit "$status"
|
2011-08-24 22:54:50 +04:00
|
|
|
elif test "$dirty" = t
|
2010-08-10 19:17:51 +04:00
|
|
|
then
|
2016-06-17 23:21:03 +03:00
|
|
|
# TRANSLATORS: after these lines is a command to be issued by the user
|
|
|
|
warn "$(eval_gettext "\
|
|
|
|
Execution succeeded: \$rest
|
|
|
|
but left changes to the index and/or the working tree
|
|
|
|
Commit or stash your changes, and then run
|
|
|
|
|
|
|
|
git rebase --continue")"
|
2010-08-10 19:17:51 +04:00
|
|
|
warn
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2007-06-25 04:11:14 +04:00
|
|
|
*)
|
2016-06-17 23:21:03 +03:00
|
|
|
warn "$(eval_gettext "Unknown command: \$command \$sha1 \$rest")"
|
|
|
|
fixtodo="$(gettext "Please fix this using 'git rebase --edit-todo'.")"
|
2009-10-27 17:58:14 +03:00
|
|
|
if git rev-parse --verify -q "$sha1" >/dev/null
|
|
|
|
then
|
2012-09-19 10:43:54 +04:00
|
|
|
die_with_patch $sha1 "$fixtodo"
|
2009-10-27 17:58:14 +03:00
|
|
|
else
|
2012-09-19 10:43:54 +04:00
|
|
|
die "$fixtodo"
|
2009-10-27 17:58:14 +03:00
|
|
|
fi
|
2007-09-25 19:42:51 +04:00
|
|
|
;;
|
2007-06-25 04:11:14 +04:00
|
|
|
esac
|
2011-02-06 21:43:37 +03:00
|
|
|
test -s "$todo" && return
|
2007-06-25 04:11:14 +04:00
|
|
|
|
2007-06-25 21:58:28 +04:00
|
|
|
comment_for_reflog finish &&
|
2011-02-06 21:43:37 +03:00
|
|
|
newhead=$(git rev-parse HEAD) &&
|
2011-02-06 21:43:50 +03:00
|
|
|
case $head_name in
|
2007-09-25 19:43:15 +04:00
|
|
|
refs/*)
|
2012-08-10 10:51:19 +04:00
|
|
|
message="$GIT_REFLOG_ACTION: $head_name onto $onto" &&
|
2011-02-06 21:43:50 +03:00
|
|
|
git update-ref -m "$message" $head_name $newhead $orig_head &&
|
2011-05-28 00:16:14 +04:00
|
|
|
git symbolic-ref \
|
|
|
|
-m "$GIT_REFLOG_ACTION: returning to $head_name" \
|
|
|
|
HEAD $head_name
|
2007-09-25 19:43:15 +04:00
|
|
|
;;
|
|
|
|
esac && {
|
2011-02-06 21:43:50 +03:00
|
|
|
test ! -f "$state_dir"/verbose ||
|
2011-02-06 21:43:52 +03:00
|
|
|
git diff-tree --stat $orig_head..HEAD
|
2007-07-08 06:02:13 +04:00
|
|
|
} &&
|
2010-03-12 20:04:33 +03:00
|
|
|
{
|
2011-02-06 21:43:37 +03:00
|
|
|
test -s "$rewritten_list" &&
|
|
|
|
git notes copy --for-rewrite=rebase < "$rewritten_list" ||
|
2010-03-12 20:04:33 +03:00
|
|
|
true # we don't care if this copying failed
|
|
|
|
} &&
|
2014-11-30 11:24:38 +03:00
|
|
|
hook="$(git rev-parse --git-path hooks/post-rewrite)"
|
|
|
|
if test -x "$hook" && test -s "$rewritten_list"; then
|
|
|
|
"$hook" rebase < "$rewritten_list"
|
2010-03-12 20:04:30 +03:00
|
|
|
true # we don't care if this hook failed
|
|
|
|
fi &&
|
2016-06-17 23:21:03 +03:00
|
|
|
warn "$(eval_gettext "Successfully rebased and updated \$head_name.")"
|
2007-06-25 04:11:14 +04:00
|
|
|
|
2013-05-12 15:56:39 +04:00
|
|
|
return 1 # not failure; just to break the do_rest loop
|
2007-06-25 04:11:14 +04:00
|
|
|
}
|
|
|
|
|
2013-05-12 15:56:39 +04:00
|
|
|
# can only return 0, when the infinite loop breaks
|
2007-06-25 04:11:14 +04:00
|
|
|
do_rest () {
|
|
|
|
while :
|
|
|
|
do
|
2013-05-12 15:56:39 +04:00
|
|
|
do_next || break
|
2007-06-25 04:11:14 +04:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2013-08-24 04:10:42 +04:00
|
|
|
expand_todo_ids() {
|
2017-07-14 17:45:11 +03:00
|
|
|
git rebase--helper --expand-ids
|
2013-08-24 04:10:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
collapse_todo_ids() {
|
2017-07-14 17:45:11 +03:00
|
|
|
git rebase--helper --shorten-ids
|
2009-12-08 06:13:14 +03:00
|
|
|
}
|
|
|
|
|
2015-06-29 23:20:31 +03:00
|
|
|
# Switch to the branch in $into and notify it in the reflog
|
|
|
|
checkout_onto () {
|
|
|
|
GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name"
|
2016-06-17 23:21:03 +03:00
|
|
|
output git checkout $onto || die_abort "$(gettext "could not detach HEAD")"
|
2015-06-29 23:20:31 +03:00
|
|
|
git update-ref ORIG_HEAD $orig_head
|
|
|
|
}
|
|
|
|
|
|
|
|
get_missing_commit_check_level () {
|
|
|
|
check_level=$(git config --get rebase.missingCommitsCheck)
|
|
|
|
check_level=${check_level:-ignore}
|
|
|
|
# Don't be case sensitive
|
|
|
|
printf '%s' "$check_level" | tr 'A-Z' 'a-z'
|
|
|
|
}
|
|
|
|
|
2014-04-11 12:28:17 +04:00
|
|
|
# The whole contents of this file is run by dot-sourcing it from
|
|
|
|
# inside a shell function. It used to be that "return"s we see
|
|
|
|
# below were not inside any function, and expected to return
|
|
|
|
# to the function that dot-sourced us.
|
|
|
|
#
|
2016-06-17 18:33:29 +03:00
|
|
|
# However, older (9.x) versions of FreeBSD /bin/sh misbehave on such a
|
|
|
|
# construct and continue to run the statements that follow such a "return".
|
2014-04-11 12:28:17 +04:00
|
|
|
# As a work-around, we introduce an extra layer of a function
|
|
|
|
# here, and immediately call it after defining it.
|
|
|
|
git_rebase__interactive () {
|
|
|
|
|
2011-02-06 21:43:39 +03:00
|
|
|
case "$action" in
|
|
|
|
continue)
|
2017-02-10 01:23:11 +03:00
|
|
|
if test ! -d "$rewritten"
|
|
|
|
then
|
|
|
|
exec git rebase--helper ${force_rebase:+--no-ff} --continue
|
|
|
|
fi
|
2011-02-06 21:43:39 +03:00
|
|
|
# do we have anything to commit?
|
2012-04-07 14:20:53 +04:00
|
|
|
if git diff-index --cached --quiet HEAD --
|
2011-02-06 21:43:39 +03:00
|
|
|
then
|
2015-06-18 19:38:53 +03:00
|
|
|
# Nothing to commit -- skip this commit
|
|
|
|
|
|
|
|
test ! -f "$GIT_DIR"/CHERRY_PICK_HEAD ||
|
|
|
|
rm "$GIT_DIR"/CHERRY_PICK_HEAD ||
|
2016-06-17 23:21:03 +03:00
|
|
|
die "$(gettext "Could not remove CHERRY_PICK_HEAD")"
|
2011-02-06 21:43:39 +03:00
|
|
|
else
|
2011-08-24 18:01:48 +04:00
|
|
|
if ! test -f "$author_script"
|
|
|
|
then
|
2014-02-10 05:03:37 +04:00
|
|
|
gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
|
2016-06-17 23:21:03 +03:00
|
|
|
die "$(eval_gettext "\
|
|
|
|
You have staged changes in your working tree.
|
|
|
|
If these changes are meant to be
|
2011-08-24 18:01:48 +04:00
|
|
|
squashed into the previous commit, run:
|
|
|
|
|
2016-06-17 23:21:03 +03:00
|
|
|
git commit --amend \$gpg_sign_opt_quoted
|
2011-08-24 18:01:48 +04:00
|
|
|
|
|
|
|
If they are meant to go into a new commit, run:
|
|
|
|
|
2016-06-17 23:21:03 +03:00
|
|
|
git commit \$gpg_sign_opt_quoted
|
2011-08-24 18:01:48 +04:00
|
|
|
|
2016-09-08 07:34:17 +03:00
|
|
|
In both cases, once you're done, continue with:
|
2011-08-24 18:01:48 +04:00
|
|
|
|
|
|
|
git rebase --continue
|
2016-06-17 23:21:03 +03:00
|
|
|
")"
|
2011-08-24 18:01:48 +04:00
|
|
|
fi
|
2011-02-06 21:43:39 +03:00
|
|
|
. "$author_script" ||
|
2016-06-17 23:21:03 +03:00
|
|
|
die "$(gettext "Error trying to find the author identity to amend commit")"
|
2011-02-06 21:43:39 +03:00
|
|
|
if test -f "$amend"
|
2007-12-20 10:12:12 +03:00
|
|
|
then
|
2011-02-06 21:43:39 +03:00
|
|
|
current_head=$(git rev-parse --verify HEAD)
|
|
|
|
test "$current_head" = $(cat "$amend") ||
|
2016-06-17 23:21:03 +03:00
|
|
|
die "$(gettext "\
|
|
|
|
You have uncommitted changes in your working tree. Please commit them
|
|
|
|
first and then run 'git rebase --continue' again.")"
|
2014-02-10 05:03:37 +04:00
|
|
|
do_with_author git commit --amend --no-verify -F "$msg" -e \
|
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2016-06-17 23:21:03 +03:00
|
|
|
die "$(gettext "Could not commit staged changes.")"
|
2012-07-24 16:17:03 +04:00
|
|
|
else
|
2014-02-10 05:03:37 +04:00
|
|
|
do_with_author git commit --no-verify -F "$msg" -e \
|
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2016-06-17 23:21:03 +03:00
|
|
|
die "$(gettext "Could not commit staged changes.")"
|
2007-12-20 10:12:12 +03:00
|
|
|
fi
|
2011-02-06 21:43:39 +03:00
|
|
|
fi
|
2007-07-08 06:01:29 +04:00
|
|
|
|
2015-05-22 16:15:49 +03:00
|
|
|
if test -r "$state_dir"/stopped-sha
|
|
|
|
then
|
|
|
|
record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
|
|
|
|
fi
|
2010-03-28 23:36:00 +04:00
|
|
|
|
2011-02-06 21:43:39 +03:00
|
|
|
require_clean_work_tree "rebase"
|
|
|
|
do_rest
|
2013-05-12 15:56:39 +04:00
|
|
|
return 0
|
2011-02-06 21:43:39 +03:00
|
|
|
;;
|
|
|
|
skip)
|
|
|
|
git rerere clear
|
|
|
|
|
2017-02-10 01:23:11 +03:00
|
|
|
if test ! -d "$rewritten"
|
|
|
|
then
|
|
|
|
exec git rebase--helper ${force_rebase:+--no-ff} --continue
|
|
|
|
fi
|
2011-02-06 21:43:52 +03:00
|
|
|
do_rest
|
2013-05-12 15:56:39 +04:00
|
|
|
return 0
|
2011-02-06 21:43:39 +03:00
|
|
|
;;
|
2012-09-18 05:28:09 +04:00
|
|
|
edit-todo)
|
2013-02-12 03:08:04 +04:00
|
|
|
git stripspace --strip-comments <"$todo" >"$todo".new
|
2012-09-18 05:28:09 +04:00
|
|
|
mv -f "$todo".new "$todo"
|
2013-08-24 04:10:42 +04:00
|
|
|
collapse_todo_ids
|
2012-09-18 05:28:09 +04:00
|
|
|
append_todo_help
|
2016-06-17 23:21:04 +03:00
|
|
|
gettext "
|
2013-02-12 03:08:04 +04:00
|
|
|
You are editing the todo file of an ongoing interactive rebase.
|
|
|
|
To continue rebase after editing, run:
|
|
|
|
git rebase --continue
|
|
|
|
|
2016-06-17 23:21:04 +03:00
|
|
|
" | git stripspace --comment-lines >>"$todo"
|
2012-09-18 05:28:09 +04:00
|
|
|
|
|
|
|
git_sequence_editor "$todo" ||
|
2016-06-17 23:21:03 +03:00
|
|
|
die "$(gettext "Could not execute editor")"
|
2013-08-24 04:10:42 +04:00
|
|
|
expand_todo_ids
|
2012-09-18 05:28:09 +04:00
|
|
|
|
|
|
|
exit
|
|
|
|
;;
|
2011-02-06 21:43:39 +03:00
|
|
|
esac
|
2007-06-25 04:11:14 +04:00
|
|
|
|
2011-02-06 21:43:35 +03:00
|
|
|
comment_for_reflog start
|
|
|
|
|
2011-02-06 21:43:42 +03:00
|
|
|
if test ! -z "$switch_to"
|
2011-02-06 21:43:35 +03:00
|
|
|
then
|
2013-06-16 12:45:13 +04:00
|
|
|
GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to"
|
2011-02-06 21:43:42 +03:00
|
|
|
output git checkout "$switch_to" -- ||
|
2016-06-17 23:21:03 +03:00
|
|
|
die "$(eval_gettext "Could not checkout \$switch_to")"
|
2013-06-16 12:45:13 +04:00
|
|
|
|
|
|
|
comment_for_reflog start
|
2011-02-06 21:43:35 +03:00
|
|
|
fi
|
|
|
|
|
2016-06-17 23:21:03 +03:00
|
|
|
orig_head=$(git rev-parse --verify HEAD) || die "$(gettext "No HEAD?")"
|
|
|
|
mkdir -p "$state_dir" || die "$(eval_gettext "Could not create temporary \$state_dir")"
|
2011-02-06 21:43:35 +03:00
|
|
|
|
2016-06-17 23:21:03 +03:00
|
|
|
: > "$state_dir"/interactive || die "$(gettext "Could not mark as interactive")"
|
2011-02-06 21:43:53 +03:00
|
|
|
write_basic_state
|
2011-02-06 21:43:37 +03:00
|
|
|
if test t = "$preserve_merges"
|
2011-02-06 21:43:35 +03:00
|
|
|
then
|
2011-02-06 21:43:37 +03:00
|
|
|
if test -z "$rebase_root"
|
2011-02-06 21:43:35 +03:00
|
|
|
then
|
2011-02-06 21:43:37 +03:00
|
|
|
mkdir "$rewritten" &&
|
2011-02-06 21:43:50 +03:00
|
|
|
for c in $(git merge-base --all $orig_head $upstream)
|
2008-10-15 11:44:38 +04:00
|
|
|
do
|
2011-02-06 21:43:37 +03:00
|
|
|
echo $onto > "$rewritten"/$c ||
|
2016-06-17 23:21:03 +03:00
|
|
|
die "$(gettext "Could not init rewritten commits")"
|
2008-10-15 11:44:38 +04:00
|
|
|
done
|
2011-02-06 21:43:35 +03:00
|
|
|
else
|
2011-02-06 21:43:37 +03:00
|
|
|
mkdir "$rewritten" &&
|
|
|
|
echo $onto > "$rewritten"/root ||
|
2016-06-17 23:21:03 +03:00
|
|
|
die "$(gettext "Could not init rewritten commits")"
|
2011-02-06 21:43:35 +03:00
|
|
|
fi
|
|
|
|
# No cherry-pick because our first pass is to determine
|
|
|
|
# parents to rewrite and skipping dropped commits would
|
|
|
|
# prematurely end our probe
|
2011-02-06 21:43:37 +03:00
|
|
|
merges_option=
|
2011-02-06 21:43:35 +03:00
|
|
|
else
|
2011-02-06 21:43:37 +03:00
|
|
|
merges_option="--no-merges --cherry-pick"
|
2011-02-06 21:43:35 +03:00
|
|
|
fi
|
|
|
|
|
2011-02-06 21:43:50 +03:00
|
|
|
shorthead=$(git rev-parse --short $orig_head)
|
2011-02-06 21:43:37 +03:00
|
|
|
shortonto=$(git rev-parse --short $onto)
|
|
|
|
if test -z "$rebase_root"
|
|
|
|
# this is now equivalent to ! -z "$upstream"
|
2011-02-06 21:43:35 +03:00
|
|
|
then
|
2011-02-06 21:43:37 +03:00
|
|
|
shortupstream=$(git rev-parse --short $upstream)
|
2011-02-06 21:43:50 +03:00
|
|
|
revisions=$upstream...$orig_head
|
2011-02-06 21:43:37 +03:00
|
|
|
shortrevisions=$shortupstream..$shorthead
|
2011-02-06 21:43:35 +03:00
|
|
|
else
|
2011-02-06 21:43:50 +03:00
|
|
|
revisions=$onto...$orig_head
|
2011-02-06 21:43:37 +03:00
|
|
|
shortrevisions=$shorthead
|
2011-02-06 21:43:35 +03:00
|
|
|
fi
|
2017-07-14 17:44:58 +03:00
|
|
|
if test t != "$preserve_merges"
|
|
|
|
then
|
|
|
|
git rebase--helper --make-script ${keep_empty:+--keep-empty} \
|
2017-12-23 02:55:38 +03:00
|
|
|
$revisions ${restrict_revision+^$restrict_revision} >"$todo" ||
|
|
|
|
die "$(gettext "Could not generate todo list")"
|
2017-07-14 17:44:58 +03:00
|
|
|
else
|
|
|
|
format=$(git config --get rebase.instructionFormat)
|
|
|
|
# the 'rev-list .. | sed' requires %m to parse; the instruction requires %H to parse
|
|
|
|
git rev-list $merges_option --format="%m%H ${format:-%s}" \
|
|
|
|
--reverse --left-right --topo-order \
|
|
|
|
$revisions ${restrict_revision+^$restrict_revision} | \
|
|
|
|
sed -n "s/^>//p" |
|
|
|
|
while read -r sha1 rest
|
|
|
|
do
|
|
|
|
|
|
|
|
if test -z "$keep_empty" && is_empty_commit $sha1 && ! is_merge_commit $sha1
|
|
|
|
then
|
|
|
|
comment_out="$comment_char "
|
|
|
|
else
|
|
|
|
comment_out=
|
|
|
|
fi
|
2012-04-20 18:36:17 +04:00
|
|
|
|
2011-02-06 21:43:37 +03:00
|
|
|
if test -z "$rebase_root"
|
2008-10-15 11:44:38 +04:00
|
|
|
then
|
2011-02-06 21:43:35 +03:00
|
|
|
preserve=t
|
|
|
|
for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
|
2008-10-15 11:44:38 +04:00
|
|
|
do
|
rebase -i -p: include non-first-parent commits in todo list
Consider this graph:
D---E (topic, HEAD)
/ /
A---B---C (master)
\
F (topic2)
and the following three commands:
1. git rebase -i -p A
2. git rebase -i -p --onto F A
3. git rebase -i -p B
Currently, (1) and (2) will pick B, D, C, and E onto A and F,
respectively. However, (3) will only pick D and E onto B, but not C,
which is inconsistent with (1) and (2). As a result, we cannot modify C
during the interactive-rebase.
The current behavior also creates a bug if we do:
4. git rebase -i -p C
In (4), E is never picked. And since interactive-rebase resets "HEAD"
to "onto" before picking any commits, D and E are lost after the
interactive-rebase.
This patch fixes the inconsistency and bug by ensuring that all children
of upstream are always picked. This essentially reverts the commit:
d80d6bc146232d81f1bb4bc58e5d89263fd228d4
When compiling the todo list, commits reachable from "upstream" should
never be skipped under any conditions. Otherwise, we lose the ability
to modify them like (3), and create a bug like (4).
Two of the tests contain a scenario like (3). Since the new behavior
added more commits for picking, these tests need to be updated to
account for the additional pick lines. A new test has also been added
for (4).
Signed-off-by: Andrew Wong <andrew.kw.w@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-06-19 02:12:01 +04:00
|
|
|
if test -f "$rewritten"/$p
|
2008-10-15 11:44:38 +04:00
|
|
|
then
|
2011-02-06 21:43:35 +03:00
|
|
|
preserve=f
|
2008-10-15 11:44:38 +04:00
|
|
|
fi
|
|
|
|
done
|
2011-02-06 21:43:35 +03:00
|
|
|
else
|
|
|
|
preserve=f
|
|
|
|
fi
|
|
|
|
if test f = "$preserve"
|
|
|
|
then
|
2011-02-06 21:43:37 +03:00
|
|
|
touch "$rewritten"/$sha1
|
2015-01-22 14:50:15 +03:00
|
|
|
printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo"
|
2008-10-15 11:44:38 +04:00
|
|
|
fi
|
2017-07-14 17:44:58 +03:00
|
|
|
done
|
|
|
|
fi
|
2009-01-03 01:28:28 +03:00
|
|
|
|
2011-02-06 21:43:35 +03:00
|
|
|
# Watch for commits that been dropped by --cherry-pick
|
2011-02-06 21:43:37 +03:00
|
|
|
if test t = "$preserve_merges"
|
2011-02-06 21:43:35 +03:00
|
|
|
then
|
2011-02-06 21:43:37 +03:00
|
|
|
mkdir "$dropped"
|
2011-02-06 21:43:35 +03:00
|
|
|
# Save all non-cherry-picked changes
|
2011-02-06 21:43:37 +03:00
|
|
|
git rev-list $revisions --left-right --cherry-pick | \
|
2011-02-06 21:43:50 +03:00
|
|
|
sed -n "s/^>//p" > "$state_dir"/not-cherry-picks
|
2011-02-06 21:43:35 +03:00
|
|
|
# Now all commits and note which ones are missing in
|
|
|
|
# not-cherry-picks and hence being dropped
|
2011-02-06 21:43:37 +03:00
|
|
|
git rev-list $revisions |
|
2011-02-06 21:43:35 +03:00
|
|
|
while read rev
|
|
|
|
do
|
2016-03-09 02:51:36 +03:00
|
|
|
if test -f "$rewritten"/$rev &&
|
|
|
|
! sane_grep "$rev" "$state_dir"/not-cherry-picks >/dev/null
|
2011-02-06 21:43:35 +03:00
|
|
|
then
|
|
|
|
# Use -f2 because if rev-list is telling us this commit is
|
|
|
|
# not worthwhile, we don't want to track its multiple heads,
|
|
|
|
# just the history of its first-parent for others that will
|
|
|
|
# be rebasing on top of it
|
2011-02-06 21:43:37 +03:00
|
|
|
git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$dropped"/$rev
|
2015-01-22 14:50:15 +03:00
|
|
|
sha1=$(git rev-list -1 $rev)
|
|
|
|
sane_grep -v "^[a-z][a-z]* $sha1" <"$todo" > "${todo}2" ; mv "${todo}2" "$todo"
|
2011-02-06 21:43:37 +03:00
|
|
|
rm "$rewritten"/$rev
|
2011-02-06 21:43:35 +03:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2011-02-06 21:43:37 +03:00
|
|
|
test -s "$todo" || echo noop >> "$todo"
|
2017-07-14 17:45:31 +03:00
|
|
|
test -z "$autosquash" || git rebase--helper --rearrange-squash || exit
|
2017-12-05 20:52:33 +03:00
|
|
|
test -n "$cmd" && git rebase--helper --add-exec-commands "$cmd"
|
2012-06-12 12:05:12 +04:00
|
|
|
|
2014-12-10 21:16:44 +03:00
|
|
|
todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
|
2015-03-04 10:53:04 +03:00
|
|
|
todocount=${todocount##* }
|
2014-12-10 21:16:44 +03:00
|
|
|
|
2013-02-12 03:08:04 +04:00
|
|
|
cat >>"$todo" <<EOF
|
2007-11-22 15:30:10 +03:00
|
|
|
|
2016-06-17 23:21:04 +03:00
|
|
|
$comment_char $(eval_ngettext \
|
|
|
|
"Rebase \$shortrevisions onto \$shortonto (\$todocount command)" \
|
|
|
|
"Rebase \$shortrevisions onto \$shortonto (\$todocount commands)" \
|
|
|
|
"$todocount")
|
2012-09-18 05:28:08 +04:00
|
|
|
EOF
|
|
|
|
append_todo_help
|
2016-06-17 23:21:04 +03:00
|
|
|
gettext "
|
2013-02-12 03:08:04 +04:00
|
|
|
However, if you remove everything, the rebase will be aborted.
|
|
|
|
|
2016-06-17 23:21:04 +03:00
|
|
|
" | git stripspace --comment-lines >>"$todo"
|
2007-06-25 04:11:14 +04:00
|
|
|
|
2012-04-20 18:36:17 +04:00
|
|
|
if test -z "$keep_empty"
|
|
|
|
then
|
2016-06-17 23:21:03 +03:00
|
|
|
printf '%s\n' "$comment_char $(gettext "Note that empty commits are commented out")" >>"$todo"
|
2012-04-20 18:36:17 +04:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2011-02-06 21:43:37 +03:00
|
|
|
has_action "$todo" ||
|
2014-05-20 02:05:20 +04:00
|
|
|
return 2
|
2007-06-25 04:11:14 +04:00
|
|
|
|
2011-02-06 21:43:37 +03:00
|
|
|
cp "$todo" "$todo".backup
|
2015-01-22 14:50:15 +03:00
|
|
|
collapse_todo_ids
|
2011-10-18 00:26:23 +04:00
|
|
|
git_sequence_editor "$todo" ||
|
2016-06-17 23:21:03 +03:00
|
|
|
die_abort "$(gettext "Could not execute editor")"
|
2007-06-25 04:11:14 +04:00
|
|
|
|
2011-02-06 21:43:37 +03:00
|
|
|
has_action "$todo" ||
|
2014-05-20 02:05:20 +04:00
|
|
|
return 2
|
2007-06-25 21:56:55 +04:00
|
|
|
|
2017-07-14 17:45:21 +03:00
|
|
|
git rebase--helper --check-todo-list || {
|
|
|
|
ret=$?
|
|
|
|
checkout_onto
|
|
|
|
exit $ret
|
|
|
|
}
|
2015-06-29 23:20:31 +03:00
|
|
|
|
2013-08-24 04:10:42 +04:00
|
|
|
expand_todo_ids
|
|
|
|
|
2017-07-14 17:45:25 +03:00
|
|
|
test -d "$rewritten" || test -n "$force_rebase" ||
|
|
|
|
onto="$(git rebase--helper --skip-unnecessary-picks)" ||
|
|
|
|
die "Could not skip unnecessary pick commands"
|
2009-03-03 12:55:31 +03:00
|
|
|
|
2015-06-29 23:20:31 +03:00
|
|
|
checkout_onto
|
2017-02-10 01:23:11 +03:00
|
|
|
if test -z "$rebase_root" && test ! -d "$rewritten"
|
|
|
|
then
|
|
|
|
require_clean_work_tree "rebase"
|
|
|
|
exec git rebase--helper ${force_rebase:+--no-ff} --continue
|
|
|
|
fi
|
2011-02-06 21:43:35 +03:00
|
|
|
do_rest
|
2014-04-11 12:28:17 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
# ... and then we call the whole thing.
|
|
|
|
git_rebase__interactive
|