2007-06-25 02:11:14 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2006 Johannes E. Schindelin
|
|
|
|
|
|
|
|
# SHORT DESCRIPTION
|
|
|
|
#
|
|
|
|
# This script makes it easy to fix up commits in the middle of a series,
|
|
|
|
# and rearrange commits.
|
|
|
|
#
|
|
|
|
# The original idea comes from Eric W. Biederman, in
|
|
|
|
# http://article.gmane.org/gmane.comp.version-control.git/22407
|
|
|
|
|
|
|
|
. git-sh-setup
|
|
|
|
|
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
|
|
|
|
|
|
|
# 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
|
|
|
|
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
|
|
|
|
|
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"
|
|
|
|
new_count=$(sane_grep -c '^[^#]' < "$done")
|
|
|
|
total=$(($new_count+$(sane_grep -c '^[^#]' < "$todo")))
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
2007-11-22 12:18:10 +01:00
|
|
|
git rerere
|
2007-06-25 02:11:14 +02:00
|
|
|
die "$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 () {
|
2009-11-24 00:56:32 +01:00
|
|
|
sane_grep '^[^#]' "$1" >/dev/null
|
2007-09-25 17:42:51 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-06-25 02:11:14 +02:00
|
|
|
pick_one () {
|
2010-03-06 21:34:46 +01:00
|
|
|
ff=--ff
|
|
|
|
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"
|
2011-02-06 19:43:37 +01:00
|
|
|
test -d "$rewritten" &&
|
2007-06-25 19:59:43 +02:00
|
|
|
pick_one_preserving_merges "$@" && return
|
2010-03-06 21:34:46 +01:00
|
|
|
output git cherry-pick $ff "$@"
|
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}
|
2010-01-14 06:54:53 +01:00
|
|
|
if ! do_with_author output \
|
2011-05-06 19:50:00 +02:00
|
|
|
git merge --no-ff ${strategy:+-s $strategy} -m \
|
2011-02-06 19:43:38 +01:00
|
|
|
"$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
|
|
|
;;
|
|
|
|
*)
|
2007-10-31 03:20:31 +01:00
|
|
|
output git cherry-pick "$@" ||
|
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 \
|
2010-01-14 06:54:50 +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
|
|
|
{
|
2011-02-06 19:43:37 +01:00
|
|
|
echo "# 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
|
|
|
{
|
|
|
|
echo "# This is a combination of 2 commits."
|
|
|
|
echo "# The first commit's message is:"
|
|
|
|
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
|
2011-02-06 19:43:37 +01:00
|
|
|
echo "# 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
|
2011-02-06 19:43:37 +01:00
|
|
|
echo "# The $(nth_string $count) commit message will be skipped:"
|
2009-12-07 10:20:59 +01:00
|
|
|
echo
|
2010-01-14 06:54:51 +01:00
|
|
|
commit_message $2 | 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 () {
|
2011-02-06 19:43:37 +01:00
|
|
|
sed -n -e "/^#/d" -e '/^$/d' -e "s/ .*//p" -e "q" < "$todo"
|
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
|
|
|
|
}
|
|
|
|
|
2007-06-25 02:11:14 +02:00
|
|
|
do_next () {
|
2011-02-06 19:43:37 +01:00
|
|
|
rm -f "$msg" "$author_script" "$amend" || exit
|
|
|
|
read -r command sha1 rest < "$todo"
|
2007-06-25 02:11:14 +02:00
|
|
|
case "$command" in
|
2008-10-10 13:42:12 +02:00
|
|
|
'#'*|''|noop)
|
2007-06-25 02:11:14 +02:00
|
|
|
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
|
|
|
|
pick_one $sha1 ||
|
|
|
|
die_with_patch $sha1 "Could not apply $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
|
|
|
|
pick_one $sha1 ||
|
|
|
|
die_with_patch $sha1 "Could not apply $sha1... $rest"
|
2010-03-12 18:04:28 +01:00
|
|
|
git commit --amend --no-post-rewrite
|
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
|
|
|
|
pick_one $sha1 ||
|
|
|
|
die_with_patch $sha1 "Could not apply $sha1... $rest"
|
2011-02-06 19:43:50 +01:00
|
|
|
echo "$sha1" > "$state_dir"/stopped-sha
|
2007-06-25 02:11:14 +02:00
|
|
|
make_patch $sha1
|
2011-02-06 19:43:37 +01:00
|
|
|
git rev-parse --verify HEAD > "$amend"
|
2008-07-23 09:46:35 +02:00
|
|
|
warn "Stopped at $sha1... $rest"
|
2007-06-25 02:11:14 +02:00
|
|
|
warn "You can amend the commit now, with"
|
|
|
|
warn
|
|
|
|
warn " git commit --amend"
|
|
|
|
warn
|
2008-02-27 13:50:22 +01:00
|
|
|
warn "Once you are satisfied with your changes, run"
|
|
|
|
warn
|
|
|
|
warn " git rebase --continue"
|
|
|
|
warn
|
2007-06-25 02:11:14 +02:00
|
|
|
exit 0
|
|
|
|
;;
|
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"
|
2008-10-03 02:08:21 +02:00
|
|
|
output git reset --soft HEAD^
|
2010-01-14 06:54:57 +01:00
|
|
|
pick_one -n $sha1 || die_failed_squash $sha1 "$rest"
|
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:
|
2011-02-06 19:43:37 +01:00
|
|
|
do_with_author output git commit --no-verify -F "$squash_msg" ||
|
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
|
2011-02-06 19:43:37 +01:00
|
|
|
do_with_author git commit --no-verify -F "$fixup_msg" ||
|
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
|
|
|
|
do_with_author git commit --no-verify -e ||
|
|
|
|
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"
|
|
|
|
# "exec" command doesn't take a sha1 in the todo-list.
|
|
|
|
# => can't just use $sha1 here.
|
2011-02-06 19:43:50 +01:00
|
|
|
git rev-parse --verify HEAD > "$state_dir"/stopped-sha
|
2010-08-10 17:17:51 +02:00
|
|
|
${SHELL:-@SHELL_PATH@} -c "$rest" # Actual execution
|
|
|
|
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
|
|
|
|
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"
|
2009-10-27 15:58:14 +01:00
|
|
|
if git rev-parse --verify -q "$sha1" >/dev/null
|
|
|
|
then
|
2011-02-06 19:43:37 +01:00
|
|
|
die_with_patch $sha1 "Please fix this in the file $todo."
|
2009-10-27 15:58:14 +01:00
|
|
|
else
|
2011-02-06 19:43:37 +01:00
|
|
|
die "Please fix this in the file $todo."
|
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:52 +01:00
|
|
|
shortonto=$(git rev-parse --short $onto) &&
|
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/*)
|
2011-02-06 19:43:50 +01:00
|
|
|
message="$GIT_REFLOG_ACTION: $head_name onto $shortonto" &&
|
|
|
|
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
|
|
|
|
} &&
|
2010-03-12 18:04:30 +01:00
|
|
|
if test -x "$GIT_DIR"/hooks/post-rewrite &&
|
2011-02-06 19:43:37 +01:00
|
|
|
test -s "$rewritten_list"; then
|
|
|
|
"$GIT_DIR"/hooks/post-rewrite 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
|
|
|
rm -rf "$state_dir" &&
|
2007-09-25 17:43:15 +02:00
|
|
|
git gc --auto &&
|
2011-02-06 19:43:50 +01:00
|
|
|
warn "Successfully rebased and updated $head_name."
|
2007-06-25 02:11:14 +02:00
|
|
|
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
do_rest () {
|
|
|
|
while :
|
|
|
|
do
|
|
|
|
do_next
|
|
|
|
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
|
|
|
;;
|
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
|
|
|
3,#*|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"
|
|
|
|
}
|
|
|
|
|
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".
|
|
|
|
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
|
|
|
|
case "$message" in
|
|
|
|
"squash! "*|"fixup! "*)
|
|
|
|
action="${message%%!*}"
|
|
|
|
rest="${message#*! }"
|
|
|
|
echo "$sha1 $action $rest"
|
|
|
|
# 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
|
|
|
|
echo "$sha1 +$action $fullsha"
|
|
|
|
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"
|
2010-11-04 23:36:31 +01:00
|
|
|
used="$used$sha1 "
|
2011-02-06 19:43:37 +01:00
|
|
|
while read -r squash action 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
|
2011-02-06 19:43:37 +01:00
|
|
|
printf '%s\n' "$action $squash $action! $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"
|
|
|
|
}
|
|
|
|
|
2011-02-06 19:43:39 +01:00
|
|
|
case "$action" in
|
|
|
|
continue)
|
|
|
|
# do we have anything to commit?
|
|
|
|
if git diff-index --cached --quiet --ignore-submodules HEAD --
|
|
|
|
then
|
|
|
|
: Nothing to commit -- skip this
|
|
|
|
else
|
2011-08-24 16:01:48 +02:00
|
|
|
if ! test -f "$author_script"
|
|
|
|
then
|
|
|
|
die "You have staged changes in your working tree. If these changes are meant to be
|
|
|
|
squashed into the previous commit, run:
|
|
|
|
|
|
|
|
git commit --amend
|
|
|
|
|
|
|
|
If they are meant to go into a new commit, run:
|
|
|
|
|
|
|
|
git commit
|
|
|
|
|
|
|
|
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
|
|
|
current_head=
|
|
|
|
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."
|
2011-02-06 19:43:39 +01:00
|
|
|
git reset --soft HEAD^ ||
|
|
|
|
die "Cannot rewind the HEAD"
|
2007-12-20 08:12:12 +01:00
|
|
|
fi
|
2011-02-06 19:43:39 +01:00
|
|
|
do_with_author git commit --no-verify -F "$msg" -e || {
|
|
|
|
test -n "$current_head" && git reset --soft $current_head
|
|
|
|
die "Could not commit staged changes."
|
|
|
|
}
|
|
|
|
fi
|
2007-07-08 04:01:29 +02:00
|
|
|
|
2011-02-06 19:43:50 +01:00
|
|
|
record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
|
2010-03-28 21:36:00 +02:00
|
|
|
|
2011-02-06 19:43:39 +01:00
|
|
|
require_clean_work_tree "rebase"
|
|
|
|
do_rest
|
|
|
|
;;
|
|
|
|
skip)
|
|
|
|
git rerere clear
|
|
|
|
|
2011-02-06 19:43:52 +01:00
|
|
|
do_rest
|
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
|
2011-02-06 19:43:42 +01:00
|
|
|
output git checkout "$switch_to" -- ||
|
|
|
|
die "Could not checkout $switch_to"
|
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?"
|
|
|
|
mkdir "$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
|
2011-02-06 19:43:37 +01:00
|
|
|
git rev-list $merges_option --pretty=oneline --abbrev-commit \
|
2011-02-06 19:43:35 +01:00
|
|
|
--abbrev=7 --reverse --left-right --topo-order \
|
2011-02-06 19:43:37 +01:00
|
|
|
$revisions | \
|
2011-02-06 19:43:35 +01:00
|
|
|
sed -n "s/^>//p" |
|
|
|
|
while read -r shortsha1 rest
|
|
|
|
do
|
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
|
|
|
printf '%s\n' "pick $shortsha1 $rest" >> "$todo"
|
2011-02-06 19:43:35 +01:00
|
|
|
else
|
|
|
|
sha1=$(git rev-parse $shortsha1)
|
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
|
|
|
|
printf '%s\n' "pick $shortsha1 $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
|
2011-02-06 19:43:50 +01:00
|
|
|
if test -f "$rewritten"/$rev -a "$(sane_grep "$rev" "$state_dir"/not-cherry-picks)" = ""
|
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
|
2011-02-06 19:43:35 +01:00
|
|
|
short=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev)
|
2011-02-06 19:43:37 +01:00
|
|
|
sane_grep -v "^[a-z][a-z]* $short" <"$todo" > "${todo}2" ; mv "${todo}2" "$todo"
|
|
|
|
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"
|
|
|
|
cat >> "$todo" << EOF
|
2007-11-22 13:30:10 +01:00
|
|
|
|
2011-02-06 19:43:37 +01:00
|
|
|
# Rebase $shortrevisions onto $shortonto
|
2007-06-25 02:11:14 +02:00
|
|
|
#
|
|
|
|
# Commands:
|
2008-06-07 18:20:19 +02:00
|
|
|
# p, pick = use commit
|
2009-10-07 08:13:23 +02:00
|
|
|
# r, reword = use commit, but edit the commit message
|
2008-06-07 18:20:19 +02:00
|
|
|
# e, edit = use commit, but stop for amending
|
|
|
|
# s, squash = use commit, but meld into previous commit
|
2009-12-07 10:20:59 +01:00
|
|
|
# f, fixup = like "squash", but discard this commit's log message
|
rebase -i: clarify in-editor documentation of "exec"
The hints in the current "instruction sheet" template look like so:
# Rebase 3f14246..a1d7e01 onto 3f14246
#
# 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 <cmd>, exec <cmd> = Run a shell command <cmd>, and stop if it fails
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
This does not make it clear that the format of each line is
<insn> <commit id> <explanatory text that will be printed>
but the reader will probably infer that from the automatically
generated pick examples above it.
What about the "exec" instruction? By analogy, I might imagine that
the format of that line is "exec <command> <explanatory text>", and
the "x <cmd>" hint does not address that question (at first I read it
as taking an argument <cmd> that is the name of a shell). Meanwhile,
the mention of <cmd> makes the hints harder to scan as a table.
So remove the <cmd> and add some words to remind the reader that
"exec" runs a command named by the rest of the line. To make room, it
is left to the manpage to explain that that command is run using
$SHELL and that nonzero status from that command will pause the
rebase.
Wording from Junio.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-01-21 01:36:24 +01:00
|
|
|
# x, exec = run command (the rest of the line) using shell
|
2007-07-08 22:32:22 +02:00
|
|
|
#
|
|
|
|
# If you remove a line here THAT COMMIT WILL BE LOST.
|
2007-11-22 13:30:10 +01:00
|
|
|
# However, if you remove everything, the rebase will be aborted.
|
2007-07-08 22:32:22 +02:00
|
|
|
#
|
2007-06-25 02:11:14 +02:00
|
|
|
EOF
|
|
|
|
|
2011-02-06 19:43:37 +01:00
|
|
|
has_action "$todo" ||
|
2011-02-06 19:43:35 +01:00
|
|
|
die_abort "Nothing to do"
|
2007-06-25 02:11:14 +02:00
|
|
|
|
2011-02-06 19:43:37 +01:00
|
|
|
cp "$todo" "$todo".backup
|
|
|
|
git_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" ||
|
2011-02-06 19:43:35 +01:00
|
|
|
die_abort "Nothing to do"
|
2007-06-25 19:56:55 +02:00
|
|
|
|
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
|
|
|
|
2011-02-06 19:43:37 +01:00
|
|
|
output git checkout $onto || die_abort "could not detach HEAD"
|
2011-02-06 19:43:50 +01:00
|
|
|
git update-ref ORIG_HEAD $orig_head
|
2011-02-06 19:43:35 +01:00
|
|
|
do_rest
|