2007-06-25 00:11:14 +00: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
|
|
|
|
|
2011-02-06 18:43:37 +00:00
|
|
|
dotest="$GIT_DIR/rebase-merge"
|
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.
|
|
|
|
todo="$dotest"/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:37 +00:00
|
|
|
done="$dotest"/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:37 +00:00
|
|
|
msg="$dotest"/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:37 +00:00
|
|
|
squash_msg="$dotest"/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:37 +00:00
|
|
|
fixup_msg="$dotest"/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:37 +00:00
|
|
|
rewritten="$dotest"/rewritten
|
2010-01-14 05:54:45 +00:00
|
|
|
|
2011-02-06 18:43:37 +00:00
|
|
|
dropped="$dotest"/dropped
|
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:37 +00:00
|
|
|
author_script="$dotest"/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:37 +00:00
|
|
|
amend="$dotest"/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:37 +00:00
|
|
|
rewritten_list="$dotest"/rewritten-list
|
|
|
|
rewritten_pending="$dotest"/rewritten-pending
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-07-23 22:45:49 +00:00
|
|
|
output () {
|
2011-02-06 18:43:37 +00:00
|
|
|
case "$verbose" in
|
2007-07-23 22:45:49 +00:00
|
|
|
'')
|
2007-09-26 01:30:13 +00:00
|
|
|
output=$("$@" 2>&1 )
|
2007-07-23 22:45:49 +00:00
|
|
|
status=$?
|
2007-09-26 01:30:13 +00:00
|
|
|
test $status != 0 && printf "%s\n" "$output"
|
2007-07-23 22:45:49 +00:00
|
|
|
return $status
|
2007-09-25 15:42:51 +00:00
|
|
|
;;
|
2007-07-23 22:45:49 +00:00
|
|
|
*)
|
|
|
|
"$@"
|
2007-09-25 15:42:51 +00:00
|
|
|
;;
|
2007-07-23 22:45:49 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
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"
|
|
|
|
new_count=$(sane_grep -c '^[^#]' < "$done")
|
|
|
|
total=$(($new_count+$(sane_grep -c '^[^#]' < "$todo")))
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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:37 +00:00
|
|
|
esac > "$dotest"/patch
|
|
|
|
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:37 +00:00
|
|
|
echo "$1" > "$dotest"/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"
|
|
|
|
}
|
|
|
|
|
2007-06-25 17:56:55 +00:00
|
|
|
die_abort () {
|
2011-02-06 18:43:37 +00:00
|
|
|
rm -rf "$dotest"
|
2007-06-25 17:56:55 +00:00
|
|
|
die "$1"
|
|
|
|
}
|
|
|
|
|
2007-09-25 15:42:51 +00:00
|
|
|
has_action () {
|
2009-11-23 23:56:32 +00:00
|
|
|
sane_grep '^[^#]' "$1" >/dev/null
|
2007-09-25 15:42:51 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-06-25 00:11:14 +00:00
|
|
|
pick_one () {
|
2010-03-06 20:34:46 +00:00
|
|
|
ff=--ff
|
|
|
|
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"
|
2011-02-06 18:43:37 +00:00
|
|
|
test -d "$rewritten" &&
|
2007-06-25 17:59:43 +00:00
|
|
|
pick_one_preserving_merges "$@" && return
|
2011-02-06 18:43:37 +00:00
|
|
|
if test -n "$rebase_root"
|
2009-01-02 22:28:28 +00:00
|
|
|
then
|
|
|
|
output git cherry-pick "$@"
|
|
|
|
return
|
|
|
|
fi
|
2010-03-06 20:34:46 +00:00
|
|
|
output git cherry-pick $ff "$@"
|
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:37 +00:00
|
|
|
if test -f "$dotest"/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
|
|
|
|
done <"$dotest"/current-commit
|
|
|
|
rm "$dotest"/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:37 +00:00
|
|
|
echo $sha1 >> "$dotest"/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}
|
2010-01-14 05:54:53 +00:00
|
|
|
if ! do_with_author output \
|
2011-02-06 18:43:38 +00:00
|
|
|
git merge ${strategy:+-s $strategy} -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
|
|
|
;;
|
|
|
|
*)
|
2007-10-31 02:20:31 +00:00
|
|
|
output git cherry-pick "$@" ||
|
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 \
|
2010-01-14 05:54:50 +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
|
|
|
{
|
2011-02-06 18:43:37 +00:00
|
|
|
echo "# 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
|
|
|
{
|
|
|
|
echo "# This is a combination of 2 commits."
|
|
|
|
echo "# The first commit's message is:"
|
|
|
|
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
|
2011-02-06 18:43:37 +00:00
|
|
|
echo "# 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
|
2011-02-06 18:43:37 +00:00
|
|
|
echo "# The $(nth_string $count) commit message will be skipped:"
|
2009-12-07 09:20:59 +00:00
|
|
|
echo
|
2010-01-14 05:54:51 +00:00
|
|
|
commit_message $2 | 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 () {
|
2011-02-06 18:43:37 +00:00
|
|
|
sed -n -e "/^#/d" -e '/^$/d' -e "s/ .*//p" -e "q" < "$todo"
|
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
|
|
|
|
}
|
|
|
|
|
2007-06-25 00:11:14 +00:00
|
|
|
do_next () {
|
2011-02-06 18:43:37 +00:00
|
|
|
rm -f "$msg" "$author_script" "$amend" || exit
|
|
|
|
read -r command sha1 rest < "$todo"
|
2007-06-25 00:11:14 +00:00
|
|
|
case "$command" in
|
2008-10-10 11:42:12 +00:00
|
|
|
'#'*|''|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
|
|
|
|
pick_one $sha1 ||
|
|
|
|
die_with_patch $sha1 "Could not apply $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
|
|
|
|
pick_one $sha1 ||
|
|
|
|
die_with_patch $sha1 "Could not apply $sha1... $rest"
|
2010-03-12 17:04:28 +00:00
|
|
|
git commit --amend --no-post-rewrite
|
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
|
|
|
|
pick_one $sha1 ||
|
|
|
|
die_with_patch $sha1 "Could not apply $sha1... $rest"
|
2011-02-06 18:43:37 +00:00
|
|
|
echo "$sha1" > "$dotest"/stopped-sha
|
2007-06-25 00:11:14 +00:00
|
|
|
make_patch $sha1
|
2011-02-06 18:43:37 +00:00
|
|
|
git rev-parse --verify HEAD > "$amend"
|
2008-07-23 07:46:35 +00:00
|
|
|
warn "Stopped at $sha1... $rest"
|
2007-06-25 00:11:14 +00:00
|
|
|
warn "You can amend the commit now, with"
|
|
|
|
warn
|
|
|
|
warn " git commit --amend"
|
|
|
|
warn
|
2008-02-27 12:50:22 +00:00
|
|
|
warn "Once you are satisfied with your changes, run"
|
|
|
|
warn
|
|
|
|
warn " git rebase --continue"
|
|
|
|
warn
|
2007-06-25 00:11:14 +00:00
|
|
|
exit 0
|
|
|
|
;;
|
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"
|
2008-10-03 00:08:21 +00:00
|
|
|
output git reset --soft HEAD^
|
2010-01-14 05:54:57 +00:00
|
|
|
pick_one -n $sha1 || die_failed_squash $sha1 "$rest"
|
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:
|
2011-02-06 18:43:37 +00:00
|
|
|
do_with_author output git commit --no-verify -F "$squash_msg" ||
|
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
|
2011-02-06 18:43:37 +00:00
|
|
|
do_with_author git commit --no-verify -F "$fixup_msg" ||
|
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
|
|
|
|
do_with_author git commit --no-verify -e ||
|
|
|
|
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"
|
|
|
|
# "exec" command doesn't take a sha1 in the todo-list.
|
|
|
|
# => can't just use $sha1 here.
|
2011-02-06 18:43:37 +00:00
|
|
|
git rev-parse --verify HEAD > "$dotest"/stopped-sha
|
2010-08-10 15:17:51 +00:00
|
|
|
${SHELL:-@SHELL_PATH@} -c "$rest" # Actual execution
|
|
|
|
status=$?
|
|
|
|
if test "$status" -ne 0
|
|
|
|
then
|
|
|
|
warn "Execution failed: $rest"
|
|
|
|
warn "You can fix the problem, and then run"
|
|
|
|
warn
|
|
|
|
warn " git rebase --continue"
|
|
|
|
warn
|
|
|
|
exit "$status"
|
|
|
|
fi
|
|
|
|
# Run in subshell because require_clean_work_tree can die.
|
2010-10-19 14:39:28 +00:00
|
|
|
if ! (require_clean_work_tree "rebase")
|
2010-08-10 15:17:51 +00:00
|
|
|
then
|
|
|
|
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"
|
2009-10-27 14:58:14 +00:00
|
|
|
if git rev-parse --verify -q "$sha1" >/dev/null
|
|
|
|
then
|
2011-02-06 18:43:37 +00:00
|
|
|
die_with_patch $sha1 "Please fix this in the file $todo."
|
2009-10-27 14:58:14 +00:00
|
|
|
else
|
2011-02-06 18:43:37 +00:00
|
|
|
die "Please fix this in the file $todo."
|
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
|
|
|
headname=$(cat "$dotest"/head-name) &&
|
|
|
|
oldhead=$(cat "$dotest"/head) &&
|
|
|
|
shortonto=$(git rev-parse --short $(cat "$dotest"/onto)) &&
|
|
|
|
newhead=$(git rev-parse HEAD) &&
|
|
|
|
case $headname in
|
2007-09-25 15:43:15 +00:00
|
|
|
refs/*)
|
2011-02-06 18:43:37 +00:00
|
|
|
message="$GIT_REFLOG_ACTION: $headname onto $shortonto" &&
|
|
|
|
git update-ref -m "$message" $headname $newhead $oldhead &&
|
|
|
|
git symbolic-ref HEAD $headname
|
2007-09-25 15:43:15 +00:00
|
|
|
;;
|
|
|
|
esac && {
|
2011-02-06 18:43:37 +00:00
|
|
|
test ! -f "$dotest"/verbose ||
|
|
|
|
git diff-tree --stat $(cat "$dotest"/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:37 +00:00
|
|
|
rm -rf "$dotest" &&
|
2007-09-25 15:43:15 +00:00
|
|
|
git gc --auto &&
|
2011-02-06 18:43:37 +00:00
|
|
|
warn "Successfully rebased and updated $headname."
|
2007-06-25 00:11:14 +00:00
|
|
|
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
do_rest () {
|
|
|
|
while :
|
|
|
|
do
|
|
|
|
do_next
|
|
|
|
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
|
|
|
;;
|
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
|
|
|
3,#*|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"
|
|
|
|
}
|
|
|
|
|
2008-07-12 15:48:20 +00:00
|
|
|
get_saved_options () {
|
2011-02-06 18:43:37 +00:00
|
|
|
test -d "$rewritten" && preserve_merges=t
|
|
|
|
test -f "$dotest"/strategy && strategy="$(cat "$dotest"/strategy)"
|
|
|
|
test -f "$dotest"/verbose && verbose=t
|
|
|
|
test -f "$dotest"/rebase-root && rebase_root=t
|
2008-07-12 15:48:20 +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%%!*}"
|
|
|
|
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 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 "
|
2011-02-06 18:43:37 +00:00
|
|
|
while read -r squash action 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
|
2011-02-06 18:43:37 +00:00
|
|
|
printf '%s\n' "$action $squash $action! $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"
|
|
|
|
}
|
|
|
|
|
2011-02-06 18:43:39 +00:00
|
|
|
case "$action" in
|
|
|
|
continue)
|
|
|
|
get_saved_options
|
|
|
|
comment_for_reflog continue
|
|
|
|
|
|
|
|
# Sanity check
|
|
|
|
git rev-parse --verify HEAD >/dev/null ||
|
|
|
|
die "Cannot read HEAD"
|
|
|
|
git update-index --ignore-submodules --refresh &&
|
|
|
|
git diff-files --quiet --ignore-submodules ||
|
|
|
|
die "Working tree is dirty"
|
|
|
|
|
|
|
|
# do we have anything to commit?
|
|
|
|
if git diff-index --cached --quiet --ignore-submodules HEAD --
|
|
|
|
then
|
|
|
|
: Nothing to commit -- skip this
|
|
|
|
else
|
|
|
|
. "$author_script" ||
|
|
|
|
die "Cannot find the author identity"
|
|
|
|
current_head=
|
|
|
|
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."
|
2011-02-06 18:43:39 +00:00
|
|
|
git reset --soft HEAD^ ||
|
|
|
|
die "Cannot rewind the HEAD"
|
2007-12-20 07:12:12 +00:00
|
|
|
fi
|
2011-02-06 18:43:39 +00: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 02:01:29 +00:00
|
|
|
|
2011-02-06 18:43:39 +00:00
|
|
|
record_in_rewritten "$(cat "$dotest"/stopped-sha)"
|
2010-03-28 19:36:00 +00:00
|
|
|
|
2011-02-06 18:43:39 +00:00
|
|
|
require_clean_work_tree "rebase"
|
|
|
|
do_rest
|
|
|
|
;;
|
|
|
|
abort)
|
|
|
|
get_saved_options
|
|
|
|
comment_for_reflog abort
|
2007-06-25 00:11:14 +00:00
|
|
|
|
2011-02-06 18:43:39 +00:00
|
|
|
git rerere clear
|
2007-06-25 00:11:14 +00:00
|
|
|
|
2011-02-06 18:43:39 +00:00
|
|
|
headname=$(cat "$dotest"/head-name)
|
|
|
|
head=$(cat "$dotest"/head)
|
|
|
|
case $headname in
|
|
|
|
refs/*)
|
|
|
|
git symbolic-ref HEAD $headname
|
2011-02-06 18:43:35 +00:00
|
|
|
;;
|
2011-02-06 18:43:39 +00:00
|
|
|
esac &&
|
|
|
|
output git reset --hard $head &&
|
|
|
|
rm -rf "$dotest"
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
skip)
|
|
|
|
get_saved_options
|
|
|
|
comment_for_reflog skip
|
|
|
|
|
|
|
|
git rerere clear
|
|
|
|
|
|
|
|
output git reset --hard && do_rest
|
|
|
|
;;
|
|
|
|
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
|
2011-02-06 18:43:42 +00:00
|
|
|
output git checkout "$switch_to" -- ||
|
|
|
|
die "Could not checkout $switch_to"
|
2011-02-06 18:43:35 +00:00
|
|
|
fi
|
|
|
|
|
2011-02-06 18:43:37 +00:00
|
|
|
head=$(git rev-parse --verify HEAD) || die "No HEAD?"
|
|
|
|
mkdir "$dotest" || die "Could not create temporary $dotest"
|
2011-02-06 18:43:35 +00:00
|
|
|
|
2011-02-06 18:43:37 +00:00
|
|
|
: > "$dotest"/interactive || die "Could not mark as interactive"
|
2011-02-06 18:43:42 +00:00
|
|
|
echo "$head_name" > "$dotest"/head-name
|
2011-02-06 18:43:35 +00:00
|
|
|
|
2011-02-06 18:43:37 +00:00
|
|
|
echo $head > "$dotest"/head
|
|
|
|
case "$rebase_root" in
|
2011-02-06 18:43:35 +00:00
|
|
|
'')
|
2011-02-06 18:43:37 +00:00
|
|
|
rm -f "$dotest"/rebase-root ;;
|
2011-02-06 18:43:35 +00:00
|
|
|
*)
|
2011-02-06 18:43:37 +00:00
|
|
|
: >"$dotest"/rebase-root ;;
|
2011-02-06 18:43:35 +00:00
|
|
|
esac
|
2011-02-06 18:43:37 +00:00
|
|
|
echo $onto > "$dotest"/onto
|
|
|
|
test -z "$strategy" || echo "$strategy" > "$dotest"/strategy
|
|
|
|
test t = "$verbose" && : > "$dotest"/verbose
|
|
|
|
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" &&
|
|
|
|
for c in $(git merge-base --all $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=
|
|
|
|
first_after_upstream="$(git rev-list --reverse --first-parent $upstream..$head | head -n 1)"
|
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:37 +00:00
|
|
|
shorthead=$(git rev-parse --short $head)
|
|
|
|
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)
|
|
|
|
revisions=$upstream...$head
|
|
|
|
shortrevisions=$shortupstream..$shorthead
|
2011-02-06 18:43:35 +00:00
|
|
|
else
|
2011-02-06 18:43:37 +00:00
|
|
|
revisions=$onto...$head
|
|
|
|
shortrevisions=$shorthead
|
2011-02-06 18:43:35 +00:00
|
|
|
fi
|
2011-02-06 18:43:37 +00:00
|
|
|
git rev-list $merges_option --pretty=oneline --abbrev-commit \
|
2011-02-06 18:43:35 +00:00
|
|
|
--abbrev=7 --reverse --left-right --topo-order \
|
2011-02-06 18:43:37 +00:00
|
|
|
$revisions | \
|
2011-02-06 18:43:35 +00:00
|
|
|
sed -n "s/^>//p" |
|
|
|
|
while read -r shortsha1 rest
|
|
|
|
do
|
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
|
|
|
printf '%s\n' "pick $shortsha1 $rest" >> "$todo"
|
2011-02-06 18:43:35 +00:00
|
|
|
else
|
|
|
|
sha1=$(git rev-parse $shortsha1)
|
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
|
2011-02-06 18:43:37 +00:00
|
|
|
if test -f "$rewritten"/$p -a \( $p != $onto -o $sha1 = $first_after_upstream \)
|
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
|
|
|
|
printf '%s\n' "pick $shortsha1 $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 | \
|
|
|
|
sed -n "s/^>//p" > "$dotest"/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
|
2011-02-06 18:43:37 +00:00
|
|
|
if test -f "$rewritten"/$rev -a "$(sane_grep "$rev" "$dotest"/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
|
2011-02-06 18:43:35 +00:00
|
|
|
short=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev)
|
2011-02-06 18:43:37 +00:00
|
|
|
sane_grep -v "^[a-z][a-z]* $short" <"$todo" > "${todo}2" ; mv "${todo}2" "$todo"
|
|
|
|
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"
|
|
|
|
cat >> "$todo" << EOF
|
2007-11-22 12:30:10 +00:00
|
|
|
|
2011-02-06 18:43:37 +00:00
|
|
|
# Rebase $shortrevisions onto $shortonto
|
2007-06-25 00:11:14 +00:00
|
|
|
#
|
|
|
|
# Commands:
|
2008-06-07 16:20:19 +00:00
|
|
|
# p, pick = use commit
|
2009-10-07 06:13:23 +00:00
|
|
|
# r, reword = use commit, but edit the commit message
|
2008-06-07 16:20:19 +00:00
|
|
|
# e, edit = use commit, but stop for amending
|
|
|
|
# s, squash = use commit, but meld into previous commit
|
2009-12-07 09:20:59 +00: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 00:36:24 +00:00
|
|
|
# x, exec = run command (the rest of the line) using shell
|
2007-07-08 20:32:22 +00:00
|
|
|
#
|
|
|
|
# If you remove a line here THAT COMMIT WILL BE LOST.
|
2007-11-22 12:30:10 +00:00
|
|
|
# However, if you remove everything, the rebase will be aborted.
|
2007-07-08 20:32:22 +00:00
|
|
|
#
|
2007-06-25 00:11:14 +00:00
|
|
|
EOF
|
|
|
|
|
2011-02-06 18:43:37 +00:00
|
|
|
has_action "$todo" ||
|
2011-02-06 18:43:35 +00:00
|
|
|
die_abort "Nothing to do"
|
2007-06-25 00:11:14 +00:00
|
|
|
|
2011-02-06 18:43:37 +00:00
|
|
|
cp "$todo" "$todo".backup
|
|
|
|
git_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" ||
|
2011-02-06 18:43:35 +00:00
|
|
|
die_abort "Nothing to do"
|
2007-06-25 17:56:55 +00:00
|
|
|
|
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
|
|
|
|
2011-02-06 18:43:37 +00:00
|
|
|
output git checkout $onto || die_abort "could not detach HEAD"
|
|
|
|
git update-ref ORIG_HEAD $head
|
2011-02-06 18:43:35 +00:00
|
|
|
do_rest
|