2013-11-25 21:03:52 +00: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 00:11:14 +00: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 14:51:54 +00:00
|
|
|
#
|
2010-01-14 05:54:45 +00: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 18:43:37 +00:00
|
|
|
# file and written to the tail of $done.
|
2011-02-06 18:43:50 +00:00
|
|
|
todo="$state_dir"/git-rebase-todo
|
2010-01-14 05:54:45 +00: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 18:43:50 +00:00
|
|
|
done="$state_dir"/done
|
2010-01-14 05:54:45 +00: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 18:43:50 +00:00
|
|
|
msg="$state_dir"/message
|
2010-01-14 05:54:45 +00: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 18:43:37 +00:00
|
|
|
# # This is a combination of $count commits.
|
|
|
|
# where $count is the number of commits whose messages have been
|
2010-01-14 05:54:45 +00: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 18:43:50 +00:00
|
|
|
squash_msg="$state_dir"/message-squash
|
2010-01-14 05:54:45 +00:00
|
|
|
|
2010-01-14 05:54:55 +00: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 18:43:50 +00:00
|
|
|
fixup_msg="$state_dir"/message-fixup
|
2010-01-14 05:54:55 +00:00
|
|
|
|
2011-02-06 18:43:37 +00: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 05:54:45 +00: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 18:43:50 +00:00
|
|
|
rewritten="$state_dir"/rewritten
|
2010-01-14 05:54:45 +00:00
|
|
|
|
2011-02-06 18:43:50 +00:00
|
|
|
dropped="$state_dir"/dropped
|
2010-01-14 05:54:46 +00:00
|
|
|
|
2013-04-25 09:28:54 +00:00
|
|
|
end="$state_dir"/end
|
|
|
|
msgnum="$state_dir"/msgnum
|
|
|
|
|
2010-01-14 05:54:46 +00: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 18:43:50 +00:00
|
|
|
author_script="$state_dir"/author-script
|
2010-01-14 05:54:46 +00:00
|
|
|
|
2010-01-14 05:54:47 +00: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 18:43:50 +00:00
|
|
|
amend="$state_dir"/amend
|
2010-01-14 05:54:47 +00:00
|
|
|
|
2010-03-12 17:04:30 +00: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 18:43:50 +00:00
|
|
|
rewritten_list="$state_dir"/rewritten-list
|
|
|
|
rewritten_pending="$state_dir"/rewritten-pending
|
2011-02-06 18:43:37 +00:00
|
|
|
|
2013-07-02 08:05:48 +00:00
|
|
|
strategy_args=
|
|
|
|
if test -n "$do_merge"
|
|
|
|
then
|
|
|
|
strategy_args=${strategy:+--strategy=$strategy}
|
|
|
|
eval '
|
|
|
|
for strategy_opt in '"$strategy_opts"'
|
|
|
|
do
|
|
|
|
strategy_args="$strategy_args -X$(git rev-parse --sq-quote "${strategy_opt#--}")"
|
|
|
|
done
|
|
|
|
'
|
|
|
|
fi
|
|
|
|
|
2011-02-06 18:43:49 +00:00
|
|
|
GIT_CHERRY_PICK_HELP="$resolvemsg"
|
2007-11-28 08:06:36 +00:00
|
|
|
export GIT_CHERRY_PICK_HELP
|
|
|
|
|
2013-02-11 23:08:04 +00:00
|
|
|
comment_char=$(git config --get core.commentchar 2>/dev/null | cut -c1)
|
|
|
|
: ${comment_char:=#}
|
|
|
|
|
2007-06-25 00:11:14 +00:00
|
|
|
warn () {
|
2010-07-22 19:15:11 +00:00
|
|
|
printf '%s\n' "$*" >&2
|
2007-06-25 00:11:14 +00:00
|
|
|
}
|
|
|
|
|
2010-01-14 05:54:51 +00:00
|
|
|
# Output the commit message for the specified commit.
|
|
|
|
commit_message () {
|
|
|
|
git cat-file commit "$1" | sed "1,/^$/d"
|
|
|
|
}
|
|
|
|
|
2011-02-06 18:43:37 +00:00
|
|
|
orig_reflog_action="$GIT_REFLOG_ACTION"
|
2007-06-25 00:11:14 +00:00
|
|
|
|
|
|
|
comment_for_reflog () {
|
2011-02-06 18:43:37 +00:00
|
|
|
case "$orig_reflog_action" in
|
2007-06-25 00:11:14 +00:00
|
|
|
''|rebase*)
|
|
|
|
GIT_REFLOG_ACTION="rebase -i ($1)"
|
|
|
|
export GIT_REFLOG_ACTION
|
2007-09-25 15:42:51 +00:00
|
|
|
;;
|
2007-06-25 00:11:14 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2008-01-15 04:01:21 +00:00
|
|
|
last_count=
|
2007-06-25 00:11:14 +00:00
|
|
|
mark_action_done () {
|
2011-02-06 18:43:37 +00:00
|
|
|
sed -e 1q < "$todo" >> "$done"
|
|
|
|
sed -e 1d < "$todo" >> "$todo".new
|
|
|
|
mv -f "$todo".new "$todo"
|
2013-02-11 23:08:04 +00:00
|
|
|
new_count=$(git stripspace --strip-comments <"$done" | wc -l)
|
2013-04-25 09:28:54 +00:00
|
|
|
echo $new_count >"$msgnum"
|
2013-02-11 23:08:04 +00:00
|
|
|
total=$(($new_count + $(git stripspace --strip-comments <"$todo" | wc -l)))
|
2013-04-25 09:28:54 +00:00
|
|
|
echo $total >"$end"
|
2011-02-06 18:43:37 +00:00
|
|
|
if test "$last_count" != "$new_count"
|
2008-01-15 04:01:21 +00:00
|
|
|
then
|
2011-02-06 18:43:37 +00:00
|
|
|
last_count=$new_count
|
|
|
|
printf "Rebasing (%d/%d)\r" $new_count $total
|
|
|
|
test -z "$verbose" || echo
|
2008-01-15 04:01:21 +00:00
|
|
|
fi
|
2007-06-25 00:11:14 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:55:20 +00: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 01:28:08 +00:00
|
|
|
append_todo_help () {
|
2013-02-11 23:08:04 +00: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
|
|
|
|
|
|
|
|
These lines can be re-ordered; they are executed from top to bottom.
|
|
|
|
|
|
|
|
If you remove a line here THAT COMMIT WILL BE LOST.
|
2012-09-18 01:28:08 +00:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2007-06-25 00:11:14 +00:00
|
|
|
make_patch () {
|
2008-12-22 21:16:51 +00: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 18:43:50 +00:00
|
|
|
esac > "$state_dir"/patch
|
2011-02-06 18:43:37 +00:00
|
|
|
test -f "$msg" ||
|
|
|
|
commit_message "$1" > "$msg"
|
|
|
|
test -f "$author_script" ||
|
|
|
|
get_author_ident_from_commit "$1" > "$author_script"
|
2007-06-25 00:11:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
die_with_patch () {
|
2011-02-06 18:43:50 +00:00
|
|
|
echo "$1" > "$state_dir"/stopped-sha
|
2007-06-25 00:11:14 +00:00
|
|
|
make_patch "$1"
|
2007-11-22 11:18:10 +00:00
|
|
|
git rerere
|
2007-06-25 00:11:14 +00:00
|
|
|
die "$2"
|
|
|
|
}
|
|
|
|
|
2011-11-30 15:52:51 +00:00
|
|
|
exit_with_patch () {
|
|
|
|
echo "$1" > "$state_dir"/stopped-sha
|
|
|
|
make_patch $1
|
|
|
|
git rev-parse --verify HEAD > "$amend"
|
2014-02-10 01:03:37 +00:00
|
|
|
gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
|
2011-11-30 15:52:51 +00:00
|
|
|
warn "You can amend the commit now, with"
|
|
|
|
warn
|
2014-02-10 01:03:37 +00:00
|
|
|
warn " git commit --amend $gpg_sign_opt_quoted"
|
2011-11-30 15:52:51 +00:00
|
|
|
warn
|
|
|
|
warn "Once you are satisfied with your changes, run"
|
|
|
|
warn
|
|
|
|
warn " git rebase --continue"
|
|
|
|
warn
|
|
|
|
exit $2
|
|
|
|
}
|
|
|
|
|
2007-06-25 17:56:55 +00:00
|
|
|
die_abort () {
|
2011-02-06 18:43:50 +00:00
|
|
|
rm -rf "$state_dir"
|
2007-06-25 17:56:55 +00:00
|
|
|
die "$1"
|
|
|
|
}
|
|
|
|
|
2007-09-25 15:42:51 +00:00
|
|
|
has_action () {
|
2013-02-11 23:08:04 +00:00
|
|
|
test -n "$(git stripspace --strip-comments <"$1")"
|
2007-09-25 15:42:51 +00:00
|
|
|
}
|
|
|
|
|
2012-04-20 14:36:17 +00: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 20:46:01 +00:00
|
|
|
is_merge_commit()
|
|
|
|
{
|
|
|
|
git rev-parse --verify --quiet "$1"^2 >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
2010-01-14 05:54:53 +00: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 21:09:24 +00:00
|
|
|
(
|
|
|
|
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
|
|
|
|
"$@"
|
|
|
|
)
|
2010-01-14 05:54:53 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 20:26:23 +00: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 00:11:14 +00:00
|
|
|
pick_one () {
|
2010-03-06 20:34:46 +00:00
|
|
|
ff=--ff
|
2012-04-20 14:36:17 +00:00
|
|
|
|
2010-03-06 20:34:46 +00:00
|
|
|
case "$1" in -n) sha1=$2; ff= ;; *) sha1=$1 ;; esac
|
2011-02-06 18:43:37 +00:00
|
|
|
case "$force_rebase" in '') ;; ?*) ff= ;; esac
|
2007-07-23 22:45:49 +00:00
|
|
|
output git rev-parse --verify $sha1 || die "Invalid commit name: $sha1"
|
2012-04-20 14:36:17 +00:00
|
|
|
|
|
|
|
if is_empty_commit "$sha1"
|
|
|
|
then
|
|
|
|
empty_args="--allow-empty"
|
|
|
|
fi
|
|
|
|
|
2011-02-06 18:43:37 +00:00
|
|
|
test -d "$rewritten" &&
|
2007-06-25 17:59:43 +00:00
|
|
|
pick_one_preserving_merges "$@" && return
|
2014-02-10 01:03:37 +00:00
|
|
|
output eval git cherry-pick \
|
|
|
|
${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \
|
|
|
|
"$strategy_args" $empty_args $ff "$@"
|
2015-04-28 22:55:20 +00: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 00:11:14 +00:00
|
|
|
}
|
|
|
|
|
2007-06-25 17:59:43 +00:00
|
|
|
pick_one_preserving_merges () {
|
2008-08-13 21:41:23 +00:00
|
|
|
fast_forward=t
|
|
|
|
case "$1" in
|
|
|
|
-n)
|
|
|
|
fast_forward=f
|
|
|
|
sha1=$2
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
sha1=$1
|
|
|
|
;;
|
|
|
|
esac
|
2007-06-25 17:59:43 +00:00
|
|
|
sha1=$(git rev-parse $sha1)
|
|
|
|
|
2011-02-06 18:43:50 +00:00
|
|
|
if test -f "$state_dir"/current-commit
|
2007-06-25 17:59:43 +00:00
|
|
|
then
|
2008-10-22 18:59:30 +00:00
|
|
|
if test "$fast_forward" = t
|
2008-10-15 07:44:36 +00:00
|
|
|
then
|
2010-07-06 05:16:15 +00:00
|
|
|
while read current_commit
|
2008-10-15 07:44:36 +00:00
|
|
|
do
|
2011-02-06 18:43:37 +00:00
|
|
|
git rev-parse HEAD > "$rewritten"/$current_commit
|
2011-02-06 18:43:50 +00:00
|
|
|
done <"$state_dir"/current-commit
|
|
|
|
rm "$state_dir"/current-commit ||
|
2008-10-15 07:44:36 +00:00
|
|
|
die "Cannot write current commit's replacement sha1"
|
|
|
|
fi
|
2007-06-25 17:59:43 +00:00
|
|
|
fi
|
|
|
|
|
2011-02-06 18:43:50 +00:00
|
|
|
echo $sha1 >> "$state_dir"/current-commit
|
2008-08-13 21:41:24 +00:00
|
|
|
|
2007-06-25 17:59:43 +00:00
|
|
|
# rewrite parents; if none were rewritten, we can fast-forward.
|
|
|
|
new_parents=
|
2009-01-02 22:28:28 +00:00
|
|
|
pend=" $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)"
|
|
|
|
if test "$pend" = " "
|
|
|
|
then
|
|
|
|
pend=" root"
|
|
|
|
fi
|
2008-10-06 04:26:52 +00:00
|
|
|
while [ "$pend" != "" ]
|
2007-06-25 17:59:43 +00:00
|
|
|
do
|
2008-10-06 04:26:52 +00:00
|
|
|
p=$(expr "$pend" : ' \([^ ]*\)')
|
|
|
|
pend="${pend# $p}"
|
|
|
|
|
2011-02-06 18:43:37 +00:00
|
|
|
if test -f "$rewritten"/$p
|
2007-06-25 17:59:43 +00:00
|
|
|
then
|
2011-02-06 18:43:37 +00:00
|
|
|
new_p=$(cat "$rewritten"/$p)
|
2008-10-15 07:44:40 +00: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 17:59:43 +00: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 15:42:51 +00:00
|
|
|
;;
|
2007-06-25 17:59:43 +00:00
|
|
|
esac
|
2008-07-16 01:51:49 +00:00
|
|
|
else
|
2011-02-06 18:43:37 +00:00
|
|
|
if test -f "$dropped"/$p
|
2008-10-06 04:26:52 +00:00
|
|
|
then
|
|
|
|
fast_forward=f
|
2011-02-06 18:43:37 +00:00
|
|
|
replacement="$(cat "$dropped"/$p)"
|
2009-01-02 22:28:28 +00:00
|
|
|
test -z "$replacement" && replacement=root
|
|
|
|
pend=" $replacement$pend"
|
2008-10-06 04:26:52 +00:00
|
|
|
else
|
|
|
|
new_parents="$new_parents $p"
|
|
|
|
fi
|
2007-06-25 17:59:43 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
case $fast_forward in
|
|
|
|
t)
|
2009-10-24 08:31:32 +00:00
|
|
|
output warn "Fast-forward to $sha1"
|
2008-08-13 21:41:23 +00:00
|
|
|
output git reset --hard $sha1 ||
|
2009-10-24 08:31:32 +00:00
|
|
|
die "Cannot fast-forward to $sha1"
|
2007-06-25 17:59:43 +00:00
|
|
|
;;
|
|
|
|
f)
|
2007-09-25 15:42:51 +00:00
|
|
|
first_parent=$(expr "$new_parents" : ' \([^ ]*\)')
|
2008-10-15 07:44:37 +00: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 17:59:43 +00:00
|
|
|
|
|
|
|
case "$new_parents" in
|
2007-09-25 15:42:51 +00:00
|
|
|
' '*' '*)
|
2008-10-15 07:44:37 +00:00
|
|
|
test "a$1" = a-n && die "Refusing to squash a merge: $sha1"
|
|
|
|
|
2007-06-25 17:59:43 +00:00
|
|
|
# redo merge
|
2011-02-06 18:43:37 +00:00
|
|
|
author_script_content=$(get_author_ident_from_commit $sha1)
|
|
|
|
eval "$author_script_content"
|
|
|
|
msg_content="$(commit_message $sha1)"
|
2007-10-31 02:20:32 +00:00
|
|
|
# No point in merging the first parent, that's HEAD
|
|
|
|
new_parents=${new_parents# $first_parent}
|
2013-08-21 18:48:57 +00:00
|
|
|
merge_args="--no-log --no-ff"
|
2013-07-02 08:05:48 +00:00
|
|
|
if ! do_with_author output eval \
|
2014-02-10 01:03:37 +00:00
|
|
|
'git merge ${gpg_sign_opt:+"$gpg_sign_opt"} \
|
|
|
|
$merge_args $strategy_args -m "$msg_content" $new_parents'
|
2007-06-25 17:59:43 +00:00
|
|
|
then
|
2011-02-06 18:43:37 +00:00
|
|
|
printf "%s\n" "$msg_content" > "$GIT_DIR"/MERGE_MSG
|
2008-12-15 10:05:31 +00:00
|
|
|
die_with_patch $sha1 "Error redoing merge $sha1"
|
2007-06-25 17:59:43 +00:00
|
|
|
fi
|
2011-02-06 18:43:37 +00:00
|
|
|
echo "$sha1 $(git rev-parse HEAD^0)" >> "$rewritten_list"
|
2007-06-25 17:59:43 +00:00
|
|
|
;;
|
|
|
|
*)
|
2014-02-10 01:03:37 +00:00
|
|
|
output eval git cherry-pick \
|
|
|
|
${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \
|
|
|
|
"$strategy_args" "$@" ||
|
2007-06-25 17:59:43 +00:00
|
|
|
die_with_patch $sha1 "Could not pick $sha1"
|
2007-09-25 15:42:51 +00:00
|
|
|
;;
|
2007-06-25 17:59:43 +00:00
|
|
|
esac
|
2007-09-25 15:42:51 +00:00
|
|
|
;;
|
2007-06-25 17:59:43 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2007-07-21 17:09:41 +00: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 05:54:55 +00:00
|
|
|
update_squash_messages () {
|
2011-02-06 18:43:37 +00:00
|
|
|
if test -f "$squash_msg"; then
|
|
|
|
mv "$squash_msg" "$squash_msg".bak || exit
|
|
|
|
count=$(($(sed -n \
|
2013-02-11 23:08:04 +00:00
|
|
|
-e "1s/^. This is a combination of \(.*\) commits\./\1/p" \
|
2011-02-06 18:43:37 +00:00
|
|
|
-e "q" < "$squash_msg".bak)+1))
|
2010-01-14 05:54:54 +00:00
|
|
|
{
|
2013-02-11 23:08:04 +00:00
|
|
|
printf '%s\n' "$comment_char This is a combination of $count commits."
|
2010-01-14 05:54:54 +00:00
|
|
|
sed -e 1d -e '2,/^./{
|
|
|
|
/^$/d
|
2011-02-06 18:43:37 +00:00
|
|
|
}' <"$squash_msg".bak
|
|
|
|
} >"$squash_msg"
|
2007-07-21 17:09:41 +00:00
|
|
|
else
|
2011-02-06 18:43:37 +00:00
|
|
|
commit_message HEAD > "$fixup_msg" || die "Cannot write $fixup_msg"
|
|
|
|
count=2
|
2010-01-14 05:54:54 +00:00
|
|
|
{
|
2013-02-11 23:08:04 +00: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 05:54:54 +00:00
|
|
|
echo
|
2011-02-06 18:43:37 +00:00
|
|
|
cat "$fixup_msg"
|
|
|
|
} >"$squash_msg"
|
2007-07-21 17:09:41 +00:00
|
|
|
fi
|
2009-12-07 09:20:59 +00:00
|
|
|
case $1 in
|
|
|
|
squash)
|
2011-02-06 18:43:37 +00:00
|
|
|
rm -f "$fixup_msg"
|
2009-12-07 09:20:59 +00:00
|
|
|
echo
|
2013-02-11 23:08:04 +00:00
|
|
|
printf '%s\n' "$comment_char This is the $(nth_string $count) commit message:"
|
2009-12-07 09:20:59 +00:00
|
|
|
echo
|
2010-01-14 05:54:51 +00:00
|
|
|
commit_message $2
|
2009-12-07 09:20:59 +00:00
|
|
|
;;
|
|
|
|
fixup)
|
|
|
|
echo
|
2013-02-11 23:08:04 +00:00
|
|
|
printf '%s\n' "$comment_char The $(nth_string $count) commit message will be skipped:"
|
2009-12-07 09:20:59 +00:00
|
|
|
echo
|
2013-02-11 23:08:04 +00:00
|
|
|
# Change the space after the comment character to TAB:
|
|
|
|
commit_message $2 | git stripspace --comment-lines | sed -e 's/ / /'
|
2009-12-07 09:20:59 +00:00
|
|
|
;;
|
2011-02-06 18:43:37 +00:00
|
|
|
esac >>"$squash_msg"
|
2007-07-21 17:09:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
peek_next_command () {
|
2013-02-11 23:08:04 +00:00
|
|
|
git stripspace --strip-comments <"$todo" | sed -n -e 's/ .*//p' -e q
|
2007-07-21 17:09:41 +00:00
|
|
|
}
|
|
|
|
|
2010-01-14 05:54:57 +00: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 18:43:37 +00:00
|
|
|
mv "$squash_msg" "$msg" || exit
|
|
|
|
rm -f "$fixup_msg"
|
|
|
|
cp "$msg" "$GIT_DIR"/MERGE_MSG || exit
|
2010-01-14 05:54:57 +00:00
|
|
|
warn
|
|
|
|
warn "Could not apply $1... $2"
|
|
|
|
die_with_patch $1 ""
|
|
|
|
}
|
|
|
|
|
2010-03-12 17:04:30 +00:00
|
|
|
flush_rewritten_pending() {
|
2011-02-06 18:43:37 +00:00
|
|
|
test -s "$rewritten_pending" || return
|
2010-03-12 17:04:30 +00:00
|
|
|
newsha1="$(git rev-parse HEAD^0)"
|
2011-02-06 18:43:37 +00:00
|
|
|
sed "s/$/ $newsha1/" < "$rewritten_pending" >> "$rewritten_list"
|
|
|
|
rm -f "$rewritten_pending"
|
2010-03-12 17:04:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
record_in_rewritten() {
|
|
|
|
oldsha1="$(git rev-parse $1)"
|
2011-02-06 18:43:37 +00:00
|
|
|
echo "$oldsha1" >> "$rewritten_pending"
|
2010-03-12 17:04:30 +00:00
|
|
|
|
|
|
|
case "$(peek_next_command)" in
|
2010-07-06 05:16:15 +00:00
|
|
|
squash|s|fixup|f)
|
2010-03-12 17:04:30 +00:00
|
|
|
;;
|
2010-07-06 05:16:15 +00:00
|
|
|
*)
|
2010-03-12 17:04:30 +00:00
|
|
|
flush_rewritten_pending
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2012-06-26 21:55:23 +00: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 01:03:37 +00:00
|
|
|
--amend --no-post-rewrite -n -q -C $1 \
|
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2012-06-26 21:55:23 +00: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 00:11:14 +00:00
|
|
|
do_next () {
|
2015-05-22 13:15:49 +00:00
|
|
|
rm -f "$msg" "$author_script" "$amend" "$state_dir"/stopped-sha || exit
|
2011-02-06 18:43:37 +00:00
|
|
|
read -r command sha1 rest < "$todo"
|
2007-06-25 00:11:14 +00:00
|
|
|
case "$command" in
|
2013-02-11 23:08:04 +00:00
|
|
|
"$comment_char"*|''|noop)
|
2007-06-25 00:11:14 +00:00
|
|
|
mark_action_done
|
|
|
|
;;
|
2007-09-29 02:32:11 +00:00
|
|
|
pick|p)
|
2007-06-25 00:11:14 +00:00
|
|
|
comment_for_reflog pick
|
|
|
|
|
|
|
|
mark_action_done
|
2012-06-26 21:55:23 +00:00
|
|
|
do_pick $sha1 "$rest"
|
2010-03-12 17:04:30 +00:00
|
|
|
record_in_rewritten $sha1
|
2007-06-25 00:11:14 +00:00
|
|
|
;;
|
2009-10-07 06:13:23 +00:00
|
|
|
reword|r)
|
|
|
|
comment_for_reflog reword
|
|
|
|
|
|
|
|
mark_action_done
|
2012-06-26 21:55:23 +00:00
|
|
|
do_pick $sha1 "$rest"
|
2014-02-10 01:03:37 +00:00
|
|
|
git commit --amend --no-post-rewrite ${gpg_sign_opt:+"$gpg_sign_opt"} || {
|
2011-11-30 15:52:51 +00: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 17:04:30 +00:00
|
|
|
record_in_rewritten $sha1
|
2009-10-07 06:13:23 +00:00
|
|
|
;;
|
2007-09-29 02:32:11 +00:00
|
|
|
edit|e)
|
2007-06-25 00:11:14 +00:00
|
|
|
comment_for_reflog edit
|
|
|
|
|
|
|
|
mark_action_done
|
2012-06-26 21:55:23 +00:00
|
|
|
do_pick $sha1 "$rest"
|
2008-07-23 07:46:35 +00:00
|
|
|
warn "Stopped at $sha1... $rest"
|
2011-11-30 15:52:51 +00:00
|
|
|
exit_with_patch $sha1 0
|
2007-06-25 00:11:14 +00:00
|
|
|
;;
|
2009-12-07 09:20:59 +00: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 00:11:14 +00:00
|
|
|
|
2011-02-06 18:43:37 +00:00
|
|
|
test -f "$done" && has_action "$done" ||
|
2009-12-07 09:20:59 +00:00
|
|
|
die "Cannot '$squash_style' without a previous commit"
|
2007-06-25 00:11:14 +00:00
|
|
|
|
|
|
|
mark_action_done
|
2010-01-14 05:54:55 +00:00
|
|
|
update_squash_messages $squash_style $sha1
|
2011-02-06 18:43:37 +00:00
|
|
|
author_script_content=$(get_author_ident_from_commit HEAD)
|
|
|
|
echo "$author_script_content" > "$author_script"
|
|
|
|
eval "$author_script_content"
|
2012-07-24 12:17:03 +00:00
|
|
|
if ! pick_one -n $sha1
|
|
|
|
then
|
|
|
|
git rev-parse --verify HEAD >"$amend"
|
|
|
|
die_failed_squash $sha1 "$rest"
|
|
|
|
fi
|
2007-07-21 17:09:41 +00:00
|
|
|
case "$(peek_next_command)" in
|
2009-12-07 09:20:59 +00:00
|
|
|
squash|s|fixup|f)
|
2010-01-14 05:54:55 +00:00
|
|
|
# This is an intermediate commit; its message will only be
|
|
|
|
# used in case of trouble. So use the long version:
|
2014-02-10 01:03:37 +00:00
|
|
|
do_with_author output git commit --amend --no-verify -F "$squash_msg" \
|
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2010-01-14 05:54:57 +00:00
|
|
|
die_failed_squash $sha1 "$rest"
|
2007-09-25 15:42:51 +00:00
|
|
|
;;
|
2007-07-21 17:09:41 +00:00
|
|
|
*)
|
2010-01-14 05:54:55 +00:00
|
|
|
# This is the final command of this squash/fixup group
|
2011-02-06 18:43:37 +00:00
|
|
|
if test -f "$fixup_msg"
|
2010-01-14 05:54:55 +00:00
|
|
|
then
|
2014-02-10 01:03:37 +00:00
|
|
|
do_with_author git commit --amend --no-verify -F "$fixup_msg" \
|
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2010-01-14 05:54:57 +00:00
|
|
|
die_failed_squash $sha1 "$rest"
|
|
|
|
else
|
2011-02-06 18:43:37 +00:00
|
|
|
cp "$squash_msg" "$GIT_DIR"/SQUASH_MSG || exit
|
2010-01-14 05:54:57 +00:00
|
|
|
rm -f "$GIT_DIR"/MERGE_MSG
|
2014-02-10 01:03:37 +00:00
|
|
|
do_with_author git commit --amend --no-verify -F "$GIT_DIR"/SQUASH_MSG -e \
|
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2010-01-14 05:54:57 +00:00
|
|
|
die_failed_squash $sha1 "$rest"
|
2010-01-14 05:54:55 +00:00
|
|
|
fi
|
2011-02-06 18:43:37 +00:00
|
|
|
rm -f "$squash_msg" "$fixup_msg"
|
2007-09-25 15:42:51 +00:00
|
|
|
;;
|
2007-07-21 17:09:41 +00:00
|
|
|
esac
|
2010-03-12 17:04:30 +00:00
|
|
|
record_in_rewritten $sha1
|
2007-06-25 00:11:14 +00:00
|
|
|
;;
|
2010-08-10 15:17:51 +00:00
|
|
|
x|"exec")
|
2011-02-06 18:43:37 +00:00
|
|
|
read -r command rest < "$todo"
|
2010-08-10 15:17:51 +00:00
|
|
|
mark_action_done
|
|
|
|
printf 'Executing: %s\n' "$rest"
|
|
|
|
${SHELL:-@SHELL_PATH@} -c "$rest" # Actual execution
|
|
|
|
status=$?
|
2011-08-24 18:54:50 +00: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 15:17:51 +00:00
|
|
|
if test "$status" -ne 0
|
|
|
|
then
|
|
|
|
warn "Execution failed: $rest"
|
2011-08-24 18:54:50 +00:00
|
|
|
test "$dirty" = f ||
|
|
|
|
warn "and made changes to the index and/or the working tree"
|
|
|
|
|
2010-08-10 15:17:51 +00:00
|
|
|
warn "You can fix the problem, and then run"
|
|
|
|
warn
|
|
|
|
warn " git rebase --continue"
|
|
|
|
warn
|
2012-09-18 11:15:26 +00:00
|
|
|
if test $status -eq 127 # command not found
|
|
|
|
then
|
|
|
|
status=1
|
|
|
|
fi
|
2010-08-10 15:17:51 +00:00
|
|
|
exit "$status"
|
2011-08-24 18:54:50 +00:00
|
|
|
elif test "$dirty" = t
|
2010-08-10 15:17:51 +00:00
|
|
|
then
|
2011-08-24 18:54:50 +00:00
|
|
|
warn "Execution succeeded: $rest"
|
|
|
|
warn "but left changes to the index and/or the working tree"
|
2010-08-10 15:17:51 +00:00
|
|
|
warn "Commit or stash your changes, and then run"
|
|
|
|
warn
|
|
|
|
warn " git rebase --continue"
|
|
|
|
warn
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2007-06-25 00:11:14 +00:00
|
|
|
*)
|
|
|
|
warn "Unknown command: $command $sha1 $rest"
|
2012-09-19 06:43:54 +00:00
|
|
|
fixtodo="Please fix this using 'git rebase --edit-todo'."
|
2009-10-27 14:58:14 +00:00
|
|
|
if git rev-parse --verify -q "$sha1" >/dev/null
|
|
|
|
then
|
2012-09-19 06:43:54 +00:00
|
|
|
die_with_patch $sha1 "$fixtodo"
|
2009-10-27 14:58:14 +00:00
|
|
|
else
|
2012-09-19 06:43:54 +00:00
|
|
|
die "$fixtodo"
|
2009-10-27 14:58:14 +00:00
|
|
|
fi
|
2007-09-25 15:42:51 +00:00
|
|
|
;;
|
2007-06-25 00:11:14 +00:00
|
|
|
esac
|
2011-02-06 18:43:37 +00:00
|
|
|
test -s "$todo" && return
|
2007-06-25 00:11:14 +00:00
|
|
|
|
2007-06-25 17:58:28 +00:00
|
|
|
comment_for_reflog finish &&
|
2011-02-06 18:43:37 +00:00
|
|
|
newhead=$(git rev-parse HEAD) &&
|
2011-02-06 18:43:50 +00:00
|
|
|
case $head_name in
|
2007-09-25 15:43:15 +00:00
|
|
|
refs/*)
|
2012-08-10 06:51:19 +00:00
|
|
|
message="$GIT_REFLOG_ACTION: $head_name onto $onto" &&
|
2011-02-06 18:43:50 +00:00
|
|
|
git update-ref -m "$message" $head_name $newhead $orig_head &&
|
2011-05-27 20:16:14 +00:00
|
|
|
git symbolic-ref \
|
|
|
|
-m "$GIT_REFLOG_ACTION: returning to $head_name" \
|
|
|
|
HEAD $head_name
|
2007-09-25 15:43:15 +00:00
|
|
|
;;
|
|
|
|
esac && {
|
2011-02-06 18:43:50 +00:00
|
|
|
test ! -f "$state_dir"/verbose ||
|
2011-02-06 18:43:52 +00:00
|
|
|
git diff-tree --stat $orig_head..HEAD
|
2007-07-08 02:02:13 +00:00
|
|
|
} &&
|
2010-03-12 17:04:33 +00:00
|
|
|
{
|
2011-02-06 18:43:37 +00:00
|
|
|
test -s "$rewritten_list" &&
|
|
|
|
git notes copy --for-rewrite=rebase < "$rewritten_list" ||
|
2010-03-12 17:04:33 +00:00
|
|
|
true # we don't care if this copying failed
|
|
|
|
} &&
|
2010-03-12 17:04:30 +00:00
|
|
|
if test -x "$GIT_DIR"/hooks/post-rewrite &&
|
2011-02-06 18:43:37 +00:00
|
|
|
test -s "$rewritten_list"; then
|
|
|
|
"$GIT_DIR"/hooks/post-rewrite rebase < "$rewritten_list"
|
2010-03-12 17:04:30 +00:00
|
|
|
true # we don't care if this hook failed
|
|
|
|
fi &&
|
2011-02-06 18:43:50 +00:00
|
|
|
warn "Successfully rebased and updated $head_name."
|
2007-06-25 00:11:14 +00:00
|
|
|
|
2013-05-12 11:56:39 +00:00
|
|
|
return 1 # not failure; just to break the do_rest loop
|
2007-06-25 00:11:14 +00:00
|
|
|
}
|
|
|
|
|
2013-05-12 11:56:39 +00:00
|
|
|
# can only return 0, when the infinite loop breaks
|
2007-06-25 00:11:14 +00:00
|
|
|
do_rest () {
|
|
|
|
while :
|
|
|
|
do
|
2013-05-12 11:56:39 +00:00
|
|
|
do_next || break
|
2007-06-25 00:11:14 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2009-03-03 09:55:31 +00: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 20:47:34 +00:00
|
|
|
while read -r command rest
|
2009-03-03 09:55:31 +00: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 20:47:34 +00:00
|
|
|
case "$fd,$command" in
|
|
|
|
3,pick|3,p)
|
2011-02-06 18:43:37 +00:00
|
|
|
# pick a commit whose parent is current $onto -> skip
|
2010-09-17 21:42:51 +00: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 20:47:34 +00:00
|
|
|
case "$(git rev-parse --verify --quiet "$sha1"^)" in
|
2011-02-06 18:43:37 +00: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 20:47:34 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
fd=1
|
|
|
|
;;
|
|
|
|
esac
|
2009-03-03 09:55:31 +00:00
|
|
|
;;
|
2013-08-16 21:44:07 +00:00
|
|
|
3,"$comment_char"*|3,)
|
2009-03-03 09:55:31 +00:00
|
|
|
# copy comments
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
fd=1
|
|
|
|
;;
|
|
|
|
esac
|
2010-08-13 20:47:35 +00:00
|
|
|
printf '%s\n' "$command${rest:+ }$rest" >&$fd
|
2011-02-06 18:43:37 +00:00
|
|
|
done <"$todo" >"$todo.new" 3>>"$done" &&
|
|
|
|
mv -f "$todo".new "$todo" &&
|
2010-03-12 17:04:30 +00:00
|
|
|
case "$(peek_next_command)" in
|
|
|
|
squash|s|fixup|f)
|
2011-02-06 18:43:37 +00:00
|
|
|
record_in_rewritten "$onto"
|
2010-03-12 17:04:30 +00:00
|
|
|
;;
|
|
|
|
esac ||
|
2009-03-03 09:55:31 +00:00
|
|
|
die "Could not skip unnecessary pick commands"
|
|
|
|
}
|
|
|
|
|
2013-08-24 00:10:42 +00: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.
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
sha1=$(git rev-parse --verify --quiet "$@" ${rest%% *}) &&
|
|
|
|
rest="$sha1 ${rest#* }"
|
|
|
|
;;
|
|
|
|
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 15:53:05 +00:00
|
|
|
transform_todo_ids --short
|
2013-08-24 00:10:42 +00:00
|
|
|
}
|
|
|
|
|
2009-12-08 03:13:14 +00: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".
|
|
|
|
rearrange_squash () {
|
2010-11-04 22:36:32 +00:00
|
|
|
# extract fixup!/squash! lines and resolve any referenced sha1's
|
|
|
|
while read -r pick sha1 message
|
|
|
|
do
|
|
|
|
case "$message" in
|
|
|
|
"squash! "*|"fixup! "*)
|
|
|
|
action="${message%%!*}"
|
2013-06-27 19:26:31 +00: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-14 23:56:43 +00:00
|
|
|
printf '%s %s %s %s\n' "$sha1" "$action" "$prefix" "$rest"
|
2010-11-04 22:36:32 +00: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 19:26:31 +00:00
|
|
|
echo "$sha1 +$action $prefix $fullsha"
|
2010-11-04 22:36:32 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
esac
|
|
|
|
done >"$1.sq" <"$1"
|
2009-12-08 03:13:14 +00:00
|
|
|
test -s "$1.sq" || return
|
|
|
|
|
|
|
|
used=
|
2010-07-06 06:08:36 +00:00
|
|
|
while read -r pick sha1 message
|
2009-12-08 03:13:14 +00:00
|
|
|
do
|
|
|
|
case " $used" in
|
|
|
|
*" $sha1 "*) continue ;;
|
|
|
|
esac
|
2010-07-22 19:15:11 +00:00
|
|
|
printf '%s\n' "$pick $sha1 $message"
|
2010-11-04 22:36:31 +00:00
|
|
|
used="$used$sha1 "
|
2013-06-27 19:26:31 +00:00
|
|
|
while read -r squash action msg_prefix msg_content
|
2009-12-08 03:13:14 +00:00
|
|
|
do
|
2010-11-04 22:36:31 +00:00
|
|
|
case " $used" in
|
|
|
|
*" $squash "*) continue ;;
|
|
|
|
esac
|
2010-11-04 22:36:32 +00:00
|
|
|
emit=0
|
|
|
|
case "$action" in
|
|
|
|
+*)
|
|
|
|
action="${action#+}"
|
|
|
|
# full sha1 prefix test
|
2011-02-06 18:43:37 +00:00
|
|
|
case "$msg_content" in "$sha1"*) emit=1;; esac ;;
|
2010-11-04 22:36:32 +00:00
|
|
|
*)
|
|
|
|
# message prefix test
|
2011-02-06 18:43:37 +00:00
|
|
|
case "$message" in "$msg_content"*) emit=1;; esac ;;
|
2010-11-04 22:36:32 +00:00
|
|
|
esac
|
|
|
|
if test $emit = 1; then
|
2013-06-27 19:26:31 +00:00
|
|
|
real_prefix=$(echo "$msg_prefix" | sed "s/,/! /g")
|
|
|
|
printf '%s\n' "$action $squash ${real_prefix}$msg_content"
|
2009-12-08 03:13:14 +00:00
|
|
|
used="$used$squash "
|
2010-11-04 22:36:32 +00:00
|
|
|
fi
|
2009-12-08 03:13:14 +00:00
|
|
|
done <"$1.sq"
|
|
|
|
done >"$1.rearranged" <"$1"
|
|
|
|
cat "$1.rearranged" >"$1"
|
|
|
|
rm -f "$1.sq" "$1.rearranged"
|
|
|
|
}
|
|
|
|
|
2012-06-12 08:05:12 +00: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"
|
|
|
|
}
|
|
|
|
|
2014-04-11 08:28:17 +00: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.
|
|
|
|
#
|
|
|
|
# However, FreeBSD /bin/sh misbehaves on such a construct and
|
|
|
|
# continues to run the statements that follow such a "return".
|
|
|
|
# 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 18:43:39 +00:00
|
|
|
case "$action" in
|
|
|
|
continue)
|
|
|
|
# do we have anything to commit?
|
2012-04-07 10:20:53 +00:00
|
|
|
if git diff-index --cached --quiet HEAD --
|
2011-02-06 18:43:39 +00:00
|
|
|
then
|
2015-06-18 16:38:53 +00: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 18:43:39 +00:00
|
|
|
else
|
2011-08-24 14:01:48 +00:00
|
|
|
if ! test -f "$author_script"
|
|
|
|
then
|
2014-02-10 01:03:37 +00:00
|
|
|
gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
|
2011-08-24 14:01:48 +00: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 01:03:37 +00:00
|
|
|
git commit --amend $gpg_sign_opt_quoted
|
2011-08-24 14:01:48 +00:00
|
|
|
|
|
|
|
If they are meant to go into a new commit, run:
|
|
|
|
|
2014-02-10 01:03:37 +00:00
|
|
|
git commit $gpg_sign_opt_quoted
|
2011-08-24 14:01:48 +00:00
|
|
|
|
|
|
|
In both case, once you're done, continue with:
|
|
|
|
|
|
|
|
git rebase --continue
|
|
|
|
"
|
|
|
|
fi
|
2011-02-06 18:43:39 +00:00
|
|
|
. "$author_script" ||
|
2011-08-24 14:01:48 +00:00
|
|
|
die "Error trying to find the author identity to amend commit"
|
2011-02-06 18:43:39 +00:00
|
|
|
if test -f "$amend"
|
2007-12-20 07:12:12 +00:00
|
|
|
then
|
2011-02-06 18:43:39 +00:00
|
|
|
current_head=$(git rev-parse --verify HEAD)
|
|
|
|
test "$current_head" = $(cat "$amend") ||
|
|
|
|
die "\
|
2008-09-09 12:05:26 +00:00
|
|
|
You have uncommitted changes in your working tree. Please, commit them
|
|
|
|
first and then run 'git rebase --continue' again."
|
2014-02-10 01:03:37 +00:00
|
|
|
do_with_author git commit --amend --no-verify -F "$msg" -e \
|
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2012-07-24 12:17:03 +00:00
|
|
|
die "Could not commit staged changes."
|
|
|
|
else
|
2014-02-10 01:03:37 +00:00
|
|
|
do_with_author git commit --no-verify -F "$msg" -e \
|
|
|
|
${gpg_sign_opt:+"$gpg_sign_opt"} ||
|
2012-07-24 12:17:03 +00:00
|
|
|
die "Could not commit staged changes."
|
2007-12-20 07:12:12 +00:00
|
|
|
fi
|
2011-02-06 18:43:39 +00:00
|
|
|
fi
|
2007-07-08 02:01:29 +00:00
|
|
|
|
2015-05-22 13:15:49 +00:00
|
|
|
if test -r "$state_dir"/stopped-sha
|
|
|
|
then
|
|
|
|
record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
|
|
|
|
fi
|
2010-03-28 19:36:00 +00:00
|
|
|
|
2011-02-06 18:43:39 +00:00
|
|
|
require_clean_work_tree "rebase"
|
|
|
|
do_rest
|
2013-05-12 11:56:39 +00:00
|
|
|
return 0
|
2011-02-06 18:43:39 +00:00
|
|
|
;;
|
|
|
|
skip)
|
|
|
|
git rerere clear
|
|
|
|
|
2011-02-06 18:43:52 +00:00
|
|
|
do_rest
|
2013-05-12 11:56:39 +00:00
|
|
|
return 0
|
2011-02-06 18:43:39 +00:00
|
|
|
;;
|
2012-09-18 01:28:09 +00:00
|
|
|
edit-todo)
|
2013-02-11 23:08:04 +00:00
|
|
|
git stripspace --strip-comments <"$todo" >"$todo".new
|
2012-09-18 01:28:09 +00:00
|
|
|
mv -f "$todo".new "$todo"
|
2013-08-24 00:10:42 +00:00
|
|
|
collapse_todo_ids
|
2012-09-18 01:28:09 +00:00
|
|
|
append_todo_help
|
2013-02-11 23:08:04 +00: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 01:28:09 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
git_sequence_editor "$todo" ||
|
|
|
|
die "Could not execute editor"
|
2013-08-24 00:10:42 +00:00
|
|
|
expand_todo_ids
|
2012-09-18 01:28:09 +00:00
|
|
|
|
|
|
|
exit
|
|
|
|
;;
|
2011-02-06 18:43:39 +00:00
|
|
|
esac
|
2007-06-25 00:11:14 +00:00
|
|
|
|
2011-02-06 18:43:35 +00:00
|
|
|
git var GIT_COMMITTER_IDENT >/dev/null ||
|
|
|
|
die "You need to set your committer info first"
|
2007-06-25 00:11:14 +00:00
|
|
|
|
2011-02-06 18:43:35 +00:00
|
|
|
comment_for_reflog start
|
|
|
|
|
2011-02-06 18:43:42 +00:00
|
|
|
if test ! -z "$switch_to"
|
2011-02-06 18:43:35 +00:00
|
|
|
then
|
2013-06-16 08:45:13 +00:00
|
|
|
GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to"
|
2011-02-06 18:43:42 +00:00
|
|
|
output git checkout "$switch_to" -- ||
|
2013-06-16 08:45:13 +00:00
|
|
|
die "Could not checkout $switch_to"
|
|
|
|
|
|
|
|
comment_for_reflog start
|
2011-02-06 18:43:35 +00:00
|
|
|
fi
|
|
|
|
|
2011-02-06 18:43:50 +00:00
|
|
|
orig_head=$(git rev-parse --verify HEAD) || die "No HEAD?"
|
2013-05-12 11:56:36 +00:00
|
|
|
mkdir -p "$state_dir" || die "Could not create temporary $state_dir"
|
2011-02-06 18:43:35 +00:00
|
|
|
|
2011-02-06 18:43:50 +00:00
|
|
|
: > "$state_dir"/interactive || die "Could not mark as interactive"
|
2011-02-06 18:43:53 +00:00
|
|
|
write_basic_state
|
2011-02-06 18:43:37 +00:00
|
|
|
if test t = "$preserve_merges"
|
2011-02-06 18:43:35 +00:00
|
|
|
then
|
2011-02-06 18:43:37 +00:00
|
|
|
if test -z "$rebase_root"
|
2011-02-06 18:43:35 +00:00
|
|
|
then
|
2011-02-06 18:43:37 +00:00
|
|
|
mkdir "$rewritten" &&
|
2011-02-06 18:43:50 +00:00
|
|
|
for c in $(git merge-base --all $orig_head $upstream)
|
2008-10-15 07:44:38 +00:00
|
|
|
do
|
2011-02-06 18:43:37 +00:00
|
|
|
echo $onto > "$rewritten"/$c ||
|
2011-02-06 18:43:35 +00:00
|
|
|
die "Could not init rewritten commits"
|
2008-10-15 07:44:38 +00:00
|
|
|
done
|
2011-02-06 18:43:35 +00:00
|
|
|
else
|
2011-02-06 18:43:37 +00:00
|
|
|
mkdir "$rewritten" &&
|
|
|
|
echo $onto > "$rewritten"/root ||
|
2011-02-06 18:43:35 +00: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 18:43:37 +00:00
|
|
|
merges_option=
|
2011-02-06 18:43:35 +00:00
|
|
|
else
|
2011-02-06 18:43:37 +00:00
|
|
|
merges_option="--no-merges --cherry-pick"
|
2011-02-06 18:43:35 +00:00
|
|
|
fi
|
|
|
|
|
2011-02-06 18:43:50 +00:00
|
|
|
shorthead=$(git rev-parse --short $orig_head)
|
2011-02-06 18:43:37 +00:00
|
|
|
shortonto=$(git rev-parse --short $onto)
|
|
|
|
if test -z "$rebase_root"
|
|
|
|
# this is now equivalent to ! -z "$upstream"
|
2011-02-06 18:43:35 +00:00
|
|
|
then
|
2011-02-06 18:43:37 +00:00
|
|
|
shortupstream=$(git rev-parse --short $upstream)
|
2011-02-06 18:43:50 +00:00
|
|
|
revisions=$upstream...$orig_head
|
2011-02-06 18:43:37 +00:00
|
|
|
shortrevisions=$shortupstream..$shorthead
|
2011-02-06 18:43:35 +00:00
|
|
|
else
|
2011-02-06 18:43:50 +00:00
|
|
|
revisions=$onto...$orig_head
|
2011-02-06 18:43:37 +00:00
|
|
|
shortrevisions=$shorthead
|
2011-02-06 18:43:35 +00:00
|
|
|
fi
|
2015-01-22 11:50:15 +00:00
|
|
|
git rev-list $merges_option --pretty=oneline --reverse --left-right --topo-order \
|
2014-07-16 19:23:49 +00:00
|
|
|
$revisions ${restrict_revision+^$restrict_revision} | \
|
2011-02-06 18:43:35 +00:00
|
|
|
sed -n "s/^>//p" |
|
2015-01-22 11:50:15 +00:00
|
|
|
while read -r sha1 rest
|
2011-02-06 18:43:35 +00:00
|
|
|
do
|
2012-04-20 14:36:17 +00:00
|
|
|
|
2015-01-22 11:50:15 +00:00
|
|
|
if test -z "$keep_empty" && is_empty_commit $sha1 && ! is_merge_commit $sha1
|
2012-04-20 14:36:17 +00:00
|
|
|
then
|
2013-02-11 23:08:04 +00:00
|
|
|
comment_out="$comment_char "
|
2012-04-20 14:36:17 +00:00
|
|
|
else
|
|
|
|
comment_out=
|
|
|
|
fi
|
|
|
|
|
2011-02-06 18:43:37 +00:00
|
|
|
if test t != "$preserve_merges"
|
2011-02-06 18:43:35 +00:00
|
|
|
then
|
2015-01-22 11:50:15 +00:00
|
|
|
printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo"
|
2011-02-06 18:43:35 +00:00
|
|
|
else
|
2011-02-06 18:43:37 +00:00
|
|
|
if test -z "$rebase_root"
|
2008-10-15 07:44:38 +00:00
|
|
|
then
|
2011-02-06 18:43:35 +00:00
|
|
|
preserve=t
|
|
|
|
for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
|
2008-10-15 07:44:38 +00: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-18 22:12:01 +00:00
|
|
|
if test -f "$rewritten"/$p
|
2008-10-15 07:44:38 +00:00
|
|
|
then
|
2011-02-06 18:43:35 +00:00
|
|
|
preserve=f
|
2008-10-15 07:44:38 +00:00
|
|
|
fi
|
|
|
|
done
|
2011-02-06 18:43:35 +00:00
|
|
|
else
|
|
|
|
preserve=f
|
|
|
|
fi
|
|
|
|
if test f = "$preserve"
|
|
|
|
then
|
2011-02-06 18:43:37 +00:00
|
|
|
touch "$rewritten"/$sha1
|
2015-01-22 11:50:15 +00:00
|
|
|
printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo"
|
2008-10-15 07:44:38 +00:00
|
|
|
fi
|
2011-02-06 18:43:35 +00:00
|
|
|
fi
|
|
|
|
done
|
2009-01-02 22:28:28 +00:00
|
|
|
|
2011-02-06 18:43:35 +00:00
|
|
|
# Watch for commits that been dropped by --cherry-pick
|
2011-02-06 18:43:37 +00:00
|
|
|
if test t = "$preserve_merges"
|
2011-02-06 18:43:35 +00:00
|
|
|
then
|
2011-02-06 18:43:37 +00:00
|
|
|
mkdir "$dropped"
|
2011-02-06 18:43:35 +00:00
|
|
|
# Save all non-cherry-picked changes
|
2011-02-06 18:43:37 +00:00
|
|
|
git rev-list $revisions --left-right --cherry-pick | \
|
2011-02-06 18:43:50 +00:00
|
|
|
sed -n "s/^>//p" > "$state_dir"/not-cherry-picks
|
2011-02-06 18:43:35 +00:00
|
|
|
# Now all commits and note which ones are missing in
|
|
|
|
# not-cherry-picks and hence being dropped
|
2011-02-06 18:43:37 +00:00
|
|
|
git rev-list $revisions |
|
2011-02-06 18:43:35 +00:00
|
|
|
while read rev
|
|
|
|
do
|
2014-06-06 14:55:52 +00:00
|
|
|
if test -f "$rewritten"/$rev && test "$(sane_grep "$rev" "$state_dir"/not-cherry-picks)" = ""
|
2011-02-06 18:43:35 +00: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 18:43:37 +00:00
|
|
|
git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$dropped"/$rev
|
2015-01-22 11:50:15 +00: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 18:43:37 +00:00
|
|
|
rm "$rewritten"/$rev
|
2011-02-06 18:43:35 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2011-02-06 18:43:37 +00:00
|
|
|
test -s "$todo" || echo noop >> "$todo"
|
|
|
|
test -n "$autosquash" && rearrange_squash "$todo"
|
2012-06-12 08:05:12 +00:00
|
|
|
test -n "$cmd" && add_exec_commands "$todo"
|
|
|
|
|
2014-12-10 18:16:44 +00:00
|
|
|
todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
|
2015-03-04 07:53:04 +00:00
|
|
|
todocount=${todocount##* }
|
2014-12-10 18:16:44 +00:00
|
|
|
|
2013-02-11 23:08:04 +00:00
|
|
|
cat >>"$todo" <<EOF
|
2007-11-22 12:30:10 +00:00
|
|
|
|
2015-03-04 07:53:05 +00:00
|
|
|
$comment_char Rebase $shortrevisions onto $shortonto ($todocount command(s))
|
2012-09-18 01:28:08 +00:00
|
|
|
EOF
|
|
|
|
append_todo_help
|
2013-02-11 23:08:04 +00:00
|
|
|
git stripspace --comment-lines >>"$todo" <<\EOF
|
|
|
|
|
|
|
|
However, if you remove everything, the rebase will be aborted.
|
|
|
|
|
2007-06-25 00:11:14 +00:00
|
|
|
EOF
|
|
|
|
|
2012-04-20 14:36:17 +00:00
|
|
|
if test -z "$keep_empty"
|
|
|
|
then
|
2013-02-11 23:08:04 +00:00
|
|
|
printf '%s\n' "$comment_char Note that empty commits are commented out" >>"$todo"
|
2012-04-20 14:36:17 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2011-02-06 18:43:37 +00:00
|
|
|
has_action "$todo" ||
|
2014-05-19 22:05:20 +00:00
|
|
|
return 2
|
2007-06-25 00:11:14 +00:00
|
|
|
|
2011-02-06 18:43:37 +00:00
|
|
|
cp "$todo" "$todo".backup
|
2015-01-22 11:50:15 +00:00
|
|
|
collapse_todo_ids
|
2011-10-17 20:26:23 +00:00
|
|
|
git_sequence_editor "$todo" ||
|
2011-02-06 18:43:35 +00:00
|
|
|
die_abort "Could not execute editor"
|
2007-06-25 00:11:14 +00:00
|
|
|
|
2011-02-06 18:43:37 +00:00
|
|
|
has_action "$todo" ||
|
2014-05-19 22:05:20 +00:00
|
|
|
return 2
|
2007-06-25 17:56:55 +00:00
|
|
|
|
2013-08-24 00:10:42 +00:00
|
|
|
expand_todo_ids
|
|
|
|
|
2011-02-06 18:43:37 +00:00
|
|
|
test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks
|
2009-03-03 09:55:31 +00:00
|
|
|
|
2013-06-16 08:45:13 +00:00
|
|
|
GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name"
|
2011-02-06 18:43:37 +00:00
|
|
|
output git checkout $onto || die_abort "could not detach HEAD"
|
2011-02-06 18:43:50 +00:00
|
|
|
git update-ref ORIG_HEAD $orig_head
|
2011-02-06 18:43:35 +00:00
|
|
|
do_rest
|
2014-04-11 08:28:17 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
# ... and then we call the whole thing.
|
|
|
|
git_rebase__interactive
|