2013-11-26 05:03:52 +08: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 08:11:14 +08:00
|
|
|
#
|
|
|
|
# Copyright (c) 2006 Johannes E. Schindelin
|
|
|
|
#
|
|
|
|
# The original idea comes from Eric W. Biederman, in
|
2017-05-08 09:38:59 +08:00
|
|
|
# https://public-inbox.org/git/m1odwkyuf5.fsf_-_@ebiederm.dsl.xmission.com/
|
2012-06-26 22:51:54 +08:00
|
|
|
#
|
2010-01-14 13:54:45 +08: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-07 02:43:37 +08:00
|
|
|
# file and written to the tail of $done.
|
2011-02-07 02:43:50 +08:00
|
|
|
todo="$state_dir"/git-rebase-todo
|
2010-01-14 13:54:45 +08: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-07 02:43:50 +08:00
|
|
|
done="$state_dir"/done
|
2010-01-14 13:54:45 +08:00
|
|
|
|
|
|
|
# The commit message that is planned to be used for any changes that
|
|
|
|
# need to be committed following a user interaction.
|
2011-02-07 02:43:50 +08:00
|
|
|
msg="$state_dir"/message
|
2010-01-14 13:54:45 +08: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-07 02:43:37 +08:00
|
|
|
# # This is a combination of $count commits.
|
|
|
|
# where $count is the number of commits whose messages have been
|
2010-01-14 13:54:45 +08: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-07 02:43:50 +08:00
|
|
|
squash_msg="$state_dir"/message-squash
|
2010-01-14 13:54:45 +08:00
|
|
|
|
2010-01-14 13:54:55 +08: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-07 02:43:50 +08:00
|
|
|
fixup_msg="$state_dir"/message-fixup
|
2010-01-14 13:54:55 +08:00
|
|
|
|
2011-02-07 02:43:37 +08: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 13:54:45 +08: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-07 02:43:50 +08:00
|
|
|
rewritten="$state_dir"/rewritten
|
2010-01-14 13:54:45 +08:00
|
|
|
|
2011-02-07 02:43:50 +08:00
|
|
|
dropped="$state_dir"/dropped
|
2010-01-14 13:54:46 +08:00
|
|
|
|
2013-04-25 17:28:54 +08:00
|
|
|
end="$state_dir"/end
|
|
|
|
msgnum="$state_dir"/msgnum
|
|
|
|
|
2010-01-14 13:54:46 +08: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-07 02:43:50 +08:00
|
|
|
author_script="$state_dir"/author-script
|
2010-01-14 13:54:46 +08:00
|
|
|
|
2010-01-14 13:54:47 +08: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-07 02:43:50 +08:00
|
|
|
amend="$state_dir"/amend
|
2010-01-14 13:54:47 +08:00
|
|
|
|
2010-03-13 01:04:30 +08: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-07 02:43:50 +08:00
|
|
|
rewritten_list="$state_dir"/rewritten-list
|
|
|
|
rewritten_pending="$state_dir"/rewritten-pending
|
2011-02-07 02:43:37 +08:00
|
|
|
|
2015-10-28 22:54:48 +08: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-12 04:30:36 +08:00
|
|
|
strategy_args=${strategy:+--strategy=$strategy}
|
2016-05-11 05:07:10 +08: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-12 04:30:36 +08: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 16:05:48 +08:00
|
|
|
|
2011-02-07 02:43:49 +08:00
|
|
|
GIT_CHERRY_PICK_HELP="$resolvemsg"
|
2007-11-28 16:06:36 +08:00
|
|
|
export GIT_CHERRY_PICK_HELP
|
|
|
|
|
2016-11-21 22:18:29 +08: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 07:08:04 +08:00
|
|
|
|
2007-06-25 08:11:14 +08:00
|
|
|
warn () {
|
2010-07-23 03:15:11 +08:00
|
|
|
printf '%s\n' "$*" >&2
|
2007-06-25 08:11:14 +08:00
|
|
|
}
|
|
|
|
|
2010-01-14 13:54:51 +08:00
|
|
|
# Output the commit message for the specified commit.
|
|
|
|
commit_message () {
|
|
|
|
git cat-file commit "$1" | sed "1,/^$/d"
|
|
|
|
}
|
|
|
|
|
2011-02-07 02:43:37 +08:00
|
|
|
orig_reflog_action="$GIT_REFLOG_ACTION"
|
2007-06-25 08:11:14 +08:00
|
|
|
|
|
|
|
comment_for_reflog () {
|
2011-02-07 02:43:37 +08:00
|
|
|
case "$orig_reflog_action" in
|
2007-06-25 08:11:14 +08:00
|
|
|
''|rebase*)
|
|
|
|
GIT_REFLOG_ACTION="rebase -i ($1)"
|
|
|
|
export GIT_REFLOG_ACTION
|
2007-09-25 23:42:51 +08:00
|
|
|
;;
|
2007-06-25 08:11:14 +08:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2008-01-15 12:01:21 +08:00
|
|
|
last_count=
|
2007-06-25 08:11:14 +08:00
|
|
|
mark_action_done () {
|
2011-02-07 02:43:37 +08:00
|
|
|
sed -e 1q < "$todo" >> "$done"
|
|
|
|
sed -e 1d < "$todo" >> "$todo".new
|
|
|
|
mv -f "$todo".new "$todo"
|
2016-07-29 01:47:23 +08:00
|
|
|
new_count=$(( $(git stripspace --strip-comments <"$done" | wc -l) ))
|
2013-04-25 17:28:54 +08:00
|
|
|
echo $new_count >"$msgnum"
|
2013-02-12 07:08:04 +08:00
|
|
|
total=$(($new_count + $(git stripspace --strip-comments <"$todo" | wc -l)))
|
2013-04-25 17:28:54 +08:00
|
|
|
echo $total >"$end"
|
2011-02-07 02:43:37 +08:00
|
|
|
if test "$last_count" != "$new_count"
|
2008-01-15 12:01:21 +08:00
|
|
|
then
|
2011-02-07 02:43:37 +08:00
|
|
|
last_count=$new_count
|
2016-06-18 04:21:03 +08:00
|
|
|
eval_gettext "Rebasing (\$new_count/\$total)"; printf "\r"
|
2011-02-07 02:43:37 +08:00
|
|
|
test -z "$verbose" || echo
|
2008-01-15 12:01:21 +08:00
|
|
|
fi
|
2007-06-25 08:11:14 +08:00
|
|
|
}
|
|
|
|
|
2015-04-29 06:55:20 +08: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 09:28:08 +08:00
|
|
|
append_todo_help () {
|
2016-06-18 04:21:04 +08:00
|
|
|
gettext "
|
2013-02-12 07:08:04 +08:00
|
|
|
Commands:
|
|
|
|
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
|
2016-06-18 04:21:04 +08:00
|
|
|
f, fixup = like \"squash\", but discard this commit's log message
|
2013-02-12 07:08:04 +08:00
|
|
|
x, exec = run command (the rest of the line) using shell
|
2015-06-30 04:20:30 +08:00
|
|
|
d, drop = remove commit
|
2013-02-12 07:08:04 +08:00
|
|
|
|
|
|
|
These lines can be re-ordered; they are executed from top to bottom.
|
2016-06-18 04:21:04 +08:00
|
|
|
" | git stripspace --comment-lines >>"$todo"
|
2013-02-12 07:08:04 +08:00
|
|
|
|
2015-06-30 04:20:31 +08:00
|
|
|
if test $(get_missing_commit_check_level) = error
|
|
|
|
then
|
2016-06-18 04:21:04 +08:00
|
|
|
gettext "
|
2015-06-30 04:20:31 +08:00
|
|
|
Do not remove any line. Use 'drop' explicitly to remove a commit.
|
2016-06-18 04:21:04 +08:00
|
|
|
" | git stripspace --comment-lines >>"$todo"
|
2015-06-30 04:20:31 +08:00
|
|
|
else
|
2016-06-18 04:21:04 +08:00
|
|
|
gettext "
|
2013-02-12 07:08:04 +08:00
|
|
|
If you remove a line here THAT COMMIT WILL BE LOST.
|
2016-06-18 04:21:04 +08:00
|
|
|
" | git stripspace --comment-lines >>"$todo"
|
2015-06-30 04:20:31 +08:00
|
|
|
fi
|
2012-09-18 09:28:08 +08:00
|
|
|
}
|
|
|
|
|
2007-06-25 08:11:14 +08:00
|
|
|
make_patch () {
|
2008-12-23 05:16:51 +08: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-07 02:43:50 +08:00
|
|
|
esac > "$state_dir"/patch
|
2011-02-07 02:43:37 +08:00
|
|
|
test -f "$msg" ||
|
|
|
|
commit_message "$1" > "$msg"
|
|
|
|
test -f "$author_script" ||
|
|
|
|
get_author_ident_from_commit "$1" > "$author_script"
|
2007-06-25 08:11:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
die_with_patch () {
|
2011-02-07 02:43:50 +08:00
|
|
|
echo "$1" > "$state_dir"/stopped-sha
|
2007-06-25 08:11:14 +08:00
|
|
|
make_patch "$1"
|
|
|
|
die "$2"
|
|
|
|
}
|
|
|
|
|
2011-11-30 23:52:51 +08:00
|
|
|
exit_with_patch () {
|
|
|
|
echo "$1" > "$state_dir"/stopped-sha
|
|
|
|
make_patch $1
|
|
|
|
git rev-parse --verify HEAD > "$amend"
|
2014-02-10 09:03:37 +08:00
|
|
|
gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
|
2016-06-18 04:21:03 +08: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 23:52:51 +08:00
|
|
|
warn
|
|
|
|
exit $2
|
|
|
|
}
|
|
|
|
|
2007-06-26 01:56:55 +08:00
|
|
|
die_abort () {
|
2016-06-29 14:21:27 +08:00
|
|
|
apply_autostash
|
2011-02-07 02:43:50 +08:00
|
|
|
rm -rf "$state_dir"
|
2007-06-26 01:56:55 +08:00
|
|
|
die "$1"
|
|
|
|
}
|
|
|
|
|
2007-09-25 23:42:51 +08:00
|
|
|
has_action () {
|
2013-02-12 07:08:04 +08:00
|
|
|
test -n "$(git stripspace --strip-comments <"$1")"
|
2007-09-25 23:42:51 +08:00
|
|
|
}
|
|
|
|
|
2012-04-20 22:36:17 +08:00
|
|
|
is_empty_commit() {
|
2016-06-18 04:21:03 +08: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 22:36:17 +08:00
|
|
|
test "$tree" = "$ptree"
|
|
|
|
}
|
|
|
|
|
2013-01-13 04:46:01 +08:00
|
|
|
is_merge_commit()
|
|
|
|
{
|
|
|
|
git rev-parse --verify --quiet "$1"^2 >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
2010-01-14 13:54:53 +08: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 05:09:24 +08:00
|
|
|
(
|
|
|
|
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
|
|
|
|
"$@"
|
|
|
|
)
|
2010-01-14 13:54:53 +08:00
|
|
|
}
|
|
|
|
|
2011-10-18 04:26:23 +08: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 08:11:14 +08:00
|
|
|
pick_one () {
|
2010-03-07 04:34:46 +08:00
|
|
|
ff=--ff
|
2012-04-20 22:36:17 +08:00
|
|
|
|
2010-03-07 04:34:46 +08:00
|
|
|
case "$1" in -n) sha1=$2; ff= ;; *) sha1=$1 ;; esac
|
2011-02-07 02:43:37 +08:00
|
|
|
case "$force_rebase" in '') ;; ?*) ff= ;; esac
|
2016-06-18 04:21:03 +08:00
|
|
|
output git rev-parse --verify $sha1 || die "$(eval_gettext "Invalid commit name: \$sha1")"
|
2012-04-20 22:36:17 +08:00
|
|
|
|
|
|
|
if is_empty_commit "$sha1"
|
|
|
|
then
|
|
|
|
empty_args="--allow-empty"
|
|
|
|
fi
|
|
|
|
|
2011-02-07 02:43:37 +08:00
|
|
|
test -d "$rewritten" &&
|
2007-06-26 01:59:43 +08:00
|
|
|
pick_one_preserving_merges "$@" && return
|
2014-02-10 09:03:37 +08:00
|
|
|
output eval git cherry-pick \
|
|
|
|
${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \
|
|
|
|
"$strategy_args" $empty_args $ff "$@"
|
2015-04-29 06:55:20 +08: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 08:11:14 +08:00
|
|
|
}
|
|
|
|
|
2007-06-26 01:59:43 +08:00
|
|
|
pick_one_preserving_merges () {
|
2008-08-14 05:41:23 +08:00
|
|
|
fast_forward=t
|
|
|
|
case "$1" in
|
|
|
|
-n)
|
|
|
|
fast_forward=f
|
|
|
|
sha1=$2
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
sha1=$1
|
|
|
|
;;
|
|
|
|
esac
|
2007-06-26 01:59:43 +08:00
|
|
|
sha1=$(git rev-parse $sha1)
|
|
|
|
|
2011-02-07 02:43:50 +08:00
|
|
|
if test -f "$state_dir"/current-commit
|
2007-06-26 01:59:43 +08:00
|
|
|
then
|
2008-10-23 02:59:30 +08:00
|
|
|
if test "$fast_forward" = t
|
2008-10-15 15:44:36 +08:00
|
|
|
then
|
2010-07-06 13:16:15 +08:00
|
|
|
while read current_commit
|
2008-10-15 15:44:36 +08:00
|
|
|
do
|
2011-02-07 02:43:37 +08:00
|
|
|
git rev-parse HEAD > "$rewritten"/$current_commit
|
2011-02-07 02:43:50 +08:00
|
|
|
done <"$state_dir"/current-commit
|
|
|
|
rm "$state_dir"/current-commit ||
|
2016-06-18 04:21:03 +08:00
|
|
|
die "$(gettext "Cannot write current commit's replacement sha1")"
|
2008-10-15 15:44:36 +08:00
|
|
|
fi
|
2007-06-26 01:59:43 +08:00
|
|
|
fi
|
|
|
|
|
2011-02-07 02:43:50 +08:00
|
|
|
echo $sha1 >> "$state_dir"/current-commit
|
2008-08-14 05:41:24 +08:00
|
|
|
|
2007-06-26 01:59:43 +08:00
|
|
|
# rewrite parents; if none were rewritten, we can fast-forward.
|
|
|
|
new_parents=
|
2009-01-03 06:28:28 +08:00
|
|
|
pend=" $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)"
|
|
|
|
if test "$pend" = " "
|
|
|
|
then
|
|
|
|
pend=" root"
|
|
|
|
fi
|
2008-10-06 12:26:52 +08:00
|
|
|
while [ "$pend" != "" ]
|
2007-06-26 01:59:43 +08:00
|
|
|
do
|
2008-10-06 12:26:52 +08:00
|
|
|
p=$(expr "$pend" : ' \([^ ]*\)')
|
|
|
|
pend="${pend# $p}"
|
|
|
|
|
2011-02-07 02:43:37 +08:00
|
|
|
if test -f "$rewritten"/$p
|
2007-06-26 01:59:43 +08:00
|
|
|
then
|
2011-02-07 02:43:37 +08:00
|
|
|
new_p=$(cat "$rewritten"/$p)
|
2008-10-15 15:44:40 +08: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-26 01:59:43 +08: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 23:42:51 +08:00
|
|
|
;;
|
2007-06-26 01:59:43 +08:00
|
|
|
esac
|
2008-07-16 09:51:49 +08:00
|
|
|
else
|
2011-02-07 02:43:37 +08:00
|
|
|
if test -f "$dropped"/$p
|
2008-10-06 12:26:52 +08:00
|
|
|
then
|
|
|
|
fast_forward=f
|
2011-02-07 02:43:37 +08:00
|
|
|
replacement="$(cat "$dropped"/$p)"
|
2009-01-03 06:28:28 +08:00
|
|
|
test -z "$replacement" && replacement=root
|
|
|
|
pend=" $replacement$pend"
|
2008-10-06 12:26:52 +08:00
|
|
|
else
|
|
|
|
new_parents="$new_parents $p"
|
|
|
|
fi
|
2007-06-26 01:59:43 +08:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
case $fast_forward in
|
|
|
|
t)
|
2016-06-18 04:21:03 +08:00
|
|
|
output warn "$(eval_gettext "Fast-forward to \$sha1")"
|
2008-08-14 05:41:23 +08:00
|
|
|
output git reset --hard $sha1 ||
|
2016-06-18 04:21:03 +08:00
|
|
|
die "$(eval_gettext "Cannot fast-forward to \$sha1")"
|
2007-06-26 01:59:43 +08:00
|
|
|
;;
|
|
|
|
f)
|
2007-09-25 23:42:51 +08:00
|
|
|
first_parent=$(expr "$new_parents" : ' \([^ ]*\)')
|
2008-10-15 15:44:37 +08:00
|
|
|
|
|
|
|
if [ "$1" != "-n" ]
|
|
|
|
then
|
|
|
|
# detach HEAD to current parent
|
|
|
|
output git checkout $first_parent 2> /dev/null ||
|
2016-06-18 04:21:03 +08:00
|
|
|
die "$(eval_gettext "Cannot move HEAD to \$first_parent")"
|
2008-10-15 15:44:37 +08:00
|
|
|
fi
|
2007-06-26 01:59:43 +08:00
|
|
|
|
|
|
|
case "$new_parents" in
|
2007-09-25 23:42:51 +08:00
|
|
|
' '*' '*)
|
2016-06-18 04:21:03 +08:00
|
|
|
test "a$1" = a-n && die "$(eval_gettext "Refusing to squash a merge: \$sha1")"
|
2008-10-15 15:44:37 +08:00
|
|
|
|
2007-06-26 01:59:43 +08:00
|
|
|
# redo merge
|
2011-02-07 02:43:37 +08:00
|
|
|
author_script_content=$(get_author_ident_from_commit $sha1)
|
|
|
|
eval "$author_script_content"
|
|
|
|
msg_content="$(commit_message $sha1)"
|
2007-10-31 10:20:32 +08:00
|
|
|
# No point in merging the first parent, that's HEAD
|
|
|
|
new_parents=${new_parents# $first_parent}
|
2013-08-22 02:48:57 +08:00
|
|
|
merge_args="--no-log --no-ff"
|
2013-07-02 16:05:48 +08:00
|
|
|
if ! do_with_author output eval \
|
2014-02-10 09:03:37 +08:00
|
|
|
'git merge ${gpg_sign_opt:+"$gpg_sign_opt"} \
|
|
|
|
$merge_args $strategy_args -m "$msg_content" $new_parents'
|
2007-06-26 01:59:43 +08:00
|
|
|
then
|
2011-02-07 02:43:37 +08:00
|
|
|
printf "%s\n" "$msg_content" > "$GIT_DIR"/MERGE_MSG
|
2016-06-18 04:21:03 +08:00
|
|
|
die_with_patch $sha1 "$(eval_gettext "Error redoing merge \$sha1")"
|
2007-06-26 01:59:43 +08:00
|
|
|
fi
|
2011-02-07 02:43:37 +08:00
|
|
|
echo "$sha1 $(git rev-parse HEAD^0)" >> "$rewritten_list"
|
2007-06-26 01:59:43 +08:00
|
|
|
;;
|
|
|
|
*)
|
2014-02-10 09:03:37 +08:00
|
|
|
output eval git cherry-pick \
|
|
|
|
${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \
|
|
|
|
"$strategy_args" "$@" ||
|
2016-06-18 04:21:03 +08:00
|
|
|
die_with_patch $sha1 "$(eval_gettext "Could not pick \$sha1")"
|
2007-09-25 23:42:51 +08:00
|
|
|
;;
|
2007-06-26 01:59:43 +08:00
|
|
|
esac
|
2007-09-25 23:42:51 +08:00
|
|
|
;;
|
2007-06-26 01:59:43 +08:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2016-06-18 04:21:05 +08:00
|
|
|
this_nth_commit_message () {
|
|
|
|
n=$1
|
2016-08-21 22:50:38 +08:00
|
|
|
eval_gettext "This is the commit message #\${n}:"
|
2016-06-18 04:21:05 +08:00
|
|
|
}
|
2016-08-21 22:50:38 +08:00
|
|
|
|
2016-06-18 04:21:05 +08:00
|
|
|
skip_nth_commit_message () {
|
|
|
|
n=$1
|
2016-08-21 22:50:38 +08:00
|
|
|
eval_gettext "The commit message #\${n} will be skipped:"
|
2007-07-22 01:09:41 +08:00
|
|
|
}
|
|
|
|
|
2010-01-14 13:54:55 +08:00
|
|
|
update_squash_messages () {
|
2011-02-07 02:43:37 +08: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 16:23:19 +08:00
|
|
|
-e "1s/^$comment_char[^0-9]*\([0-9][0-9]*\).*/\1/p" \
|
2011-02-07 02:43:37 +08:00
|
|
|
-e "q" < "$squash_msg".bak)+1))
|
2010-01-14 13:54:54 +08:00
|
|
|
{
|
2016-06-18 04:21:05 +08: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 13:54:54 +08:00
|
|
|
sed -e 1d -e '2,/^./{
|
|
|
|
/^$/d
|
2011-02-07 02:43:37 +08:00
|
|
|
}' <"$squash_msg".bak
|
|
|
|
} >"$squash_msg"
|
2007-07-22 01:09:41 +08:00
|
|
|
else
|
2016-12-21 01:36:23 +08:00
|
|
|
commit_message HEAD >"$fixup_msg" ||
|
|
|
|
die "$(eval_gettext "Cannot write \$fixup_msg")"
|
2011-02-07 02:43:37 +08:00
|
|
|
count=2
|
2010-01-14 13:54:54 +08:00
|
|
|
{
|
2016-06-18 04:21:05 +08: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 13:54:54 +08:00
|
|
|
echo
|
2011-02-07 02:43:37 +08:00
|
|
|
cat "$fixup_msg"
|
|
|
|
} >"$squash_msg"
|
2007-07-22 01:09:41 +08:00
|
|
|
fi
|
2009-12-07 17:20:59 +08:00
|
|
|
case $1 in
|
|
|
|
squash)
|
2011-02-07 02:43:37 +08:00
|
|
|
rm -f "$fixup_msg"
|
2009-12-07 17:20:59 +08:00
|
|
|
echo
|
2016-06-18 04:21:05 +08:00
|
|
|
printf '%s\n' "$comment_char $(this_nth_commit_message $count)"
|
2009-12-07 17:20:59 +08:00
|
|
|
echo
|
2010-01-14 13:54:51 +08:00
|
|
|
commit_message $2
|
2009-12-07 17:20:59 +08:00
|
|
|
;;
|
|
|
|
fixup)
|
|
|
|
echo
|
2016-06-18 04:21:05 +08:00
|
|
|
printf '%s\n' "$comment_char $(skip_nth_commit_message $count)"
|
2009-12-07 17:20:59 +08:00
|
|
|
echo
|
2013-02-12 07:08:04 +08:00
|
|
|
# Change the space after the comment character to TAB:
|
|
|
|
commit_message $2 | git stripspace --comment-lines | sed -e 's/ / /'
|
2009-12-07 17:20:59 +08:00
|
|
|
;;
|
2011-02-07 02:43:37 +08:00
|
|
|
esac >>"$squash_msg"
|
2007-07-22 01:09:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
peek_next_command () {
|
2013-02-12 07:08:04 +08:00
|
|
|
git stripspace --strip-comments <"$todo" | sed -n -e 's/ .*//p' -e q
|
2007-07-22 01:09:41 +08:00
|
|
|
}
|
|
|
|
|
2010-01-14 13:54:57 +08: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-18 04:21:03 +08:00
|
|
|
sha1=$1
|
|
|
|
rest=$2
|
2011-02-07 02:43:37 +08:00
|
|
|
mv "$squash_msg" "$msg" || exit
|
|
|
|
rm -f "$fixup_msg"
|
|
|
|
cp "$msg" "$GIT_DIR"/MERGE_MSG || exit
|
2010-01-14 13:54:57 +08:00
|
|
|
warn
|
2016-06-18 04:21:03 +08:00
|
|
|
warn "$(eval_gettext "Could not apply \$sha1... \$rest")"
|
|
|
|
die_with_patch $sha1 ""
|
2010-01-14 13:54:57 +08:00
|
|
|
}
|
|
|
|
|
2010-03-13 01:04:30 +08:00
|
|
|
flush_rewritten_pending() {
|
2011-02-07 02:43:37 +08:00
|
|
|
test -s "$rewritten_pending" || return
|
2010-03-13 01:04:30 +08:00
|
|
|
newsha1="$(git rev-parse HEAD^0)"
|
2011-02-07 02:43:37 +08:00
|
|
|
sed "s/$/ $newsha1/" < "$rewritten_pending" >> "$rewritten_list"
|
|
|
|
rm -f "$rewritten_pending"
|
2010-03-13 01:04:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
record_in_rewritten() {
|
|
|
|
oldsha1="$(git rev-parse $1)"
|
2011-02-07 02:43:37 +08:00
|
|
|
echo "$oldsha1" >> "$rewritten_pending"
|
2010-03-13 01:04:30 +08:00
|
|
|
|
|
|
|
case "$(peek_next_command)" in
|
2010-07-06 13:16:15 +08:00
|
|
|
squash|s|fixup|f)
|
2010-03-13 01:04:30 +08:00
|
|
|
;;
|
2010-07-06 13:16:15 +08:00
|
|
|
*)
|
2010-03-13 01:04:30 +08:00
|
|
|
flush_rewritten_pending
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2012-06-27 05:55:23 +08:00
|
|
|
do_pick () {
|
2016-06-18 04:21:03 +08:00
|
|
|
sha1=$1
|
|
|
|
rest=$2
|
2012-06-27 05:55:23 +08: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-18 04:21:03 +08:00
|
|
|
--no-post-rewrite -n -q -C $sha1 &&
|
|
|
|
pick_one -n $sha1 &&
|
2012-06-27 05:55:23 +08:00
|
|
|
git commit --allow-empty --allow-empty-message \
|
2016-06-18 04:21:03 +08:00
|
|
|
--amend --no-post-rewrite -n -q -C $sha1 \
|
2014-02-10 09:03:37 +08:00
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2016-06-18 04:21:03 +08:00
|
|
|
die_with_patch $sha1 "$(eval_gettext "Could not apply \$sha1... \$rest")"
|
2012-06-27 05:55:23 +08:00
|
|
|
else
|
2016-06-18 04:21:03 +08:00
|
|
|
pick_one $sha1 ||
|
|
|
|
die_with_patch $sha1 "$(eval_gettext "Could not apply \$sha1... \$rest")"
|
2012-06-27 05:55:23 +08:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2007-06-25 08:11:14 +08:00
|
|
|
do_next () {
|
2015-05-22 21:15:49 +08:00
|
|
|
rm -f "$msg" "$author_script" "$amend" "$state_dir"/stopped-sha || exit
|
2011-02-07 02:43:37 +08:00
|
|
|
read -r command sha1 rest < "$todo"
|
2007-06-25 08:11:14 +08:00
|
|
|
case "$command" in
|
2015-06-30 04:20:30 +08:00
|
|
|
"$comment_char"*|''|noop|drop|d)
|
2007-06-25 08:11:14 +08:00
|
|
|
mark_action_done
|
|
|
|
;;
|
2015-10-28 22:54:48 +08:00
|
|
|
"$cr")
|
|
|
|
# Work around CR left by "read" (e.g. with Git for Windows' Bash).
|
|
|
|
mark_action_done
|
|
|
|
;;
|
2007-09-29 10:32:11 +08:00
|
|
|
pick|p)
|
2007-06-25 08:11:14 +08:00
|
|
|
comment_for_reflog pick
|
|
|
|
|
|
|
|
mark_action_done
|
2012-06-27 05:55:23 +08:00
|
|
|
do_pick $sha1 "$rest"
|
2010-03-13 01:04:30 +08:00
|
|
|
record_in_rewritten $sha1
|
2007-06-25 08:11:14 +08:00
|
|
|
;;
|
2009-10-07 14:13:23 +08:00
|
|
|
reword|r)
|
|
|
|
comment_for_reflog reword
|
|
|
|
|
|
|
|
mark_action_done
|
2012-06-27 05:55:23 +08:00
|
|
|
do_pick $sha1 "$rest"
|
2014-02-10 09:03:37 +08:00
|
|
|
git commit --amend --no-post-rewrite ${gpg_sign_opt:+"$gpg_sign_opt"} || {
|
2016-06-18 04:21:03 +08: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 23:52:51 +08:00
|
|
|
exit_with_patch $sha1 1
|
|
|
|
}
|
2010-03-13 01:04:30 +08:00
|
|
|
record_in_rewritten $sha1
|
2009-10-07 14:13:23 +08:00
|
|
|
;;
|
2007-09-29 10:32:11 +08:00
|
|
|
edit|e)
|
2007-06-25 08:11:14 +08:00
|
|
|
comment_for_reflog edit
|
|
|
|
|
|
|
|
mark_action_done
|
2012-06-27 05:55:23 +08:00
|
|
|
do_pick $sha1 "$rest"
|
2016-03-29 00:00:00 +08:00
|
|
|
sha1_abbrev=$(git rev-parse --short $sha1)
|
2016-06-18 04:21:03 +08:00
|
|
|
warn "$(eval_gettext "Stopped at \$sha1_abbrev... \$rest")"
|
2011-11-30 23:52:51 +08:00
|
|
|
exit_with_patch $sha1 0
|
2007-06-25 08:11:14 +08:00
|
|
|
;;
|
2009-12-07 17:20:59 +08: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 08:11:14 +08:00
|
|
|
|
2011-02-07 02:43:37 +08:00
|
|
|
test -f "$done" && has_action "$done" ||
|
2016-06-18 04:21:03 +08:00
|
|
|
die "$(eval_gettext "Cannot '\$squash_style' without a previous commit")"
|
2007-06-25 08:11:14 +08:00
|
|
|
|
|
|
|
mark_action_done
|
2010-01-14 13:54:55 +08:00
|
|
|
update_squash_messages $squash_style $sha1
|
2011-02-07 02:43:37 +08:00
|
|
|
author_script_content=$(get_author_ident_from_commit HEAD)
|
|
|
|
echo "$author_script_content" > "$author_script"
|
|
|
|
eval "$author_script_content"
|
2012-07-24 20:17:03 +08:00
|
|
|
if ! pick_one -n $sha1
|
|
|
|
then
|
|
|
|
git rev-parse --verify HEAD >"$amend"
|
|
|
|
die_failed_squash $sha1 "$rest"
|
|
|
|
fi
|
2007-07-22 01:09:41 +08:00
|
|
|
case "$(peek_next_command)" in
|
2009-12-07 17:20:59 +08:00
|
|
|
squash|s|fixup|f)
|
2010-01-14 13:54:55 +08:00
|
|
|
# This is an intermediate commit; its message will only be
|
|
|
|
# used in case of trouble. So use the long version:
|
2014-02-10 09:03:37 +08:00
|
|
|
do_with_author output git commit --amend --no-verify -F "$squash_msg" \
|
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2010-01-14 13:54:57 +08:00
|
|
|
die_failed_squash $sha1 "$rest"
|
2007-09-25 23:42:51 +08:00
|
|
|
;;
|
2007-07-22 01:09:41 +08:00
|
|
|
*)
|
2010-01-14 13:54:55 +08:00
|
|
|
# This is the final command of this squash/fixup group
|
2011-02-07 02:43:37 +08:00
|
|
|
if test -f "$fixup_msg"
|
2010-01-14 13:54:55 +08:00
|
|
|
then
|
2014-02-10 09:03:37 +08:00
|
|
|
do_with_author git commit --amend --no-verify -F "$fixup_msg" \
|
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2010-01-14 13:54:57 +08:00
|
|
|
die_failed_squash $sha1 "$rest"
|
|
|
|
else
|
2011-02-07 02:43:37 +08:00
|
|
|
cp "$squash_msg" "$GIT_DIR"/SQUASH_MSG || exit
|
2010-01-14 13:54:57 +08:00
|
|
|
rm -f "$GIT_DIR"/MERGE_MSG
|
2014-02-10 09:03:37 +08:00
|
|
|
do_with_author git commit --amend --no-verify -F "$GIT_DIR"/SQUASH_MSG -e \
|
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2010-01-14 13:54:57 +08:00
|
|
|
die_failed_squash $sha1 "$rest"
|
2010-01-14 13:54:55 +08:00
|
|
|
fi
|
2011-02-07 02:43:37 +08:00
|
|
|
rm -f "$squash_msg" "$fixup_msg"
|
2007-09-25 23:42:51 +08:00
|
|
|
;;
|
2007-07-22 01:09:41 +08:00
|
|
|
esac
|
2010-03-13 01:04:30 +08:00
|
|
|
record_in_rewritten $sha1
|
2007-06-25 08:11:14 +08:00
|
|
|
;;
|
2010-08-10 23:17:51 +08:00
|
|
|
x|"exec")
|
2011-02-07 02:43:37 +08:00
|
|
|
read -r command rest < "$todo"
|
2010-08-10 23:17:51 +08:00
|
|
|
mark_action_done
|
2016-06-18 04:21:03 +08:00
|
|
|
eval_gettextln "Executing: \$rest"
|
2015-11-13 14:03:19 +08:00
|
|
|
"${SHELL:-@SHELL_PATH@}" -c "$rest" # Actual execution
|
2010-08-10 23:17:51 +08:00
|
|
|
status=$?
|
2011-08-25 02:54:50 +08: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 23:17:51 +08:00
|
|
|
if test "$status" -ne 0
|
|
|
|
then
|
2016-06-18 04:21:03 +08:00
|
|
|
warn "$(eval_gettext "Execution failed: \$rest")"
|
2011-08-25 02:54:50 +08:00
|
|
|
test "$dirty" = f ||
|
2016-06-18 04:21:03 +08:00
|
|
|
warn "$(gettext "and made changes to the index and/or the working tree")"
|
2011-08-25 02:54:50 +08:00
|
|
|
|
2016-06-18 04:21:03 +08:00
|
|
|
warn "$(gettext "\
|
|
|
|
You can fix the problem, and then run
|
|
|
|
|
|
|
|
git rebase --continue")"
|
2010-08-10 23:17:51 +08:00
|
|
|
warn
|
2012-09-18 19:15:26 +08:00
|
|
|
if test $status -eq 127 # command not found
|
|
|
|
then
|
|
|
|
status=1
|
|
|
|
fi
|
2010-08-10 23:17:51 +08:00
|
|
|
exit "$status"
|
2011-08-25 02:54:50 +08:00
|
|
|
elif test "$dirty" = t
|
2010-08-10 23:17:51 +08:00
|
|
|
then
|
2016-06-18 04:21:03 +08: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 23:17:51 +08:00
|
|
|
warn
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2007-06-25 08:11:14 +08:00
|
|
|
*)
|
2016-06-18 04:21:03 +08:00
|
|
|
warn "$(eval_gettext "Unknown command: \$command \$sha1 \$rest")"
|
|
|
|
fixtodo="$(gettext "Please fix this using 'git rebase --edit-todo'.")"
|
2009-10-27 22:58:14 +08:00
|
|
|
if git rev-parse --verify -q "$sha1" >/dev/null
|
|
|
|
then
|
2012-09-19 14:43:54 +08:00
|
|
|
die_with_patch $sha1 "$fixtodo"
|
2009-10-27 22:58:14 +08:00
|
|
|
else
|
2012-09-19 14:43:54 +08:00
|
|
|
die "$fixtodo"
|
2009-10-27 22:58:14 +08:00
|
|
|
fi
|
2007-09-25 23:42:51 +08:00
|
|
|
;;
|
2007-06-25 08:11:14 +08:00
|
|
|
esac
|
2011-02-07 02:43:37 +08:00
|
|
|
test -s "$todo" && return
|
2007-06-25 08:11:14 +08:00
|
|
|
|
2007-06-26 01:58:28 +08:00
|
|
|
comment_for_reflog finish &&
|
2011-02-07 02:43:37 +08:00
|
|
|
newhead=$(git rev-parse HEAD) &&
|
2011-02-07 02:43:50 +08:00
|
|
|
case $head_name in
|
2007-09-25 23:43:15 +08:00
|
|
|
refs/*)
|
2012-08-10 14:51:19 +08:00
|
|
|
message="$GIT_REFLOG_ACTION: $head_name onto $onto" &&
|
2011-02-07 02:43:50 +08:00
|
|
|
git update-ref -m "$message" $head_name $newhead $orig_head &&
|
2011-05-28 04:16:14 +08:00
|
|
|
git symbolic-ref \
|
|
|
|
-m "$GIT_REFLOG_ACTION: returning to $head_name" \
|
|
|
|
HEAD $head_name
|
2007-09-25 23:43:15 +08:00
|
|
|
;;
|
|
|
|
esac && {
|
2011-02-07 02:43:50 +08:00
|
|
|
test ! -f "$state_dir"/verbose ||
|
2011-02-07 02:43:52 +08:00
|
|
|
git diff-tree --stat $orig_head..HEAD
|
2007-07-08 10:02:13 +08:00
|
|
|
} &&
|
2010-03-13 01:04:33 +08:00
|
|
|
{
|
2011-02-07 02:43:37 +08:00
|
|
|
test -s "$rewritten_list" &&
|
|
|
|
git notes copy --for-rewrite=rebase < "$rewritten_list" ||
|
2010-03-13 01:04:33 +08:00
|
|
|
true # we don't care if this copying failed
|
|
|
|
} &&
|
2014-11-30 16:24:38 +08: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-13 01:04:30 +08:00
|
|
|
true # we don't care if this hook failed
|
|
|
|
fi &&
|
2016-06-18 04:21:03 +08:00
|
|
|
warn "$(eval_gettext "Successfully rebased and updated \$head_name.")"
|
2007-06-25 08:11:14 +08:00
|
|
|
|
2013-05-12 19:56:39 +08:00
|
|
|
return 1 # not failure; just to break the do_rest loop
|
2007-06-25 08:11:14 +08:00
|
|
|
}
|
|
|
|
|
2013-05-12 19:56:39 +08:00
|
|
|
# can only return 0, when the infinite loop breaks
|
2007-06-25 08:11:14 +08:00
|
|
|
do_rest () {
|
|
|
|
while :
|
|
|
|
do
|
2013-05-12 19:56:39 +08:00
|
|
|
do_next || break
|
2007-06-25 08:11:14 +08:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2009-03-03 17:55:31 +08:00
|
|
|
# skip picking commits whose parents are unchanged
|
|
|
|
skip_unnecessary_picks () {
|
|
|
|
fd=3
|
git-rebase--interactive.sh: rework skip_unnecessary_picks
Commit cd035b1c introduced the exec command to interactive rebase. In
doing so, it modified the way that skip_unnecessary_picks iterates through
the list of rebase commands so that it avoided collapsing multiple spaces
into a single space. This is necessary for example if the argument to the
exec command contains a path with multiple spaces in it.
The way it did this was by reading each line of rebase commands into a
single variable, and then breaking the individual components out using
echo, sed, and cut. It used the individual broken-out components for
decision making, and was still able to write the original line to the
output file from the variable it had saved it in. But, since we only
really need to look at anything other than the first element of the line
when a 'pick' command is encountered, and even that is only necessary when
we are still searching for "unnecessary" picks, and since newer rebase
commands like 'exec' may not even require a sha1 field, let's make our read
statement parse its input into a "command" variable, and a "rest" variable,
and then only break out the sha1 from $rest, and call git-rev-parse, when
absolutely necessary.
I think this future proofs this subroutine, avoids calling git-rev-parse
unnecessarily, and possibly with bogus arguments, and still accomplishes
the goal of not mangling the $rest of the rebase command.
Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-08-14 04:47:34 +08:00
|
|
|
while read -r command rest
|
2009-03-03 17:55:31 +08:00
|
|
|
do
|
|
|
|
# fd=3 means we skip the command
|
git-rebase--interactive.sh: rework skip_unnecessary_picks
Commit cd035b1c introduced the exec command to interactive rebase. In
doing so, it modified the way that skip_unnecessary_picks iterates through
the list of rebase commands so that it avoided collapsing multiple spaces
into a single space. This is necessary for example if the argument to the
exec command contains a path with multiple spaces in it.
The way it did this was by reading each line of rebase commands into a
single variable, and then breaking the individual components out using
echo, sed, and cut. It used the individual broken-out components for
decision making, and was still able to write the original line to the
output file from the variable it had saved it in. But, since we only
really need to look at anything other than the first element of the line
when a 'pick' command is encountered, and even that is only necessary when
we are still searching for "unnecessary" picks, and since newer rebase
commands like 'exec' may not even require a sha1 field, let's make our read
statement parse its input into a "command" variable, and a "rest" variable,
and then only break out the sha1 from $rest, and call git-rev-parse, when
absolutely necessary.
I think this future proofs this subroutine, avoids calling git-rev-parse
unnecessarily, and possibly with bogus arguments, and still accomplishes
the goal of not mangling the $rest of the rebase command.
Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-08-14 04:47:34 +08:00
|
|
|
case "$fd,$command" in
|
|
|
|
3,pick|3,p)
|
2011-02-07 02:43:37 +08:00
|
|
|
# pick a commit whose parent is current $onto -> skip
|
2010-09-18 05:42:51 +08:00
|
|
|
sha1=${rest%% *}
|
git-rebase--interactive.sh: rework skip_unnecessary_picks
Commit cd035b1c introduced the exec command to interactive rebase. In
doing so, it modified the way that skip_unnecessary_picks iterates through
the list of rebase commands so that it avoided collapsing multiple spaces
into a single space. This is necessary for example if the argument to the
exec command contains a path with multiple spaces in it.
The way it did this was by reading each line of rebase commands into a
single variable, and then breaking the individual components out using
echo, sed, and cut. It used the individual broken-out components for
decision making, and was still able to write the original line to the
output file from the variable it had saved it in. But, since we only
really need to look at anything other than the first element of the line
when a 'pick' command is encountered, and even that is only necessary when
we are still searching for "unnecessary" picks, and since newer rebase
commands like 'exec' may not even require a sha1 field, let's make our read
statement parse its input into a "command" variable, and a "rest" variable,
and then only break out the sha1 from $rest, and call git-rev-parse, when
absolutely necessary.
I think this future proofs this subroutine, avoids calling git-rev-parse
unnecessarily, and possibly with bogus arguments, and still accomplishes
the goal of not mangling the $rest of the rebase command.
Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-08-14 04:47:34 +08:00
|
|
|
case "$(git rev-parse --verify --quiet "$sha1"^)" in
|
2011-02-07 02:43:37 +08:00
|
|
|
"$onto"*)
|
|
|
|
onto=$sha1
|
git-rebase--interactive.sh: rework skip_unnecessary_picks
Commit cd035b1c introduced the exec command to interactive rebase. In
doing so, it modified the way that skip_unnecessary_picks iterates through
the list of rebase commands so that it avoided collapsing multiple spaces
into a single space. This is necessary for example if the argument to the
exec command contains a path with multiple spaces in it.
The way it did this was by reading each line of rebase commands into a
single variable, and then breaking the individual components out using
echo, sed, and cut. It used the individual broken-out components for
decision making, and was still able to write the original line to the
output file from the variable it had saved it in. But, since we only
really need to look at anything other than the first element of the line
when a 'pick' command is encountered, and even that is only necessary when
we are still searching for "unnecessary" picks, and since newer rebase
commands like 'exec' may not even require a sha1 field, let's make our read
statement parse its input into a "command" variable, and a "rest" variable,
and then only break out the sha1 from $rest, and call git-rev-parse, when
absolutely necessary.
I think this future proofs this subroutine, avoids calling git-rev-parse
unnecessarily, and possibly with bogus arguments, and still accomplishes
the goal of not mangling the $rest of the rebase command.
Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-08-14 04:47:34 +08:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
fd=1
|
|
|
|
;;
|
|
|
|
esac
|
2009-03-03 17:55:31 +08:00
|
|
|
;;
|
2013-08-17 05:44:07 +08:00
|
|
|
3,"$comment_char"*|3,)
|
2009-03-03 17:55:31 +08:00
|
|
|
# copy comments
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
fd=1
|
|
|
|
;;
|
|
|
|
esac
|
2010-08-14 04:47:35 +08:00
|
|
|
printf '%s\n' "$command${rest:+ }$rest" >&$fd
|
2011-02-07 02:43:37 +08:00
|
|
|
done <"$todo" >"$todo.new" 3>>"$done" &&
|
|
|
|
mv -f "$todo".new "$todo" &&
|
2010-03-13 01:04:30 +08:00
|
|
|
case "$(peek_next_command)" in
|
|
|
|
squash|s|fixup|f)
|
2011-02-07 02:43:37 +08:00
|
|
|
record_in_rewritten "$onto"
|
2010-03-13 01:04:30 +08:00
|
|
|
;;
|
|
|
|
esac ||
|
2016-06-18 04:21:03 +08:00
|
|
|
die "$(gettext "Could not skip unnecessary pick commands")"
|
2009-03-03 17:55:31 +08:00
|
|
|
}
|
|
|
|
|
2013-08-24 08:10:42 +08:00
|
|
|
transform_todo_ids () {
|
|
|
|
while read -r command rest
|
|
|
|
do
|
|
|
|
case "$command" in
|
|
|
|
"$comment_char"* | exec)
|
|
|
|
# Be careful for oddball commands like 'exec'
|
|
|
|
# that do not have a SHA-1 at the beginning of $rest.
|
|
|
|
;;
|
|
|
|
*)
|
2015-10-01 16:18:41 +08:00
|
|
|
sha1=$(git rev-parse --verify --quiet "$@" ${rest%%[ ]*}) &&
|
|
|
|
rest="$sha1 ${rest#*[ ]}"
|
2013-08-24 08:10:42 +08:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
printf '%s\n' "$command${rest:+ }$rest"
|
|
|
|
done <"$todo" >"$todo.new" &&
|
|
|
|
mv -f "$todo.new" "$todo"
|
|
|
|
}
|
|
|
|
|
|
|
|
expand_todo_ids() {
|
|
|
|
transform_todo_ids
|
|
|
|
}
|
|
|
|
|
|
|
|
collapse_todo_ids() {
|
2013-09-28 23:53:05 +08:00
|
|
|
transform_todo_ids --short
|
2013-08-24 08:10:42 +08:00
|
|
|
}
|
|
|
|
|
2009-12-08 11:13:14 +08:00
|
|
|
# Rearrange the todo list that has both "pick sha1 msg" and
|
|
|
|
# "pick sha1 fixup!/squash! msg" appears in it so that the latter
|
|
|
|
# comes immediately after the former, and change "pick" to
|
|
|
|
# "fixup"/"squash".
|
2015-06-14 00:26:58 +08:00
|
|
|
#
|
|
|
|
# Note that if the config has specified a custom instruction format
|
|
|
|
# each log message will be re-retrieved in order to normalize the
|
|
|
|
# autosquash arrangement
|
2009-12-08 11:13:14 +08:00
|
|
|
rearrange_squash () {
|
2010-11-05 06:36:32 +08:00
|
|
|
# extract fixup!/squash! lines and resolve any referenced sha1's
|
|
|
|
while read -r pick sha1 message
|
|
|
|
do
|
2015-06-14 00:26:58 +08:00
|
|
|
test -z "${format}" || message=$(git log -n 1 --format="%s" ${sha1})
|
2010-11-05 06:36:32 +08:00
|
|
|
case "$message" in
|
|
|
|
"squash! "*|"fixup! "*)
|
|
|
|
action="${message%%!*}"
|
2013-06-28 03:26:31 +08:00
|
|
|
rest=$message
|
|
|
|
prefix=
|
|
|
|
# skip all squash! or fixup! (but save for later)
|
|
|
|
while :
|
|
|
|
do
|
|
|
|
case "$rest" in
|
|
|
|
"squash! "*|"fixup! "*)
|
|
|
|
prefix="$prefix${rest%%!*},"
|
|
|
|
rest="${rest#*! }"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2014-03-15 07:56:43 +08:00
|
|
|
printf '%s %s %s %s\n' "$sha1" "$action" "$prefix" "$rest"
|
2010-11-05 06:36:32 +08:00
|
|
|
# if it's a single word, try to resolve to a full sha1 and
|
|
|
|
# emit a second copy. This allows us to match on both message
|
|
|
|
# and on sha1 prefix
|
|
|
|
if test "${rest#* }" = "$rest"; then
|
|
|
|
fullsha="$(git rev-parse -q --verify "$rest" 2>/dev/null)"
|
|
|
|
if test -n "$fullsha"; then
|
|
|
|
# prefix the action to uniquely identify this line as
|
|
|
|
# intended for full sha1 match
|
2013-06-28 03:26:31 +08:00
|
|
|
echo "$sha1 +$action $prefix $fullsha"
|
2010-11-05 06:36:32 +08:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
esac
|
|
|
|
done >"$1.sq" <"$1"
|
2009-12-08 11:13:14 +08:00
|
|
|
test -s "$1.sq" || return
|
|
|
|
|
|
|
|
used=
|
2010-07-06 14:08:36 +08:00
|
|
|
while read -r pick sha1 message
|
2009-12-08 11:13:14 +08:00
|
|
|
do
|
|
|
|
case " $used" in
|
|
|
|
*" $sha1 "*) continue ;;
|
|
|
|
esac
|
2010-07-23 03:15:11 +08:00
|
|
|
printf '%s\n' "$pick $sha1 $message"
|
2015-06-14 00:26:58 +08:00
|
|
|
test -z "${format}" || message=$(git log -n 1 --format="%s" ${sha1})
|
2010-11-05 06:36:31 +08:00
|
|
|
used="$used$sha1 "
|
2013-06-28 03:26:31 +08:00
|
|
|
while read -r squash action msg_prefix msg_content
|
2009-12-08 11:13:14 +08:00
|
|
|
do
|
2010-11-05 06:36:31 +08:00
|
|
|
case " $used" in
|
|
|
|
*" $squash "*) continue ;;
|
|
|
|
esac
|
2010-11-05 06:36:32 +08:00
|
|
|
emit=0
|
|
|
|
case "$action" in
|
|
|
|
+*)
|
|
|
|
action="${action#+}"
|
|
|
|
# full sha1 prefix test
|
2011-02-07 02:43:37 +08:00
|
|
|
case "$msg_content" in "$sha1"*) emit=1;; esac ;;
|
2010-11-05 06:36:32 +08:00
|
|
|
*)
|
|
|
|
# message prefix test
|
2011-02-07 02:43:37 +08:00
|
|
|
case "$message" in "$msg_content"*) emit=1;; esac ;;
|
2010-11-05 06:36:32 +08:00
|
|
|
esac
|
|
|
|
if test $emit = 1; then
|
2015-06-14 00:26:58 +08:00
|
|
|
if test -n "${format}"
|
|
|
|
then
|
|
|
|
msg_content=$(git log -n 1 --format="${format}" ${squash})
|
|
|
|
else
|
|
|
|
msg_content="$(echo "$msg_prefix" | sed "s/,/! /g")$msg_content"
|
|
|
|
fi
|
|
|
|
printf '%s\n' "$action $squash $msg_content"
|
2009-12-08 11:13:14 +08:00
|
|
|
used="$used$squash "
|
2010-11-05 06:36:32 +08:00
|
|
|
fi
|
2009-12-08 11:13:14 +08:00
|
|
|
done <"$1.sq"
|
|
|
|
done >"$1.rearranged" <"$1"
|
|
|
|
cat "$1.rearranged" >"$1"
|
|
|
|
rm -f "$1.sq" "$1.rearranged"
|
|
|
|
}
|
|
|
|
|
2012-06-12 16:05:12 +08:00
|
|
|
# Add commands after a pick or after a squash/fixup serie
|
|
|
|
# in the todo list.
|
|
|
|
add_exec_commands () {
|
|
|
|
{
|
|
|
|
first=t
|
|
|
|
while read -r insn rest
|
|
|
|
do
|
|
|
|
case $insn in
|
|
|
|
pick)
|
|
|
|
test -n "$first" ||
|
|
|
|
printf "%s" "$cmd"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
printf "%s %s\n" "$insn" "$rest"
|
|
|
|
first=
|
|
|
|
done
|
|
|
|
printf "%s" "$cmd"
|
|
|
|
} <"$1" >"$1.new" &&
|
|
|
|
mv "$1.new" "$1"
|
|
|
|
}
|
|
|
|
|
2015-06-30 04:20:32 +08:00
|
|
|
# Check if the SHA-1 passed as an argument is a
|
|
|
|
# correct one, if not then print $2 in "$todo".badsha
|
|
|
|
# $1: the SHA-1 to test
|
2015-10-01 16:18:42 +08:00
|
|
|
# $2: the line number of the input
|
|
|
|
# $3: the input filename
|
2015-06-30 04:20:32 +08:00
|
|
|
check_commit_sha () {
|
|
|
|
badsha=0
|
always quote shell arguments to test -z/-n
In shell code like:
test -z $foo
test -n $foo
that does not quote its arguments, it's easy to think that
it is actually looking at the contents of $foo in each case.
But if $foo is empty, then "test" does not see any argument
at all! The results are quite subtle.
POSIX specifies that test's behavior depends on the number
of arguments it sees, and if $foo is empty, it sees only
one. The behavior in this case is:
1 argument: Exit true (0) if $1 is not null; otherwise,
exit false.
So in the "-z $foo" case, if $foo is empty, then we check
that "-z" is non-null, and it returns success. Which happens
to match what we expected. But for "-n $foo", if $foo is
empty, we'll see that "-n" is non-null and still return
success. That's the opposite of what we intended!
Furthermore, if $foo contains whitespace, we'll end up with
more than 2 arguments. The results in this case are
generally unspecified (unless the first part of $foo happens
to be a valid binary operator, in which case the results are
specified but certainly not what we intended).
And on top of this, even though "test -z $foo" _should_ work
for the empty case, some older shells (reportedly ksh88)
complain about the missing argument.
So let's make sure we consistently quote our variable
arguments to "test". After this patch, the results of:
git grep 'test -[zn] [^"]'
are empty.
Reported-by: Armin Kunaschik <megabreit@googlemail.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-05-14 04:47:33 +08:00
|
|
|
if test -z "$1"
|
2015-06-30 04:20:32 +08:00
|
|
|
then
|
|
|
|
badsha=1
|
|
|
|
else
|
|
|
|
sha1_verif="$(git rev-parse --verify --quiet $1^{commit})"
|
always quote shell arguments to test -z/-n
In shell code like:
test -z $foo
test -n $foo
that does not quote its arguments, it's easy to think that
it is actually looking at the contents of $foo in each case.
But if $foo is empty, then "test" does not see any argument
at all! The results are quite subtle.
POSIX specifies that test's behavior depends on the number
of arguments it sees, and if $foo is empty, it sees only
one. The behavior in this case is:
1 argument: Exit true (0) if $1 is not null; otherwise,
exit false.
So in the "-z $foo" case, if $foo is empty, then we check
that "-z" is non-null, and it returns success. Which happens
to match what we expected. But for "-n $foo", if $foo is
empty, we'll see that "-n" is non-null and still return
success. That's the opposite of what we intended!
Furthermore, if $foo contains whitespace, we'll end up with
more than 2 arguments. The results in this case are
generally unspecified (unless the first part of $foo happens
to be a valid binary operator, in which case the results are
specified but certainly not what we intended).
And on top of this, even though "test -z $foo" _should_ work
for the empty case, some older shells (reportedly ksh88)
complain about the missing argument.
So let's make sure we consistently quote our variable
arguments to "test". After this patch, the results of:
git grep 'test -[zn] [^"]'
are empty.
Reported-by: Armin Kunaschik <megabreit@googlemail.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-05-14 04:47:33 +08:00
|
|
|
if test -z "$sha1_verif"
|
2015-06-30 04:20:32 +08:00
|
|
|
then
|
|
|
|
badsha=1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test $badsha -ne 0
|
|
|
|
then
|
2015-10-01 16:18:42 +08:00
|
|
|
line="$(sed -n -e "${2}p" "$3")"
|
2016-06-18 04:21:03 +08:00
|
|
|
warn "$(eval_gettext "\
|
|
|
|
Warning: the SHA-1 is missing or isn't a commit in the following line:
|
|
|
|
- \$line")"
|
2015-06-30 04:20:32 +08:00
|
|
|
warn
|
|
|
|
fi
|
|
|
|
|
|
|
|
return $badsha
|
|
|
|
}
|
|
|
|
|
|
|
|
# prints the bad commits and bad commands
|
|
|
|
# from the todolist in stdin
|
|
|
|
check_bad_cmd_and_sha () {
|
|
|
|
retval=0
|
2015-10-01 16:18:42 +08:00
|
|
|
lineno=0
|
|
|
|
while read -r command rest
|
|
|
|
do
|
|
|
|
lineno=$(( $lineno + 1 ))
|
|
|
|
case $command in
|
|
|
|
"$comment_char"*|''|noop|x|exec)
|
|
|
|
# Doesn't expect a SHA-1
|
|
|
|
;;
|
2015-10-28 22:54:48 +08:00
|
|
|
"$cr")
|
|
|
|
# Work around CR left by "read" (e.g. with Git for
|
|
|
|
# Windows' Bash).
|
|
|
|
;;
|
2015-10-01 16:18:42 +08:00
|
|
|
pick|p|drop|d|reword|r|edit|e|squash|s|fixup|f)
|
|
|
|
if ! check_commit_sha "${rest%%[ ]*}" "$lineno" "$1"
|
|
|
|
then
|
2015-06-30 04:20:32 +08:00
|
|
|
retval=1
|
2015-10-01 16:18:42 +08:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
line="$(sed -n -e "${lineno}p" "$1")"
|
2016-06-18 04:21:03 +08:00
|
|
|
warn "$(eval_gettext "\
|
|
|
|
Warning: the command isn't recognized in the following line:
|
|
|
|
- \$line")"
|
2015-10-01 16:18:42 +08:00
|
|
|
warn
|
|
|
|
retval=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done <"$1"
|
|
|
|
return $retval
|
2015-06-30 04:20:32 +08:00
|
|
|
}
|
|
|
|
|
2015-06-30 04:20:31 +08:00
|
|
|
# Print the list of the SHA-1 of the commits
|
|
|
|
# from stdin to stdout
|
|
|
|
todo_list_to_sha_list () {
|
|
|
|
git stripspace --strip-comments |
|
|
|
|
while read -r command sha1 rest
|
|
|
|
do
|
|
|
|
case $command in
|
|
|
|
"$comment_char"*|''|noop|x|"exec")
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
long_sha=$(git rev-list --no-walk "$sha1" 2>/dev/null)
|
|
|
|
printf "%s\n" "$long_sha"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Use warn for each line in stdin
|
|
|
|
warn_lines () {
|
|
|
|
while read -r line
|
|
|
|
do
|
|
|
|
warn " - $line"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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-18 04:21:03 +08:00
|
|
|
output git checkout $onto || die_abort "$(gettext "could not detach HEAD")"
|
2015-06-30 04:20:31 +08: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'
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check if the user dropped some commits by mistake
|
|
|
|
# Behaviour determined by rebase.missingCommitsCheck.
|
2015-06-30 04:20:32 +08:00
|
|
|
# Check if there is an unrecognized command or a
|
|
|
|
# bad SHA-1 in a command.
|
2015-06-30 04:20:31 +08:00
|
|
|
check_todo_list () {
|
|
|
|
raise_error=f
|
|
|
|
|
|
|
|
check_level=$(get_missing_commit_check_level)
|
|
|
|
|
|
|
|
case "$check_level" in
|
|
|
|
warn|error)
|
|
|
|
# Get the SHA-1 of the commits
|
|
|
|
todo_list_to_sha_list <"$todo".backup >"$todo".oldsha1
|
|
|
|
todo_list_to_sha_list <"$todo" >"$todo".newsha1
|
|
|
|
|
|
|
|
# Sort the SHA-1 and compare them
|
|
|
|
sort -u "$todo".oldsha1 >"$todo".oldsha1+
|
|
|
|
mv "$todo".oldsha1+ "$todo".oldsha1
|
|
|
|
sort -u "$todo".newsha1 >"$todo".newsha1+
|
|
|
|
mv "$todo".newsha1+ "$todo".newsha1
|
|
|
|
comm -2 -3 "$todo".oldsha1 "$todo".newsha1 >"$todo".miss
|
|
|
|
|
|
|
|
# Warn about missing commits
|
|
|
|
if test -s "$todo".miss
|
|
|
|
then
|
|
|
|
test "$check_level" = error && raise_error=t
|
|
|
|
|
2016-06-18 04:21:03 +08:00
|
|
|
warn "$(gettext "\
|
|
|
|
Warning: some commits may have been dropped accidentally.
|
|
|
|
Dropped commits (newer to older):")"
|
2015-06-30 04:20:31 +08:00
|
|
|
|
|
|
|
# Make the list user-friendly and display
|
|
|
|
opt="--no-walk=sorted --format=oneline --abbrev-commit --stdin"
|
|
|
|
git rev-list $opt <"$todo".miss | warn_lines
|
|
|
|
|
2016-06-18 04:21:03 +08:00
|
|
|
warn "$(gettext "\
|
|
|
|
To avoid this message, use \"drop\" to explicitly remove a commit.
|
|
|
|
|
|
|
|
Use 'git config rebase.missingCommitsCheck' to change the level of warnings.
|
|
|
|
The possible behaviours are: ignore, warn, error.")"
|
2015-06-30 04:20:31 +08:00
|
|
|
warn
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
ignore)
|
|
|
|
;;
|
|
|
|
*)
|
2016-06-18 04:21:03 +08:00
|
|
|
warn "$(eval_gettext "Unrecognized setting \$check_level for option rebase.missingCommitsCheck. Ignoring.")"
|
2015-06-30 04:20:31 +08:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2015-10-01 16:18:42 +08:00
|
|
|
if ! check_bad_cmd_and_sha "$todo"
|
2015-06-30 04:20:32 +08:00
|
|
|
then
|
|
|
|
raise_error=t
|
|
|
|
fi
|
|
|
|
|
2015-06-30 04:20:31 +08:00
|
|
|
if test $raise_error = t
|
|
|
|
then
|
|
|
|
# Checkout before the first commit of the
|
|
|
|
# rebase: this way git rebase --continue
|
|
|
|
# will work correctly as it expects HEAD to be
|
|
|
|
# placed before the commit of the next action
|
|
|
|
checkout_onto
|
|
|
|
|
2016-09-07 02:59:18 +08:00
|
|
|
warn "$(gettext "You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'.")"
|
2016-06-18 04:21:03 +08:00
|
|
|
die "$(gettext "Or you can abort the rebase with 'git rebase --abort'.")"
|
2015-06-30 04:20:31 +08:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-04-11 16:28:17 +08: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 23:33:29 +08: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 16:28:17 +08: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-07 02:43:39 +08:00
|
|
|
case "$action" in
|
|
|
|
continue)
|
2017-02-10 06:23:11 +08:00
|
|
|
if test ! -d "$rewritten"
|
|
|
|
then
|
|
|
|
exec git rebase--helper ${force_rebase:+--no-ff} --continue
|
|
|
|
fi
|
2011-02-07 02:43:39 +08:00
|
|
|
# do we have anything to commit?
|
2012-04-07 18:20:53 +08:00
|
|
|
if git diff-index --cached --quiet HEAD --
|
2011-02-07 02:43:39 +08:00
|
|
|
then
|
2015-06-19 00:38:53 +08:00
|
|
|
# Nothing to commit -- skip this commit
|
|
|
|
|
|
|
|
test ! -f "$GIT_DIR"/CHERRY_PICK_HEAD ||
|
|
|
|
rm "$GIT_DIR"/CHERRY_PICK_HEAD ||
|
2016-06-18 04:21:03 +08:00
|
|
|
die "$(gettext "Could not remove CHERRY_PICK_HEAD")"
|
2011-02-07 02:43:39 +08:00
|
|
|
else
|
2011-08-24 22:01:48 +08:00
|
|
|
if ! test -f "$author_script"
|
|
|
|
then
|
2014-02-10 09:03:37 +08:00
|
|
|
gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
|
2016-06-18 04:21:03 +08:00
|
|
|
die "$(eval_gettext "\
|
|
|
|
You have staged changes in your working tree.
|
|
|
|
If these changes are meant to be
|
2011-08-24 22:01:48 +08:00
|
|
|
squashed into the previous commit, run:
|
|
|
|
|
2016-06-18 04:21:03 +08:00
|
|
|
git commit --amend \$gpg_sign_opt_quoted
|
2011-08-24 22:01:48 +08:00
|
|
|
|
|
|
|
If they are meant to go into a new commit, run:
|
|
|
|
|
2016-06-18 04:21:03 +08:00
|
|
|
git commit \$gpg_sign_opt_quoted
|
2011-08-24 22:01:48 +08:00
|
|
|
|
2016-09-08 12:34:17 +08:00
|
|
|
In both cases, once you're done, continue with:
|
2011-08-24 22:01:48 +08:00
|
|
|
|
|
|
|
git rebase --continue
|
2016-06-18 04:21:03 +08:00
|
|
|
")"
|
2011-08-24 22:01:48 +08:00
|
|
|
fi
|
2011-02-07 02:43:39 +08:00
|
|
|
. "$author_script" ||
|
2016-06-18 04:21:03 +08:00
|
|
|
die "$(gettext "Error trying to find the author identity to amend commit")"
|
2011-02-07 02:43:39 +08:00
|
|
|
if test -f "$amend"
|
2007-12-20 15:12:12 +08:00
|
|
|
then
|
2011-02-07 02:43:39 +08:00
|
|
|
current_head=$(git rev-parse --verify HEAD)
|
|
|
|
test "$current_head" = $(cat "$amend") ||
|
2016-06-18 04:21:03 +08: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 09:03:37 +08:00
|
|
|
do_with_author git commit --amend --no-verify -F "$msg" -e \
|
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2016-06-18 04:21:03 +08:00
|
|
|
die "$(gettext "Could not commit staged changes.")"
|
2012-07-24 20:17:03 +08:00
|
|
|
else
|
2014-02-10 09:03:37 +08:00
|
|
|
do_with_author git commit --no-verify -F "$msg" -e \
|
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2016-06-18 04:21:03 +08:00
|
|
|
die "$(gettext "Could not commit staged changes.")"
|
2007-12-20 15:12:12 +08:00
|
|
|
fi
|
2011-02-07 02:43:39 +08:00
|
|
|
fi
|
2007-07-08 10:01:29 +08:00
|
|
|
|
2015-05-22 21:15:49 +08:00
|
|
|
if test -r "$state_dir"/stopped-sha
|
|
|
|
then
|
|
|
|
record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
|
|
|
|
fi
|
2010-03-29 03:36:00 +08:00
|
|
|
|
2011-02-07 02:43:39 +08:00
|
|
|
require_clean_work_tree "rebase"
|
|
|
|
do_rest
|
2013-05-12 19:56:39 +08:00
|
|
|
return 0
|
2011-02-07 02:43:39 +08:00
|
|
|
;;
|
|
|
|
skip)
|
|
|
|
git rerere clear
|
|
|
|
|
2017-02-10 06:23:11 +08:00
|
|
|
if test ! -d "$rewritten"
|
|
|
|
then
|
|
|
|
exec git rebase--helper ${force_rebase:+--no-ff} --continue
|
|
|
|
fi
|
2011-02-07 02:43:52 +08:00
|
|
|
do_rest
|
2013-05-12 19:56:39 +08:00
|
|
|
return 0
|
2011-02-07 02:43:39 +08:00
|
|
|
;;
|
2012-09-18 09:28:09 +08:00
|
|
|
edit-todo)
|
2013-02-12 07:08:04 +08:00
|
|
|
git stripspace --strip-comments <"$todo" >"$todo".new
|
2012-09-18 09:28:09 +08:00
|
|
|
mv -f "$todo".new "$todo"
|
2013-08-24 08:10:42 +08:00
|
|
|
collapse_todo_ids
|
2012-09-18 09:28:09 +08:00
|
|
|
append_todo_help
|
2016-06-18 04:21:04 +08:00
|
|
|
gettext "
|
2013-02-12 07:08:04 +08:00
|
|
|
You are editing the todo file of an ongoing interactive rebase.
|
|
|
|
To continue rebase after editing, run:
|
|
|
|
git rebase --continue
|
|
|
|
|
2016-06-18 04:21:04 +08:00
|
|
|
" | git stripspace --comment-lines >>"$todo"
|
2012-09-18 09:28:09 +08:00
|
|
|
|
|
|
|
git_sequence_editor "$todo" ||
|
2016-06-18 04:21:03 +08:00
|
|
|
die "$(gettext "Could not execute editor")"
|
2013-08-24 08:10:42 +08:00
|
|
|
expand_todo_ids
|
2012-09-18 09:28:09 +08:00
|
|
|
|
|
|
|
exit
|
|
|
|
;;
|
2011-02-07 02:43:39 +08:00
|
|
|
esac
|
2007-06-25 08:11:14 +08:00
|
|
|
|
2011-02-07 02:43:35 +08:00
|
|
|
comment_for_reflog start
|
|
|
|
|
2011-02-07 02:43:42 +08:00
|
|
|
if test ! -z "$switch_to"
|
2011-02-07 02:43:35 +08:00
|
|
|
then
|
2013-06-16 16:45:13 +08:00
|
|
|
GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to"
|
2011-02-07 02:43:42 +08:00
|
|
|
output git checkout "$switch_to" -- ||
|
2016-06-18 04:21:03 +08:00
|
|
|
die "$(eval_gettext "Could not checkout \$switch_to")"
|
2013-06-16 16:45:13 +08:00
|
|
|
|
|
|
|
comment_for_reflog start
|
2011-02-07 02:43:35 +08:00
|
|
|
fi
|
|
|
|
|
2016-06-18 04:21:03 +08: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-07 02:43:35 +08:00
|
|
|
|
2016-06-18 04:21:03 +08:00
|
|
|
: > "$state_dir"/interactive || die "$(gettext "Could not mark as interactive")"
|
2011-02-07 02:43:53 +08:00
|
|
|
write_basic_state
|
2011-02-07 02:43:37 +08:00
|
|
|
if test t = "$preserve_merges"
|
2011-02-07 02:43:35 +08:00
|
|
|
then
|
2011-02-07 02:43:37 +08:00
|
|
|
if test -z "$rebase_root"
|
2011-02-07 02:43:35 +08:00
|
|
|
then
|
2011-02-07 02:43:37 +08:00
|
|
|
mkdir "$rewritten" &&
|
2011-02-07 02:43:50 +08:00
|
|
|
for c in $(git merge-base --all $orig_head $upstream)
|
2008-10-15 15:44:38 +08:00
|
|
|
do
|
2011-02-07 02:43:37 +08:00
|
|
|
echo $onto > "$rewritten"/$c ||
|
2016-06-18 04:21:03 +08:00
|
|
|
die "$(gettext "Could not init rewritten commits")"
|
2008-10-15 15:44:38 +08:00
|
|
|
done
|
2011-02-07 02:43:35 +08:00
|
|
|
else
|
2011-02-07 02:43:37 +08:00
|
|
|
mkdir "$rewritten" &&
|
|
|
|
echo $onto > "$rewritten"/root ||
|
2016-06-18 04:21:03 +08:00
|
|
|
die "$(gettext "Could not init rewritten commits")"
|
2011-02-07 02:43:35 +08: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-07 02:43:37 +08:00
|
|
|
merges_option=
|
2011-02-07 02:43:35 +08:00
|
|
|
else
|
2011-02-07 02:43:37 +08:00
|
|
|
merges_option="--no-merges --cherry-pick"
|
2011-02-07 02:43:35 +08:00
|
|
|
fi
|
|
|
|
|
2011-02-07 02:43:50 +08:00
|
|
|
shorthead=$(git rev-parse --short $orig_head)
|
2011-02-07 02:43:37 +08:00
|
|
|
shortonto=$(git rev-parse --short $onto)
|
|
|
|
if test -z "$rebase_root"
|
|
|
|
# this is now equivalent to ! -z "$upstream"
|
2011-02-07 02:43:35 +08:00
|
|
|
then
|
2011-02-07 02:43:37 +08:00
|
|
|
shortupstream=$(git rev-parse --short $upstream)
|
2011-02-07 02:43:50 +08:00
|
|
|
revisions=$upstream...$orig_head
|
2011-02-07 02:43:37 +08:00
|
|
|
shortrevisions=$shortupstream..$shorthead
|
2011-02-07 02:43:35 +08:00
|
|
|
else
|
2011-02-07 02:43:50 +08:00
|
|
|
revisions=$onto...$orig_head
|
2011-02-07 02:43:37 +08:00
|
|
|
shortrevisions=$shorthead
|
2011-02-07 02:43:35 +08:00
|
|
|
fi
|
2015-06-14 00:26:58 +08:00
|
|
|
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 \
|
2014-07-17 03:23:49 +08:00
|
|
|
$revisions ${restrict_revision+^$restrict_revision} | \
|
2011-02-07 02:43:35 +08:00
|
|
|
sed -n "s/^>//p" |
|
2015-01-22 19:50:15 +08:00
|
|
|
while read -r sha1 rest
|
2011-02-07 02:43:35 +08:00
|
|
|
do
|
2012-04-20 22:36:17 +08:00
|
|
|
|
2015-01-22 19:50:15 +08:00
|
|
|
if test -z "$keep_empty" && is_empty_commit $sha1 && ! is_merge_commit $sha1
|
2012-04-20 22:36:17 +08:00
|
|
|
then
|
2013-02-12 07:08:04 +08:00
|
|
|
comment_out="$comment_char "
|
2012-04-20 22:36:17 +08:00
|
|
|
else
|
|
|
|
comment_out=
|
|
|
|
fi
|
|
|
|
|
2011-02-07 02:43:37 +08:00
|
|
|
if test t != "$preserve_merges"
|
2011-02-07 02:43:35 +08:00
|
|
|
then
|
2015-01-22 19:50:15 +08:00
|
|
|
printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo"
|
2011-02-07 02:43:35 +08:00
|
|
|
else
|
2011-02-07 02:43:37 +08:00
|
|
|
if test -z "$rebase_root"
|
2008-10-15 15:44:38 +08:00
|
|
|
then
|
2011-02-07 02:43:35 +08:00
|
|
|
preserve=t
|
|
|
|
for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
|
2008-10-15 15:44:38 +08: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 06:12:01 +08:00
|
|
|
if test -f "$rewritten"/$p
|
2008-10-15 15:44:38 +08:00
|
|
|
then
|
2011-02-07 02:43:35 +08:00
|
|
|
preserve=f
|
2008-10-15 15:44:38 +08:00
|
|
|
fi
|
|
|
|
done
|
2011-02-07 02:43:35 +08:00
|
|
|
else
|
|
|
|
preserve=f
|
|
|
|
fi
|
|
|
|
if test f = "$preserve"
|
|
|
|
then
|
2011-02-07 02:43:37 +08:00
|
|
|
touch "$rewritten"/$sha1
|
2015-01-22 19:50:15 +08:00
|
|
|
printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo"
|
2008-10-15 15:44:38 +08:00
|
|
|
fi
|
2011-02-07 02:43:35 +08:00
|
|
|
fi
|
|
|
|
done
|
2009-01-03 06:28:28 +08:00
|
|
|
|
2011-02-07 02:43:35 +08:00
|
|
|
# Watch for commits that been dropped by --cherry-pick
|
2011-02-07 02:43:37 +08:00
|
|
|
if test t = "$preserve_merges"
|
2011-02-07 02:43:35 +08:00
|
|
|
then
|
2011-02-07 02:43:37 +08:00
|
|
|
mkdir "$dropped"
|
2011-02-07 02:43:35 +08:00
|
|
|
# Save all non-cherry-picked changes
|
2011-02-07 02:43:37 +08:00
|
|
|
git rev-list $revisions --left-right --cherry-pick | \
|
2011-02-07 02:43:50 +08:00
|
|
|
sed -n "s/^>//p" > "$state_dir"/not-cherry-picks
|
2011-02-07 02:43:35 +08:00
|
|
|
# Now all commits and note which ones are missing in
|
|
|
|
# not-cherry-picks and hence being dropped
|
2011-02-07 02:43:37 +08:00
|
|
|
git rev-list $revisions |
|
2011-02-07 02:43:35 +08:00
|
|
|
while read rev
|
|
|
|
do
|
2016-03-09 07:51:36 +08:00
|
|
|
if test -f "$rewritten"/$rev &&
|
|
|
|
! sane_grep "$rev" "$state_dir"/not-cherry-picks >/dev/null
|
2011-02-07 02:43:35 +08: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-07 02:43:37 +08:00
|
|
|
git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$dropped"/$rev
|
2015-01-22 19:50:15 +08:00
|
|
|
sha1=$(git rev-list -1 $rev)
|
|
|
|
sane_grep -v "^[a-z][a-z]* $sha1" <"$todo" > "${todo}2" ; mv "${todo}2" "$todo"
|
2011-02-07 02:43:37 +08:00
|
|
|
rm "$rewritten"/$rev
|
2011-02-07 02:43:35 +08:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2011-02-07 02:43:37 +08:00
|
|
|
test -s "$todo" || echo noop >> "$todo"
|
|
|
|
test -n "$autosquash" && rearrange_squash "$todo"
|
2012-06-12 16:05:12 +08:00
|
|
|
test -n "$cmd" && add_exec_commands "$todo"
|
|
|
|
|
2014-12-11 02:16:44 +08:00
|
|
|
todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
|
2015-03-04 15:53:04 +08:00
|
|
|
todocount=${todocount##* }
|
2014-12-11 02:16:44 +08:00
|
|
|
|
2013-02-12 07:08:04 +08:00
|
|
|
cat >>"$todo" <<EOF
|
2007-11-22 20:30:10 +08:00
|
|
|
|
2016-06-18 04:21:04 +08:00
|
|
|
$comment_char $(eval_ngettext \
|
|
|
|
"Rebase \$shortrevisions onto \$shortonto (\$todocount command)" \
|
|
|
|
"Rebase \$shortrevisions onto \$shortonto (\$todocount commands)" \
|
|
|
|
"$todocount")
|
2012-09-18 09:28:08 +08:00
|
|
|
EOF
|
|
|
|
append_todo_help
|
2016-06-18 04:21:04 +08:00
|
|
|
gettext "
|
2013-02-12 07:08:04 +08:00
|
|
|
However, if you remove everything, the rebase will be aborted.
|
|
|
|
|
2016-06-18 04:21:04 +08:00
|
|
|
" | git stripspace --comment-lines >>"$todo"
|
2007-06-25 08:11:14 +08:00
|
|
|
|
2012-04-20 22:36:17 +08:00
|
|
|
if test -z "$keep_empty"
|
|
|
|
then
|
2016-06-18 04:21:03 +08:00
|
|
|
printf '%s\n' "$comment_char $(gettext "Note that empty commits are commented out")" >>"$todo"
|
2012-04-20 22:36:17 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2011-02-07 02:43:37 +08:00
|
|
|
has_action "$todo" ||
|
2014-05-20 06:05:20 +08:00
|
|
|
return 2
|
2007-06-25 08:11:14 +08:00
|
|
|
|
2011-02-07 02:43:37 +08:00
|
|
|
cp "$todo" "$todo".backup
|
2015-01-22 19:50:15 +08:00
|
|
|
collapse_todo_ids
|
2011-10-18 04:26:23 +08:00
|
|
|
git_sequence_editor "$todo" ||
|
2016-06-18 04:21:03 +08:00
|
|
|
die_abort "$(gettext "Could not execute editor")"
|
2007-06-25 08:11:14 +08:00
|
|
|
|
2011-02-07 02:43:37 +08:00
|
|
|
has_action "$todo" ||
|
2014-05-20 06:05:20 +08:00
|
|
|
return 2
|
2007-06-26 01:56:55 +08:00
|
|
|
|
2015-06-30 04:20:31 +08:00
|
|
|
check_todo_list
|
|
|
|
|
2013-08-24 08:10:42 +08:00
|
|
|
expand_todo_ids
|
|
|
|
|
2011-02-07 02:43:37 +08:00
|
|
|
test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks
|
2009-03-03 17:55:31 +08:00
|
|
|
|
2015-06-30 04:20:31 +08:00
|
|
|
checkout_onto
|
2017-02-10 06:23:11 +08: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-07 02:43:35 +08:00
|
|
|
do_rest
|
2014-04-11 16:28:17 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
# ... and then we call the whole thing.
|
|
|
|
git_rebase__interactive
|