2013-11-25 22:03:52 +01: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 02:11:14 +02:00
|
|
|
#
|
|
|
|
# Copyright (c) 2006 Johannes E. Schindelin
|
|
|
|
#
|
|
|
|
# The original idea comes from Eric W. Biederman, in
|
|
|
|
# http://article.gmane.org/gmane.comp.version-control.git/22407
|
2012-06-26 16:51:54 +02:00
|
|
|
#
|
2010-01-14 06:54:45 +01: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 19:43:37 +01:00
|
|
|
# file and written to the tail of $done.
|
2011-02-06 19:43:50 +01:00
|
|
|
todo="$state_dir"/git-rebase-todo
|
2010-01-14 06:54:45 +01: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 19:43:50 +01:00
|
|
|
done="$state_dir"/done
|
2010-01-14 06:54:45 +01: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 19:43:50 +01:00
|
|
|
msg="$state_dir"/message
|
2010-01-14 06:54:45 +01: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 19:43:37 +01:00
|
|
|
# # This is a combination of $count commits.
|
|
|
|
# where $count is the number of commits whose messages have been
|
2010-01-14 06:54:45 +01: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 19:43:50 +01:00
|
|
|
squash_msg="$state_dir"/message-squash
|
2010-01-14 06:54:45 +01:00
|
|
|
|
2010-01-14 06:54:55 +01: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 19:43:50 +01:00
|
|
|
fixup_msg="$state_dir"/message-fixup
|
2010-01-14 06:54:55 +01:00
|
|
|
|
2011-02-06 19:43:37 +01: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 06:54:45 +01: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 19:43:50 +01:00
|
|
|
rewritten="$state_dir"/rewritten
|
2010-01-14 06:54:45 +01:00
|
|
|
|
2011-02-06 19:43:50 +01:00
|
|
|
dropped="$state_dir"/dropped
|
2010-01-14 06:54:46 +01:00
|
|
|
|
2013-04-25 11:28:54 +02:00
|
|
|
end="$state_dir"/end
|
|
|
|
msgnum="$state_dir"/msgnum
|
|
|
|
|
2010-01-14 06:54:46 +01: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 19:43:50 +01:00
|
|
|
author_script="$state_dir"/author-script
|
2010-01-14 06:54:46 +01:00
|
|
|
|
2010-01-14 06:54:47 +01: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 19:43:50 +01:00
|
|
|
amend="$state_dir"/amend
|
2010-01-14 06:54:47 +01:00
|
|
|
|
2010-03-12 18:04:30 +01: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 19:43:50 +01:00
|
|
|
rewritten_list="$state_dir"/rewritten-list
|
|
|
|
rewritten_pending="$state_dir"/rewritten-pending
|
2011-02-06 19:43:37 +01:00
|
|
|
|
2015-10-28 15:54:48 +01: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 21:30:36 +01:00
|
|
|
strategy_args=${strategy:+--strategy=$strategy}
|
2016-05-10 23:07:10 +02: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 21:30:36 +01: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 10:05:48 +02:00
|
|
|
|
2011-02-06 19:43:49 +01:00
|
|
|
GIT_CHERRY_PICK_HELP="$resolvemsg"
|
2007-11-28 09:06:36 +01:00
|
|
|
export GIT_CHERRY_PICK_HELP
|
|
|
|
|
2013-02-12 00:08:04 +01:00
|
|
|
comment_char=$(git config --get core.commentchar 2>/dev/null | cut -c1)
|
|
|
|
: ${comment_char:=#}
|
|
|
|
|
2007-06-25 02:11:14 +02:00
|
|
|
warn () {
|
2010-07-22 21:15:11 +02:00
|
|
|
printf '%s\n' "$*" >&2
|
2007-06-25 02:11:14 +02:00
|
|
|
}
|
|
|
|
|
2010-01-14 06:54:51 +01:00
|
|
|
# Output the commit message for the specified commit.
|
|
|
|
commit_message () {
|
|
|
|
git cat-file commit "$1" | sed "1,/^$/d"
|
|
|
|
}
|
|
|
|
|
2011-02-06 19:43:37 +01:00
|
|
|
orig_reflog_action="$GIT_REFLOG_ACTION"
|
2007-06-25 02:11:14 +02:00
|
|
|
|
|
|
|
comment_for_reflog () {
|
2011-02-06 19:43:37 +01:00
|
|
|
case "$orig_reflog_action" in
|
2007-06-25 02:11:14 +02:00
|
|
|
''|rebase*)
|
|
|
|
GIT_REFLOG_ACTION="rebase -i ($1)"
|
|
|
|
export GIT_REFLOG_ACTION
|
2007-09-25 17:42:51 +02:00
|
|
|
;;
|
2007-06-25 02:11:14 +02:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2008-01-15 05:01:21 +01:00
|
|
|
last_count=
|
2007-06-25 02:11:14 +02:00
|
|
|
mark_action_done () {
|
2011-02-06 19:43:37 +01:00
|
|
|
sed -e 1q < "$todo" >> "$done"
|
|
|
|
sed -e 1d < "$todo" >> "$todo".new
|
|
|
|
mv -f "$todo".new "$todo"
|
2013-02-12 00:08:04 +01:00
|
|
|
new_count=$(git stripspace --strip-comments <"$done" | wc -l)
|
2013-04-25 11:28:54 +02:00
|
|
|
echo $new_count >"$msgnum"
|
2013-02-12 00:08:04 +01:00
|
|
|
total=$(($new_count + $(git stripspace --strip-comments <"$todo" | wc -l)))
|
2013-04-25 11:28:54 +02:00
|
|
|
echo $total >"$end"
|
2011-02-06 19:43:37 +01:00
|
|
|
if test "$last_count" != "$new_count"
|
2008-01-15 05:01:21 +01:00
|
|
|
then
|
2011-02-06 19:43:37 +01:00
|
|
|
last_count=$new_count
|
|
|
|
printf "Rebasing (%d/%d)\r" $new_count $total
|
|
|
|
test -z "$verbose" || echo
|
2008-01-15 05:01:21 +01:00
|
|
|
fi
|
2007-06-25 02:11:14 +02:00
|
|
|
}
|
|
|
|
|
2015-04-29 00:55:20 +02: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 03:28:08 +02:00
|
|
|
append_todo_help () {
|
2013-02-12 00:08:04 +01:00
|
|
|
git stripspace --comment-lines >>"$todo" <<\EOF
|
|
|
|
|
|
|
|
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
|
|
|
|
f, fixup = like "squash", but discard this commit's log message
|
|
|
|
x, exec = run command (the rest of the line) using shell
|
2015-06-29 22:20:30 +02:00
|
|
|
d, drop = remove commit
|
2013-02-12 00:08:04 +01:00
|
|
|
|
|
|
|
These lines can be re-ordered; they are executed from top to bottom.
|
|
|
|
|
2015-06-29 22:20:31 +02:00
|
|
|
EOF
|
|
|
|
if test $(get_missing_commit_check_level) = error
|
|
|
|
then
|
|
|
|
git stripspace --comment-lines >>"$todo" <<\EOF
|
|
|
|
Do not remove any line. Use 'drop' explicitly to remove a commit.
|
|
|
|
EOF
|
|
|
|
else
|
|
|
|
git stripspace --comment-lines >>"$todo" <<\EOF
|
2013-02-12 00:08:04 +01:00
|
|
|
If you remove a line here THAT COMMIT WILL BE LOST.
|
2012-09-18 03:28:08 +02:00
|
|
|
EOF
|
2015-06-29 22:20:31 +02:00
|
|
|
fi
|
2012-09-18 03:28:08 +02:00
|
|
|
}
|
|
|
|
|
2007-06-25 02:11:14 +02:00
|
|
|
make_patch () {
|
2008-12-22 22:16:51 +01: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 19:43:50 +01:00
|
|
|
esac > "$state_dir"/patch
|
2011-02-06 19:43:37 +01:00
|
|
|
test -f "$msg" ||
|
|
|
|
commit_message "$1" > "$msg"
|
|
|
|
test -f "$author_script" ||
|
|
|
|
get_author_ident_from_commit "$1" > "$author_script"
|
2007-06-25 02:11:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
die_with_patch () {
|
2011-02-06 19:43:50 +01:00
|
|
|
echo "$1" > "$state_dir"/stopped-sha
|
2007-06-25 02:11:14 +02:00
|
|
|
make_patch "$1"
|
|
|
|
die "$2"
|
|
|
|
}
|
|
|
|
|
2011-11-30 16:52:51 +01:00
|
|
|
exit_with_patch () {
|
|
|
|
echo "$1" > "$state_dir"/stopped-sha
|
|
|
|
make_patch $1
|
|
|
|
git rev-parse --verify HEAD > "$amend"
|
2014-02-10 02:03:37 +01:00
|
|
|
gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
|
2011-11-30 16:52:51 +01:00
|
|
|
warn "You can amend the commit now, with"
|
|
|
|
warn
|
2014-02-10 02:03:37 +01:00
|
|
|
warn " git commit --amend $gpg_sign_opt_quoted"
|
2011-11-30 16:52:51 +01:00
|
|
|
warn
|
|
|
|
warn "Once you are satisfied with your changes, run"
|
|
|
|
warn
|
|
|
|
warn " git rebase --continue"
|
|
|
|
warn
|
|
|
|
exit $2
|
|
|
|
}
|
|
|
|
|
2007-06-25 19:56:55 +02:00
|
|
|
die_abort () {
|
2011-02-06 19:43:50 +01:00
|
|
|
rm -rf "$state_dir"
|
2007-06-25 19:56:55 +02:00
|
|
|
die "$1"
|
|
|
|
}
|
|
|
|
|
2007-09-25 17:42:51 +02:00
|
|
|
has_action () {
|
2013-02-12 00:08:04 +01:00
|
|
|
test -n "$(git stripspace --strip-comments <"$1")"
|
2007-09-25 17:42:51 +02:00
|
|
|
}
|
|
|
|
|
2012-04-20 16:36:17 +02:00
|
|
|
is_empty_commit() {
|
|
|
|
tree=$(git rev-parse -q --verify "$1"^{tree} 2>/dev/null ||
|
|
|
|
die "$1: not a commit that can be picked")
|
|
|
|
ptree=$(git rev-parse -q --verify "$1"^^{tree} 2>/dev/null ||
|
|
|
|
ptree=4b825dc642cb6eb9a060e54bf8d69288fbee4904)
|
|
|
|
test "$tree" = "$ptree"
|
|
|
|
}
|
|
|
|
|
2013-01-12 21:46:01 +01:00
|
|
|
is_merge_commit()
|
|
|
|
{
|
|
|
|
git rev-parse --verify --quiet "$1"^2 >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
2010-01-14 06:54:53 +01:00
|
|
|
# Run command with GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
|
|
|
|
# GIT_AUTHOR_DATE exported from the current environment.
|
|
|
|
do_with_author () {
|
2010-01-22 22:09:24 +01:00
|
|
|
(
|
|
|
|
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
|
|
|
|
"$@"
|
|
|
|
)
|
2010-01-14 06:54:53 +01:00
|
|
|
}
|
|
|
|
|
2011-10-17 22:26:23 +02: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 02:11:14 +02:00
|
|
|
pick_one () {
|
2010-03-06 21:34:46 +01:00
|
|
|
ff=--ff
|
2012-04-20 16:36:17 +02:00
|
|
|
|
2010-03-06 21:34:46 +01:00
|
|
|
case "$1" in -n) sha1=$2; ff= ;; *) sha1=$1 ;; esac
|
2011-02-06 19:43:37 +01:00
|
|
|
case "$force_rebase" in '') ;; ?*) ff= ;; esac
|
2007-07-24 00:45:49 +02:00
|
|
|
output git rev-parse --verify $sha1 || die "Invalid commit name: $sha1"
|
2012-04-20 16:36:17 +02:00
|
|
|
|
|
|
|
if is_empty_commit "$sha1"
|
|
|
|
then
|
|
|
|
empty_args="--allow-empty"
|
|
|
|
fi
|
|
|
|
|
2011-02-06 19:43:37 +01:00
|
|
|
test -d "$rewritten" &&
|
2007-06-25 19:59:43 +02:00
|
|
|
pick_one_preserving_merges "$@" && return
|
2014-02-10 02:03:37 +01: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 00:55:20 +02: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 02:11:14 +02:00
|
|
|
}
|
|
|
|
|
2007-06-25 19:59:43 +02:00
|
|
|
pick_one_preserving_merges () {
|
2008-08-13 23:41:23 +02:00
|
|
|
fast_forward=t
|
|
|
|
case "$1" in
|
|
|
|
-n)
|
|
|
|
fast_forward=f
|
|
|
|
sha1=$2
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
sha1=$1
|
|
|
|
;;
|
|
|
|
esac
|
2007-06-25 19:59:43 +02:00
|
|
|
sha1=$(git rev-parse $sha1)
|
|
|
|
|
2011-02-06 19:43:50 +01:00
|
|
|
if test -f "$state_dir"/current-commit
|
2007-06-25 19:59:43 +02:00
|
|
|
then
|
2008-10-22 20:59:30 +02:00
|
|
|
if test "$fast_forward" = t
|
2008-10-15 09:44:36 +02:00
|
|
|
then
|
2010-07-06 07:16:15 +02:00
|
|
|
while read current_commit
|
2008-10-15 09:44:36 +02:00
|
|
|
do
|
2011-02-06 19:43:37 +01:00
|
|
|
git rev-parse HEAD > "$rewritten"/$current_commit
|
2011-02-06 19:43:50 +01:00
|
|
|
done <"$state_dir"/current-commit
|
|
|
|
rm "$state_dir"/current-commit ||
|
2008-10-15 09:44:36 +02:00
|
|
|
die "Cannot write current commit's replacement sha1"
|
|
|
|
fi
|
2007-06-25 19:59:43 +02:00
|
|
|
fi
|
|
|
|
|
2011-02-06 19:43:50 +01:00
|
|
|
echo $sha1 >> "$state_dir"/current-commit
|
2008-08-13 23:41:24 +02:00
|
|
|
|
2007-06-25 19:59:43 +02:00
|
|
|
# rewrite parents; if none were rewritten, we can fast-forward.
|
|
|
|
new_parents=
|
2009-01-02 23:28:28 +01:00
|
|
|
pend=" $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)"
|
|
|
|
if test "$pend" = " "
|
|
|
|
then
|
|
|
|
pend=" root"
|
|
|
|
fi
|
2008-10-06 06:26:52 +02:00
|
|
|
while [ "$pend" != "" ]
|
2007-06-25 19:59:43 +02:00
|
|
|
do
|
2008-10-06 06:26:52 +02:00
|
|
|
p=$(expr "$pend" : ' \([^ ]*\)')
|
|
|
|
pend="${pend# $p}"
|
|
|
|
|
2011-02-06 19:43:37 +01:00
|
|
|
if test -f "$rewritten"/$p
|
2007-06-25 19:59:43 +02:00
|
|
|
then
|
2011-02-06 19:43:37 +01:00
|
|
|
new_p=$(cat "$rewritten"/$p)
|
2008-10-15 09:44:40 +02: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 19:59:43 +02: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 17:42:51 +02:00
|
|
|
;;
|
2007-06-25 19:59:43 +02:00
|
|
|
esac
|
2008-07-16 03:51:49 +02:00
|
|
|
else
|
2011-02-06 19:43:37 +01:00
|
|
|
if test -f "$dropped"/$p
|
2008-10-06 06:26:52 +02:00
|
|
|
then
|
|
|
|
fast_forward=f
|
2011-02-06 19:43:37 +01:00
|
|
|
replacement="$(cat "$dropped"/$p)"
|
2009-01-02 23:28:28 +01:00
|
|
|
test -z "$replacement" && replacement=root
|
|
|
|
pend=" $replacement$pend"
|
2008-10-06 06:26:52 +02:00
|
|
|
else
|
|
|
|
new_parents="$new_parents $p"
|
|
|
|
fi
|
2007-06-25 19:59:43 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
case $fast_forward in
|
|
|
|
t)
|
2009-10-24 10:31:32 +02:00
|
|
|
output warn "Fast-forward to $sha1"
|
2008-08-13 23:41:23 +02:00
|
|
|
output git reset --hard $sha1 ||
|
2009-10-24 10:31:32 +02:00
|
|
|
die "Cannot fast-forward to $sha1"
|
2007-06-25 19:59:43 +02:00
|
|
|
;;
|
|
|
|
f)
|
2007-09-25 17:42:51 +02:00
|
|
|
first_parent=$(expr "$new_parents" : ' \([^ ]*\)')
|
2008-10-15 09:44:37 +02:00
|
|
|
|
|
|
|
if [ "$1" != "-n" ]
|
|
|
|
then
|
|
|
|
# detach HEAD to current parent
|
|
|
|
output git checkout $first_parent 2> /dev/null ||
|
|
|
|
die "Cannot move HEAD to $first_parent"
|
|
|
|
fi
|
2007-06-25 19:59:43 +02:00
|
|
|
|
|
|
|
case "$new_parents" in
|
2007-09-25 17:42:51 +02:00
|
|
|
' '*' '*)
|
2008-10-15 09:44:37 +02:00
|
|
|
test "a$1" = a-n && die "Refusing to squash a merge: $sha1"
|
|
|
|
|
2007-06-25 19:59:43 +02:00
|
|
|
# redo merge
|
2011-02-06 19:43:37 +01:00
|
|
|
author_script_content=$(get_author_ident_from_commit $sha1)
|
|
|
|
eval "$author_script_content"
|
|
|
|
msg_content="$(commit_message $sha1)"
|
2007-10-31 03:20:32 +01:00
|
|
|
# No point in merging the first parent, that's HEAD
|
|
|
|
new_parents=${new_parents# $first_parent}
|
2013-08-21 20:48:57 +02:00
|
|
|
merge_args="--no-log --no-ff"
|
2013-07-02 10:05:48 +02:00
|
|
|
if ! do_with_author output eval \
|
2014-02-10 02:03:37 +01:00
|
|
|
'git merge ${gpg_sign_opt:+"$gpg_sign_opt"} \
|
|
|
|
$merge_args $strategy_args -m "$msg_content" $new_parents'
|
2007-06-25 19:59:43 +02:00
|
|
|
then
|
2011-02-06 19:43:37 +01:00
|
|
|
printf "%s\n" "$msg_content" > "$GIT_DIR"/MERGE_MSG
|
2008-12-15 11:05:31 +01:00
|
|
|
die_with_patch $sha1 "Error redoing merge $sha1"
|
2007-06-25 19:59:43 +02:00
|
|
|
fi
|
2011-02-06 19:43:37 +01:00
|
|
|
echo "$sha1 $(git rev-parse HEAD^0)" >> "$rewritten_list"
|
2007-06-25 19:59:43 +02:00
|
|
|
;;
|
|
|
|
*)
|
2014-02-10 02:03:37 +01:00
|
|
|
output eval git cherry-pick \
|
|
|
|
${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \
|
|
|
|
"$strategy_args" "$@" ||
|
2007-06-25 19:59:43 +02:00
|
|
|
die_with_patch $sha1 "Could not pick $sha1"
|
2007-09-25 17:42:51 +02:00
|
|
|
;;
|
2007-06-25 19:59:43 +02:00
|
|
|
esac
|
2007-09-25 17:42:51 +02:00
|
|
|
;;
|
2007-06-25 19:59:43 +02:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2007-07-21 19:09:41 +02:00
|
|
|
nth_string () {
|
|
|
|
case "$1" in
|
|
|
|
*1[0-9]|*[04-9]) echo "$1"th;;
|
|
|
|
*1) echo "$1"st;;
|
|
|
|
*2) echo "$1"nd;;
|
|
|
|
*3) echo "$1"rd;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2010-01-14 06:54:55 +01:00
|
|
|
update_squash_messages () {
|
2011-02-06 19:43:37 +01:00
|
|
|
if test -f "$squash_msg"; then
|
|
|
|
mv "$squash_msg" "$squash_msg".bak || exit
|
|
|
|
count=$(($(sed -n \
|
2013-02-12 00:08:04 +01:00
|
|
|
-e "1s/^. This is a combination of \(.*\) commits\./\1/p" \
|
2011-02-06 19:43:37 +01:00
|
|
|
-e "q" < "$squash_msg".bak)+1))
|
2010-01-14 06:54:54 +01:00
|
|
|
{
|
2013-02-12 00:08:04 +01:00
|
|
|
printf '%s\n' "$comment_char This is a combination of $count commits."
|
2010-01-14 06:54:54 +01:00
|
|
|
sed -e 1d -e '2,/^./{
|
|
|
|
/^$/d
|
2011-02-06 19:43:37 +01:00
|
|
|
}' <"$squash_msg".bak
|
|
|
|
} >"$squash_msg"
|
2007-07-21 19:09:41 +02:00
|
|
|
else
|
2011-02-06 19:43:37 +01:00
|
|
|
commit_message HEAD > "$fixup_msg" || die "Cannot write $fixup_msg"
|
|
|
|
count=2
|
2010-01-14 06:54:54 +01:00
|
|
|
{
|
2013-02-12 00:08:04 +01:00
|
|
|
printf '%s\n' "$comment_char This is a combination of 2 commits."
|
|
|
|
printf '%s\n' "$comment_char The first commit's message is:"
|
2010-01-14 06:54:54 +01:00
|
|
|
echo
|
2011-02-06 19:43:37 +01:00
|
|
|
cat "$fixup_msg"
|
|
|
|
} >"$squash_msg"
|
2007-07-21 19:09:41 +02:00
|
|
|
fi
|
2009-12-07 10:20:59 +01:00
|
|
|
case $1 in
|
|
|
|
squash)
|
2011-02-06 19:43:37 +01:00
|
|
|
rm -f "$fixup_msg"
|
2009-12-07 10:20:59 +01:00
|
|
|
echo
|
2013-02-12 00:08:04 +01:00
|
|
|
printf '%s\n' "$comment_char This is the $(nth_string $count) commit message:"
|
2009-12-07 10:20:59 +01:00
|
|
|
echo
|
2010-01-14 06:54:51 +01:00
|
|
|
commit_message $2
|
2009-12-07 10:20:59 +01:00
|
|
|
;;
|
|
|
|
fixup)
|
|
|
|
echo
|
2013-02-12 00:08:04 +01:00
|
|
|
printf '%s\n' "$comment_char The $(nth_string $count) commit message will be skipped:"
|
2009-12-07 10:20:59 +01:00
|
|
|
echo
|
2013-02-12 00:08:04 +01:00
|
|
|
# Change the space after the comment character to TAB:
|
|
|
|
commit_message $2 | git stripspace --comment-lines | sed -e 's/ / /'
|
2009-12-07 10:20:59 +01:00
|
|
|
;;
|
2011-02-06 19:43:37 +01:00
|
|
|
esac >>"$squash_msg"
|
2007-07-21 19:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
peek_next_command () {
|
2013-02-12 00:08:04 +01:00
|
|
|
git stripspace --strip-comments <"$todo" | sed -n -e 's/ .*//p' -e q
|
2007-07-21 19:09:41 +02:00
|
|
|
}
|
|
|
|
|
2010-01-14 06:54:57 +01: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() {
|
2011-02-06 19:43:37 +01:00
|
|
|
mv "$squash_msg" "$msg" || exit
|
|
|
|
rm -f "$fixup_msg"
|
|
|
|
cp "$msg" "$GIT_DIR"/MERGE_MSG || exit
|
2010-01-14 06:54:57 +01:00
|
|
|
warn
|
|
|
|
warn "Could not apply $1... $2"
|
|
|
|
die_with_patch $1 ""
|
|
|
|
}
|
|
|
|
|
2010-03-12 18:04:30 +01:00
|
|
|
flush_rewritten_pending() {
|
2011-02-06 19:43:37 +01:00
|
|
|
test -s "$rewritten_pending" || return
|
2010-03-12 18:04:30 +01:00
|
|
|
newsha1="$(git rev-parse HEAD^0)"
|
2011-02-06 19:43:37 +01:00
|
|
|
sed "s/$/ $newsha1/" < "$rewritten_pending" >> "$rewritten_list"
|
|
|
|
rm -f "$rewritten_pending"
|
2010-03-12 18:04:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
record_in_rewritten() {
|
|
|
|
oldsha1="$(git rev-parse $1)"
|
2011-02-06 19:43:37 +01:00
|
|
|
echo "$oldsha1" >> "$rewritten_pending"
|
2010-03-12 18:04:30 +01:00
|
|
|
|
|
|
|
case "$(peek_next_command)" in
|
2010-07-06 07:16:15 +02:00
|
|
|
squash|s|fixup|f)
|
2010-03-12 18:04:30 +01:00
|
|
|
;;
|
2010-07-06 07:16:15 +02:00
|
|
|
*)
|
2010-03-12 18:04:30 +01:00
|
|
|
flush_rewritten_pending
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2012-06-26 23:55:23 +02:00
|
|
|
do_pick () {
|
|
|
|
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 \
|
|
|
|
--no-post-rewrite -n -q -C $1 &&
|
|
|
|
pick_one -n $1 &&
|
|
|
|
git commit --allow-empty --allow-empty-message \
|
2014-02-10 02:03:37 +01:00
|
|
|
--amend --no-post-rewrite -n -q -C $1 \
|
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2012-06-26 23:55:23 +02:00
|
|
|
die_with_patch $1 "Could not apply $1... $2"
|
|
|
|
else
|
|
|
|
pick_one $1 ||
|
|
|
|
die_with_patch $1 "Could not apply $1... $2"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2007-06-25 02:11:14 +02:00
|
|
|
do_next () {
|
2015-05-22 15:15:49 +02:00
|
|
|
rm -f "$msg" "$author_script" "$amend" "$state_dir"/stopped-sha || exit
|
2011-02-06 19:43:37 +01:00
|
|
|
read -r command sha1 rest < "$todo"
|
2007-06-25 02:11:14 +02:00
|
|
|
case "$command" in
|
2015-06-29 22:20:30 +02:00
|
|
|
"$comment_char"*|''|noop|drop|d)
|
2007-06-25 02:11:14 +02:00
|
|
|
mark_action_done
|
|
|
|
;;
|
2015-10-28 15:54:48 +01:00
|
|
|
"$cr")
|
|
|
|
# Work around CR left by "read" (e.g. with Git for Windows' Bash).
|
|
|
|
mark_action_done
|
|
|
|
;;
|
2007-09-29 04:32:11 +02:00
|
|
|
pick|p)
|
2007-06-25 02:11:14 +02:00
|
|
|
comment_for_reflog pick
|
|
|
|
|
|
|
|
mark_action_done
|
2012-06-26 23:55:23 +02:00
|
|
|
do_pick $sha1 "$rest"
|
2010-03-12 18:04:30 +01:00
|
|
|
record_in_rewritten $sha1
|
2007-06-25 02:11:14 +02:00
|
|
|
;;
|
2009-10-07 08:13:23 +02:00
|
|
|
reword|r)
|
|
|
|
comment_for_reflog reword
|
|
|
|
|
|
|
|
mark_action_done
|
2012-06-26 23:55:23 +02:00
|
|
|
do_pick $sha1 "$rest"
|
2014-02-10 02:03:37 +01:00
|
|
|
git commit --amend --no-post-rewrite ${gpg_sign_opt:+"$gpg_sign_opt"} || {
|
2011-11-30 16:52:51 +01:00
|
|
|
warn "Could not amend commit after successfully picking $sha1... $rest"
|
|
|
|
warn "This is most likely due to an empty commit message, or the pre-commit hook"
|
|
|
|
warn "failed. If the pre-commit hook failed, you may need to resolve the issue before"
|
|
|
|
warn "you are able to reword the commit."
|
|
|
|
exit_with_patch $sha1 1
|
|
|
|
}
|
2010-03-12 18:04:30 +01:00
|
|
|
record_in_rewritten $sha1
|
2009-10-07 08:13:23 +02:00
|
|
|
;;
|
2007-09-29 04:32:11 +02:00
|
|
|
edit|e)
|
2007-06-25 02:11:14 +02:00
|
|
|
comment_for_reflog edit
|
|
|
|
|
|
|
|
mark_action_done
|
2012-06-26 23:55:23 +02:00
|
|
|
do_pick $sha1 "$rest"
|
2016-03-28 18:00:00 +02:00
|
|
|
sha1_abbrev=$(git rev-parse --short $sha1)
|
|
|
|
warn "Stopped at $sha1_abbrev... $rest"
|
2011-11-30 16:52:51 +01:00
|
|
|
exit_with_patch $sha1 0
|
2007-06-25 02:11:14 +02:00
|
|
|
;;
|
2009-12-07 10:20:59 +01: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 02:11:14 +02:00
|
|
|
|
2011-02-06 19:43:37 +01:00
|
|
|
test -f "$done" && has_action "$done" ||
|
2009-12-07 10:20:59 +01:00
|
|
|
die "Cannot '$squash_style' without a previous commit"
|
2007-06-25 02:11:14 +02:00
|
|
|
|
|
|
|
mark_action_done
|
2010-01-14 06:54:55 +01:00
|
|
|
update_squash_messages $squash_style $sha1
|
2011-02-06 19:43:37 +01:00
|
|
|
author_script_content=$(get_author_ident_from_commit HEAD)
|
|
|
|
echo "$author_script_content" > "$author_script"
|
|
|
|
eval "$author_script_content"
|
2012-07-24 14:17:03 +02:00
|
|
|
if ! pick_one -n $sha1
|
|
|
|
then
|
|
|
|
git rev-parse --verify HEAD >"$amend"
|
|
|
|
die_failed_squash $sha1 "$rest"
|
|
|
|
fi
|
2007-07-21 19:09:41 +02:00
|
|
|
case "$(peek_next_command)" in
|
2009-12-07 10:20:59 +01:00
|
|
|
squash|s|fixup|f)
|
2010-01-14 06:54:55 +01:00
|
|
|
# This is an intermediate commit; its message will only be
|
|
|
|
# used in case of trouble. So use the long version:
|
2014-02-10 02:03:37 +01:00
|
|
|
do_with_author output git commit --amend --no-verify -F "$squash_msg" \
|
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2010-01-14 06:54:57 +01:00
|
|
|
die_failed_squash $sha1 "$rest"
|
2007-09-25 17:42:51 +02:00
|
|
|
;;
|
2007-07-21 19:09:41 +02:00
|
|
|
*)
|
2010-01-14 06:54:55 +01:00
|
|
|
# This is the final command of this squash/fixup group
|
2011-02-06 19:43:37 +01:00
|
|
|
if test -f "$fixup_msg"
|
2010-01-14 06:54:55 +01:00
|
|
|
then
|
2014-02-10 02:03:37 +01:00
|
|
|
do_with_author git commit --amend --no-verify -F "$fixup_msg" \
|
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2010-01-14 06:54:57 +01:00
|
|
|
die_failed_squash $sha1 "$rest"
|
|
|
|
else
|
2011-02-06 19:43:37 +01:00
|
|
|
cp "$squash_msg" "$GIT_DIR"/SQUASH_MSG || exit
|
2010-01-14 06:54:57 +01:00
|
|
|
rm -f "$GIT_DIR"/MERGE_MSG
|
2014-02-10 02:03:37 +01:00
|
|
|
do_with_author git commit --amend --no-verify -F "$GIT_DIR"/SQUASH_MSG -e \
|
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2010-01-14 06:54:57 +01:00
|
|
|
die_failed_squash $sha1 "$rest"
|
2010-01-14 06:54:55 +01:00
|
|
|
fi
|
2011-02-06 19:43:37 +01:00
|
|
|
rm -f "$squash_msg" "$fixup_msg"
|
2007-09-25 17:42:51 +02:00
|
|
|
;;
|
2007-07-21 19:09:41 +02:00
|
|
|
esac
|
2010-03-12 18:04:30 +01:00
|
|
|
record_in_rewritten $sha1
|
2007-06-25 02:11:14 +02:00
|
|
|
;;
|
2010-08-10 17:17:51 +02:00
|
|
|
x|"exec")
|
2011-02-06 19:43:37 +01:00
|
|
|
read -r command rest < "$todo"
|
2010-08-10 17:17:51 +02:00
|
|
|
mark_action_done
|
|
|
|
printf 'Executing: %s\n' "$rest"
|
2015-11-13 07:03:19 +01:00
|
|
|
"${SHELL:-@SHELL_PATH@}" -c "$rest" # Actual execution
|
2010-08-10 17:17:51 +02:00
|
|
|
status=$?
|
2011-08-24 20:54:50 +02: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 17:17:51 +02:00
|
|
|
if test "$status" -ne 0
|
|
|
|
then
|
|
|
|
warn "Execution failed: $rest"
|
2011-08-24 20:54:50 +02:00
|
|
|
test "$dirty" = f ||
|
|
|
|
warn "and made changes to the index and/or the working tree"
|
|
|
|
|
2010-08-10 17:17:51 +02:00
|
|
|
warn "You can fix the problem, and then run"
|
|
|
|
warn
|
|
|
|
warn " git rebase --continue"
|
|
|
|
warn
|
2012-09-18 13:15:26 +02:00
|
|
|
if test $status -eq 127 # command not found
|
|
|
|
then
|
|
|
|
status=1
|
|
|
|
fi
|
2010-08-10 17:17:51 +02:00
|
|
|
exit "$status"
|
2011-08-24 20:54:50 +02:00
|
|
|
elif test "$dirty" = t
|
2010-08-10 17:17:51 +02:00
|
|
|
then
|
2011-08-24 20:54:50 +02:00
|
|
|
warn "Execution succeeded: $rest"
|
|
|
|
warn "but left changes to the index and/or the working tree"
|
2010-08-10 17:17:51 +02:00
|
|
|
warn "Commit or stash your changes, and then run"
|
|
|
|
warn
|
|
|
|
warn " git rebase --continue"
|
|
|
|
warn
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2007-06-25 02:11:14 +02:00
|
|
|
*)
|
|
|
|
warn "Unknown command: $command $sha1 $rest"
|
2012-09-19 08:43:54 +02:00
|
|
|
fixtodo="Please fix this using 'git rebase --edit-todo'."
|
2009-10-27 15:58:14 +01:00
|
|
|
if git rev-parse --verify -q "$sha1" >/dev/null
|
|
|
|
then
|
2012-09-19 08:43:54 +02:00
|
|
|
die_with_patch $sha1 "$fixtodo"
|
2009-10-27 15:58:14 +01:00
|
|
|
else
|
2012-09-19 08:43:54 +02:00
|
|
|
die "$fixtodo"
|
2009-10-27 15:58:14 +01:00
|
|
|
fi
|
2007-09-25 17:42:51 +02:00
|
|
|
;;
|
2007-06-25 02:11:14 +02:00
|
|
|
esac
|
2011-02-06 19:43:37 +01:00
|
|
|
test -s "$todo" && return
|
2007-06-25 02:11:14 +02:00
|
|
|
|
2007-06-25 19:58:28 +02:00
|
|
|
comment_for_reflog finish &&
|
2011-02-06 19:43:37 +01:00
|
|
|
newhead=$(git rev-parse HEAD) &&
|
2011-02-06 19:43:50 +01:00
|
|
|
case $head_name in
|
2007-09-25 17:43:15 +02:00
|
|
|
refs/*)
|
2012-08-10 08:51:19 +02:00
|
|
|
message="$GIT_REFLOG_ACTION: $head_name onto $onto" &&
|
2011-02-06 19:43:50 +01:00
|
|
|
git update-ref -m "$message" $head_name $newhead $orig_head &&
|
2011-05-27 22:16:14 +02:00
|
|
|
git symbolic-ref \
|
|
|
|
-m "$GIT_REFLOG_ACTION: returning to $head_name" \
|
|
|
|
HEAD $head_name
|
2007-09-25 17:43:15 +02:00
|
|
|
;;
|
|
|
|
esac && {
|
2011-02-06 19:43:50 +01:00
|
|
|
test ! -f "$state_dir"/verbose ||
|
2011-02-06 19:43:52 +01:00
|
|
|
git diff-tree --stat $orig_head..HEAD
|
2007-07-08 04:02:13 +02:00
|
|
|
} &&
|
2010-03-12 18:04:33 +01:00
|
|
|
{
|
2011-02-06 19:43:37 +01:00
|
|
|
test -s "$rewritten_list" &&
|
|
|
|
git notes copy --for-rewrite=rebase < "$rewritten_list" ||
|
2010-03-12 18:04:33 +01:00
|
|
|
true # we don't care if this copying failed
|
|
|
|
} &&
|
2014-11-30 09:24:38 +01: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 18:04:30 +01:00
|
|
|
true # we don't care if this hook failed
|
|
|
|
fi &&
|
2011-02-06 19:43:50 +01:00
|
|
|
warn "Successfully rebased and updated $head_name."
|
2007-06-25 02:11:14 +02:00
|
|
|
|
2013-05-12 13:56:39 +02:00
|
|
|
return 1 # not failure; just to break the do_rest loop
|
2007-06-25 02:11:14 +02:00
|
|
|
}
|
|
|
|
|
2013-05-12 13:56:39 +02:00
|
|
|
# can only return 0, when the infinite loop breaks
|
2007-06-25 02:11:14 +02:00
|
|
|
do_rest () {
|
|
|
|
while :
|
|
|
|
do
|
2013-05-12 13:56:39 +02:00
|
|
|
do_next || break
|
2007-06-25 02:11:14 +02:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2009-03-03 10:55:31 +01: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-13 22:47:34 +02:00
|
|
|
while read -r command rest
|
2009-03-03 10:55:31 +01: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-13 22:47:34 +02:00
|
|
|
case "$fd,$command" in
|
|
|
|
3,pick|3,p)
|
2011-02-06 19:43:37 +01:00
|
|
|
# pick a commit whose parent is current $onto -> skip
|
2010-09-17 23:42:51 +02: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-13 22:47:34 +02:00
|
|
|
case "$(git rev-parse --verify --quiet "$sha1"^)" in
|
2011-02-06 19:43:37 +01: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-13 22:47:34 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
fd=1
|
|
|
|
;;
|
|
|
|
esac
|
2009-03-03 10:55:31 +01:00
|
|
|
;;
|
2013-08-16 23:44:07 +02:00
|
|
|
3,"$comment_char"*|3,)
|
2009-03-03 10:55:31 +01:00
|
|
|
# copy comments
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
fd=1
|
|
|
|
;;
|
|
|
|
esac
|
2010-08-13 22:47:35 +02:00
|
|
|
printf '%s\n' "$command${rest:+ }$rest" >&$fd
|
2011-02-06 19:43:37 +01:00
|
|
|
done <"$todo" >"$todo.new" 3>>"$done" &&
|
|
|
|
mv -f "$todo".new "$todo" &&
|
2010-03-12 18:04:30 +01:00
|
|
|
case "$(peek_next_command)" in
|
|
|
|
squash|s|fixup|f)
|
2011-02-06 19:43:37 +01:00
|
|
|
record_in_rewritten "$onto"
|
2010-03-12 18:04:30 +01:00
|
|
|
;;
|
|
|
|
esac ||
|
2009-03-03 10:55:31 +01:00
|
|
|
die "Could not skip unnecessary pick commands"
|
|
|
|
}
|
|
|
|
|
2013-08-24 02:10:42 +02: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 10:18:41 +02:00
|
|
|
sha1=$(git rev-parse --verify --quiet "$@" ${rest%%[ ]*}) &&
|
|
|
|
rest="$sha1 ${rest#*[ ]}"
|
2013-08-24 02:10:42 +02: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 17:53:05 +02:00
|
|
|
transform_todo_ids --short
|
2013-08-24 02:10:42 +02:00
|
|
|
}
|
|
|
|
|
2009-12-08 04:13:14 +01: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-13 18:26:58 +02: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 04:13:14 +01:00
|
|
|
rearrange_squash () {
|
2010-11-04 23:36:32 +01:00
|
|
|
# extract fixup!/squash! lines and resolve any referenced sha1's
|
|
|
|
while read -r pick sha1 message
|
|
|
|
do
|
2015-06-13 18:26:58 +02:00
|
|
|
test -z "${format}" || message=$(git log -n 1 --format="%s" ${sha1})
|
2010-11-04 23:36:32 +01:00
|
|
|
case "$message" in
|
|
|
|
"squash! "*|"fixup! "*)
|
|
|
|
action="${message%%!*}"
|
2013-06-27 21:26:31 +02: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 00:56:43 +01:00
|
|
|
printf '%s %s %s %s\n' "$sha1" "$action" "$prefix" "$rest"
|
2010-11-04 23:36:32 +01: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-27 21:26:31 +02:00
|
|
|
echo "$sha1 +$action $prefix $fullsha"
|
2010-11-04 23:36:32 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
esac
|
|
|
|
done >"$1.sq" <"$1"
|
2009-12-08 04:13:14 +01:00
|
|
|
test -s "$1.sq" || return
|
|
|
|
|
|
|
|
used=
|
2010-07-06 08:08:36 +02:00
|
|
|
while read -r pick sha1 message
|
2009-12-08 04:13:14 +01:00
|
|
|
do
|
|
|
|
case " $used" in
|
|
|
|
*" $sha1 "*) continue ;;
|
|
|
|
esac
|
2010-07-22 21:15:11 +02:00
|
|
|
printf '%s\n' "$pick $sha1 $message"
|
2015-06-13 18:26:58 +02:00
|
|
|
test -z "${format}" || message=$(git log -n 1 --format="%s" ${sha1})
|
2010-11-04 23:36:31 +01:00
|
|
|
used="$used$sha1 "
|
2013-06-27 21:26:31 +02:00
|
|
|
while read -r squash action msg_prefix msg_content
|
2009-12-08 04:13:14 +01:00
|
|
|
do
|
2010-11-04 23:36:31 +01:00
|
|
|
case " $used" in
|
|
|
|
*" $squash "*) continue ;;
|
|
|
|
esac
|
2010-11-04 23:36:32 +01:00
|
|
|
emit=0
|
|
|
|
case "$action" in
|
|
|
|
+*)
|
|
|
|
action="${action#+}"
|
|
|
|
# full sha1 prefix test
|
2011-02-06 19:43:37 +01:00
|
|
|
case "$msg_content" in "$sha1"*) emit=1;; esac ;;
|
2010-11-04 23:36:32 +01:00
|
|
|
*)
|
|
|
|
# message prefix test
|
2011-02-06 19:43:37 +01:00
|
|
|
case "$message" in "$msg_content"*) emit=1;; esac ;;
|
2010-11-04 23:36:32 +01:00
|
|
|
esac
|
|
|
|
if test $emit = 1; then
|
2015-06-13 18:26:58 +02: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 04:13:14 +01:00
|
|
|
used="$used$squash "
|
2010-11-04 23:36:32 +01:00
|
|
|
fi
|
2009-12-08 04:13:14 +01:00
|
|
|
done <"$1.sq"
|
|
|
|
done >"$1.rearranged" <"$1"
|
|
|
|
cat "$1.rearranged" >"$1"
|
|
|
|
rm -f "$1.sq" "$1.rearranged"
|
|
|
|
}
|
|
|
|
|
2012-06-12 10:05:12 +02: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-29 22:20:32 +02: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 10:18:42 +02:00
|
|
|
# $2: the line number of the input
|
|
|
|
# $3: the input filename
|
2015-06-29 22:20:32 +02: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-13 22:47:33 +02:00
|
|
|
if test -z "$1"
|
2015-06-29 22:20:32 +02: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-13 22:47:33 +02:00
|
|
|
if test -z "$sha1_verif"
|
2015-06-29 22:20:32 +02:00
|
|
|
then
|
|
|
|
badsha=1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test $badsha -ne 0
|
|
|
|
then
|
2015-10-01 10:18:42 +02:00
|
|
|
line="$(sed -n -e "${2}p" "$3")"
|
2015-06-29 22:20:32 +02:00
|
|
|
warn "Warning: the SHA-1 is missing or isn't" \
|
|
|
|
"a commit in the following line:"
|
2015-10-01 10:18:42 +02:00
|
|
|
warn " - $line"
|
2015-06-29 22:20:32 +02: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 10:18:42 +02: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 15:54:48 +01:00
|
|
|
"$cr")
|
|
|
|
# Work around CR left by "read" (e.g. with Git for
|
|
|
|
# Windows' Bash).
|
|
|
|
;;
|
2015-10-01 10:18:42 +02:00
|
|
|
pick|p|drop|d|reword|r|edit|e|squash|s|fixup|f)
|
|
|
|
if ! check_commit_sha "${rest%%[ ]*}" "$lineno" "$1"
|
|
|
|
then
|
2015-06-29 22:20:32 +02:00
|
|
|
retval=1
|
2015-10-01 10:18:42 +02:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
line="$(sed -n -e "${lineno}p" "$1")"
|
|
|
|
warn "Warning: the command isn't recognized" \
|
|
|
|
"in the following line:"
|
|
|
|
warn " - $line"
|
|
|
|
warn
|
|
|
|
retval=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done <"$1"
|
|
|
|
return $retval
|
2015-06-29 22:20:32 +02:00
|
|
|
}
|
|
|
|
|
2015-06-29 22:20:31 +02: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"
|
|
|
|
output git checkout $onto || die_abort "could not detach HEAD"
|
|
|
|
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-29 22:20:32 +02:00
|
|
|
# Check if there is an unrecognized command or a
|
|
|
|
# bad SHA-1 in a command.
|
2015-06-29 22:20:31 +02: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
|
|
|
|
|
|
|
|
warn "Warning: some commits may have been dropped" \
|
|
|
|
"accidentally."
|
|
|
|
warn "Dropped commits (newer to older):"
|
|
|
|
|
|
|
|
# Make the list user-friendly and display
|
|
|
|
opt="--no-walk=sorted --format=oneline --abbrev-commit --stdin"
|
|
|
|
git rev-list $opt <"$todo".miss | warn_lines
|
|
|
|
|
|
|
|
warn "To avoid this message, use \"drop\" to" \
|
|
|
|
"explicitly remove a commit."
|
|
|
|
warn
|
|
|
|
warn "Use 'git config rebase.missingCommitsCheck' to change" \
|
|
|
|
"the level of warnings."
|
|
|
|
warn "The possible behaviours are: ignore, warn, error."
|
|
|
|
warn
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
ignore)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
warn "Unrecognized setting $check_level for option" \
|
|
|
|
"rebase.missingCommitsCheck. Ignoring."
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2015-10-01 10:18:42 +02:00
|
|
|
if ! check_bad_cmd_and_sha "$todo"
|
2015-06-29 22:20:32 +02:00
|
|
|
then
|
|
|
|
raise_error=t
|
|
|
|
fi
|
|
|
|
|
2015-06-29 22:20:31 +02: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
|
|
|
|
|
|
|
|
warn "You can fix this with 'git rebase --edit-todo'."
|
|
|
|
die "Or you can abort the rebase with 'git rebase --abort'."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-04-11 10:28:17 +02: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 17:33:29 +02: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 10:28:17 +02: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 19:43:39 +01:00
|
|
|
case "$action" in
|
|
|
|
continue)
|
|
|
|
# do we have anything to commit?
|
2012-04-07 12:20:53 +02:00
|
|
|
if git diff-index --cached --quiet HEAD --
|
2011-02-06 19:43:39 +01:00
|
|
|
then
|
2015-06-18 18:38:53 +02:00
|
|
|
# Nothing to commit -- skip this commit
|
|
|
|
|
|
|
|
test ! -f "$GIT_DIR"/CHERRY_PICK_HEAD ||
|
|
|
|
rm "$GIT_DIR"/CHERRY_PICK_HEAD ||
|
|
|
|
die "Could not remove CHERRY_PICK_HEAD"
|
2011-02-06 19:43:39 +01:00
|
|
|
else
|
2011-08-24 16:01:48 +02:00
|
|
|
if ! test -f "$author_script"
|
|
|
|
then
|
2014-02-10 02:03:37 +01:00
|
|
|
gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
|
2011-08-24 16:01:48 +02:00
|
|
|
die "You have staged changes in your working tree. If these changes are meant to be
|
|
|
|
squashed into the previous commit, run:
|
|
|
|
|
2014-02-10 02:03:37 +01:00
|
|
|
git commit --amend $gpg_sign_opt_quoted
|
2011-08-24 16:01:48 +02:00
|
|
|
|
|
|
|
If they are meant to go into a new commit, run:
|
|
|
|
|
2014-02-10 02:03:37 +01:00
|
|
|
git commit $gpg_sign_opt_quoted
|
2011-08-24 16:01:48 +02:00
|
|
|
|
|
|
|
In both case, once you're done, continue with:
|
|
|
|
|
|
|
|
git rebase --continue
|
|
|
|
"
|
|
|
|
fi
|
2011-02-06 19:43:39 +01:00
|
|
|
. "$author_script" ||
|
2011-08-24 16:01:48 +02:00
|
|
|
die "Error trying to find the author identity to amend commit"
|
2011-02-06 19:43:39 +01:00
|
|
|
if test -f "$amend"
|
2007-12-20 08:12:12 +01:00
|
|
|
then
|
2011-02-06 19:43:39 +01:00
|
|
|
current_head=$(git rev-parse --verify HEAD)
|
|
|
|
test "$current_head" = $(cat "$amend") ||
|
|
|
|
die "\
|
2008-09-09 14:05:26 +02:00
|
|
|
You have uncommitted changes in your working tree. Please, commit them
|
|
|
|
first and then run 'git rebase --continue' again."
|
2014-02-10 02:03:37 +01:00
|
|
|
do_with_author git commit --amend --no-verify -F "$msg" -e \
|
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2012-07-24 14:17:03 +02:00
|
|
|
die "Could not commit staged changes."
|
|
|
|
else
|
2014-02-10 02:03:37 +01:00
|
|
|
do_with_author git commit --no-verify -F "$msg" -e \
|
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2012-07-24 14:17:03 +02:00
|
|
|
die "Could not commit staged changes."
|
2007-12-20 08:12:12 +01:00
|
|
|
fi
|
2011-02-06 19:43:39 +01:00
|
|
|
fi
|
2007-07-08 04:01:29 +02:00
|
|
|
|
2015-05-22 15:15:49 +02:00
|
|
|
if test -r "$state_dir"/stopped-sha
|
|
|
|
then
|
|
|
|
record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
|
|
|
|
fi
|
2010-03-28 21:36:00 +02:00
|
|
|
|
2011-02-06 19:43:39 +01:00
|
|
|
require_clean_work_tree "rebase"
|
|
|
|
do_rest
|
2013-05-12 13:56:39 +02:00
|
|
|
return 0
|
2011-02-06 19:43:39 +01:00
|
|
|
;;
|
|
|
|
skip)
|
|
|
|
git rerere clear
|
|
|
|
|
2011-02-06 19:43:52 +01:00
|
|
|
do_rest
|
2013-05-12 13:56:39 +02:00
|
|
|
return 0
|
2011-02-06 19:43:39 +01:00
|
|
|
;;
|
2012-09-18 03:28:09 +02:00
|
|
|
edit-todo)
|
2013-02-12 00:08:04 +01:00
|
|
|
git stripspace --strip-comments <"$todo" >"$todo".new
|
2012-09-18 03:28:09 +02:00
|
|
|
mv -f "$todo".new "$todo"
|
2013-08-24 02:10:42 +02:00
|
|
|
collapse_todo_ids
|
2012-09-18 03:28:09 +02:00
|
|
|
append_todo_help
|
2013-02-12 00:08:04 +01:00
|
|
|
git stripspace --comment-lines >>"$todo" <<\EOF
|
|
|
|
|
|
|
|
You are editing the todo file of an ongoing interactive rebase.
|
|
|
|
To continue rebase after editing, run:
|
|
|
|
git rebase --continue
|
|
|
|
|
2012-09-18 03:28:09 +02:00
|
|
|
EOF
|
|
|
|
|
|
|
|
git_sequence_editor "$todo" ||
|
|
|
|
die "Could not execute editor"
|
2013-08-24 02:10:42 +02:00
|
|
|
expand_todo_ids
|
2012-09-18 03:28:09 +02:00
|
|
|
|
|
|
|
exit
|
|
|
|
;;
|
2011-02-06 19:43:39 +01:00
|
|
|
esac
|
2007-06-25 02:11:14 +02:00
|
|
|
|
2011-02-06 19:43:35 +01:00
|
|
|
git var GIT_COMMITTER_IDENT >/dev/null ||
|
|
|
|
die "You need to set your committer info first"
|
2007-06-25 02:11:14 +02:00
|
|
|
|
2011-02-06 19:43:35 +01:00
|
|
|
comment_for_reflog start
|
|
|
|
|
2011-02-06 19:43:42 +01:00
|
|
|
if test ! -z "$switch_to"
|
2011-02-06 19:43:35 +01:00
|
|
|
then
|
2013-06-16 10:45:13 +02:00
|
|
|
GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to"
|
2011-02-06 19:43:42 +01:00
|
|
|
output git checkout "$switch_to" -- ||
|
2013-06-16 10:45:13 +02:00
|
|
|
die "Could not checkout $switch_to"
|
|
|
|
|
|
|
|
comment_for_reflog start
|
2011-02-06 19:43:35 +01:00
|
|
|
fi
|
|
|
|
|
2011-02-06 19:43:50 +01:00
|
|
|
orig_head=$(git rev-parse --verify HEAD) || die "No HEAD?"
|
2013-05-12 13:56:36 +02:00
|
|
|
mkdir -p "$state_dir" || die "Could not create temporary $state_dir"
|
2011-02-06 19:43:35 +01:00
|
|
|
|
2011-02-06 19:43:50 +01:00
|
|
|
: > "$state_dir"/interactive || die "Could not mark as interactive"
|
2011-02-06 19:43:53 +01:00
|
|
|
write_basic_state
|
2011-02-06 19:43:37 +01:00
|
|
|
if test t = "$preserve_merges"
|
2011-02-06 19:43:35 +01:00
|
|
|
then
|
2011-02-06 19:43:37 +01:00
|
|
|
if test -z "$rebase_root"
|
2011-02-06 19:43:35 +01:00
|
|
|
then
|
2011-02-06 19:43:37 +01:00
|
|
|
mkdir "$rewritten" &&
|
2011-02-06 19:43:50 +01:00
|
|
|
for c in $(git merge-base --all $orig_head $upstream)
|
2008-10-15 09:44:38 +02:00
|
|
|
do
|
2011-02-06 19:43:37 +01:00
|
|
|
echo $onto > "$rewritten"/$c ||
|
2011-02-06 19:43:35 +01:00
|
|
|
die "Could not init rewritten commits"
|
2008-10-15 09:44:38 +02:00
|
|
|
done
|
2011-02-06 19:43:35 +01:00
|
|
|
else
|
2011-02-06 19:43:37 +01:00
|
|
|
mkdir "$rewritten" &&
|
|
|
|
echo $onto > "$rewritten"/root ||
|
2011-02-06 19:43:35 +01:00
|
|
|
die "Could not init rewritten commits"
|
|
|
|
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 19:43:37 +01:00
|
|
|
merges_option=
|
2011-02-06 19:43:35 +01:00
|
|
|
else
|
2011-02-06 19:43:37 +01:00
|
|
|
merges_option="--no-merges --cherry-pick"
|
2011-02-06 19:43:35 +01:00
|
|
|
fi
|
|
|
|
|
2011-02-06 19:43:50 +01:00
|
|
|
shorthead=$(git rev-parse --short $orig_head)
|
2011-02-06 19:43:37 +01:00
|
|
|
shortonto=$(git rev-parse --short $onto)
|
|
|
|
if test -z "$rebase_root"
|
|
|
|
# this is now equivalent to ! -z "$upstream"
|
2011-02-06 19:43:35 +01:00
|
|
|
then
|
2011-02-06 19:43:37 +01:00
|
|
|
shortupstream=$(git rev-parse --short $upstream)
|
2011-02-06 19:43:50 +01:00
|
|
|
revisions=$upstream...$orig_head
|
2011-02-06 19:43:37 +01:00
|
|
|
shortrevisions=$shortupstream..$shorthead
|
2011-02-06 19:43:35 +01:00
|
|
|
else
|
2011-02-06 19:43:50 +01:00
|
|
|
revisions=$onto...$orig_head
|
2011-02-06 19:43:37 +01:00
|
|
|
shortrevisions=$shorthead
|
2011-02-06 19:43:35 +01:00
|
|
|
fi
|
2015-06-13 18:26:58 +02: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-16 21:23:49 +02:00
|
|
|
$revisions ${restrict_revision+^$restrict_revision} | \
|
2011-02-06 19:43:35 +01:00
|
|
|
sed -n "s/^>//p" |
|
2015-01-22 12:50:15 +01:00
|
|
|
while read -r sha1 rest
|
2011-02-06 19:43:35 +01:00
|
|
|
do
|
2012-04-20 16:36:17 +02:00
|
|
|
|
2015-01-22 12:50:15 +01:00
|
|
|
if test -z "$keep_empty" && is_empty_commit $sha1 && ! is_merge_commit $sha1
|
2012-04-20 16:36:17 +02:00
|
|
|
then
|
2013-02-12 00:08:04 +01:00
|
|
|
comment_out="$comment_char "
|
2012-04-20 16:36:17 +02:00
|
|
|
else
|
|
|
|
comment_out=
|
|
|
|
fi
|
|
|
|
|
2011-02-06 19:43:37 +01:00
|
|
|
if test t != "$preserve_merges"
|
2011-02-06 19:43:35 +01:00
|
|
|
then
|
2015-01-22 12:50:15 +01:00
|
|
|
printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo"
|
2011-02-06 19:43:35 +01:00
|
|
|
else
|
2011-02-06 19:43:37 +01:00
|
|
|
if test -z "$rebase_root"
|
2008-10-15 09:44:38 +02:00
|
|
|
then
|
2011-02-06 19:43:35 +01:00
|
|
|
preserve=t
|
|
|
|
for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
|
2008-10-15 09:44:38 +02: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 00:12:01 +02:00
|
|
|
if test -f "$rewritten"/$p
|
2008-10-15 09:44:38 +02:00
|
|
|
then
|
2011-02-06 19:43:35 +01:00
|
|
|
preserve=f
|
2008-10-15 09:44:38 +02:00
|
|
|
fi
|
|
|
|
done
|
2011-02-06 19:43:35 +01:00
|
|
|
else
|
|
|
|
preserve=f
|
|
|
|
fi
|
|
|
|
if test f = "$preserve"
|
|
|
|
then
|
2011-02-06 19:43:37 +01:00
|
|
|
touch "$rewritten"/$sha1
|
2015-01-22 12:50:15 +01:00
|
|
|
printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo"
|
2008-10-15 09:44:38 +02:00
|
|
|
fi
|
2011-02-06 19:43:35 +01:00
|
|
|
fi
|
|
|
|
done
|
2009-01-02 23:28:28 +01:00
|
|
|
|
2011-02-06 19:43:35 +01:00
|
|
|
# Watch for commits that been dropped by --cherry-pick
|
2011-02-06 19:43:37 +01:00
|
|
|
if test t = "$preserve_merges"
|
2011-02-06 19:43:35 +01:00
|
|
|
then
|
2011-02-06 19:43:37 +01:00
|
|
|
mkdir "$dropped"
|
2011-02-06 19:43:35 +01:00
|
|
|
# Save all non-cherry-picked changes
|
2011-02-06 19:43:37 +01:00
|
|
|
git rev-list $revisions --left-right --cherry-pick | \
|
2011-02-06 19:43:50 +01:00
|
|
|
sed -n "s/^>//p" > "$state_dir"/not-cherry-picks
|
2011-02-06 19:43:35 +01:00
|
|
|
# Now all commits and note which ones are missing in
|
|
|
|
# not-cherry-picks and hence being dropped
|
2011-02-06 19:43:37 +01:00
|
|
|
git rev-list $revisions |
|
2011-02-06 19:43:35 +01:00
|
|
|
while read rev
|
|
|
|
do
|
2016-03-09 00:51:36 +01:00
|
|
|
if test -f "$rewritten"/$rev &&
|
|
|
|
! sane_grep "$rev" "$state_dir"/not-cherry-picks >/dev/null
|
2011-02-06 19:43:35 +01: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 19:43:37 +01:00
|
|
|
git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$dropped"/$rev
|
2015-01-22 12:50:15 +01: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 19:43:37 +01:00
|
|
|
rm "$rewritten"/$rev
|
2011-02-06 19:43:35 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2011-02-06 19:43:37 +01:00
|
|
|
test -s "$todo" || echo noop >> "$todo"
|
|
|
|
test -n "$autosquash" && rearrange_squash "$todo"
|
2012-06-12 10:05:12 +02:00
|
|
|
test -n "$cmd" && add_exec_commands "$todo"
|
|
|
|
|
2014-12-10 19:16:44 +01:00
|
|
|
todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
|
2015-03-04 08:53:04 +01:00
|
|
|
todocount=${todocount##* }
|
2014-12-10 19:16:44 +01:00
|
|
|
|
2013-02-12 00:08:04 +01:00
|
|
|
cat >>"$todo" <<EOF
|
2007-11-22 13:30:10 +01:00
|
|
|
|
2015-03-04 08:53:05 +01:00
|
|
|
$comment_char Rebase $shortrevisions onto $shortonto ($todocount command(s))
|
2012-09-18 03:28:08 +02:00
|
|
|
EOF
|
|
|
|
append_todo_help
|
2013-02-12 00:08:04 +01:00
|
|
|
git stripspace --comment-lines >>"$todo" <<\EOF
|
|
|
|
|
|
|
|
However, if you remove everything, the rebase will be aborted.
|
|
|
|
|
2007-06-25 02:11:14 +02:00
|
|
|
EOF
|
|
|
|
|
2012-04-20 16:36:17 +02:00
|
|
|
if test -z "$keep_empty"
|
|
|
|
then
|
2013-02-12 00:08:04 +01:00
|
|
|
printf '%s\n' "$comment_char Note that empty commits are commented out" >>"$todo"
|
2012-04-20 16:36:17 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2011-02-06 19:43:37 +01:00
|
|
|
has_action "$todo" ||
|
2014-05-20 00:05:20 +02:00
|
|
|
return 2
|
2007-06-25 02:11:14 +02:00
|
|
|
|
2011-02-06 19:43:37 +01:00
|
|
|
cp "$todo" "$todo".backup
|
2015-01-22 12:50:15 +01:00
|
|
|
collapse_todo_ids
|
2011-10-17 22:26:23 +02:00
|
|
|
git_sequence_editor "$todo" ||
|
2011-02-06 19:43:35 +01:00
|
|
|
die_abort "Could not execute editor"
|
2007-06-25 02:11:14 +02:00
|
|
|
|
2011-02-06 19:43:37 +01:00
|
|
|
has_action "$todo" ||
|
2014-05-20 00:05:20 +02:00
|
|
|
return 2
|
2007-06-25 19:56:55 +02:00
|
|
|
|
2015-06-29 22:20:31 +02:00
|
|
|
check_todo_list
|
|
|
|
|
2013-08-24 02:10:42 +02:00
|
|
|
expand_todo_ids
|
|
|
|
|
2011-02-06 19:43:37 +01:00
|
|
|
test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks
|
2009-03-03 10:55:31 +01:00
|
|
|
|
2015-06-29 22:20:31 +02:00
|
|
|
checkout_onto
|
2011-02-06 19:43:35 +01:00
|
|
|
do_rest
|
2014-04-11 10:28:17 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
# ... and then we call the whole thing.
|
|
|
|
git_rebase__interactive
|