output () {
case "$VERBOSE" in
'')
- "$@" > "$DOTEST"/output 2>&1
+ output=$("$@" 2>&1 )
status=$?
- test $status != 0 &&
- cat "$DOTEST"/output
+ test $status != 0 && printf "%s\n" "$output"
return $status
;;
*)
make_patch () {
parent_sha1=$(git rev-parse --verify "$1"^) ||
die "Cannot get patch for $1^"
- git diff "$parent_sha1".."$1" > "$DOTEST"/patch
+ git diff-tree -p "$parent_sha1".."$1" > "$DOTEST"/patch
test -f "$DOTEST"/message ||
git cat-file commit "$1" | sed "1,/^$/d" > "$DOTEST"/message
test -f "$DOTEST"/author-script ||
parent_sha1=$(git rev-parse --verify $sha1^) ||
die "Could not get the parent of $sha1"
current_sha1=$(git rev-parse --verify HEAD)
- if test $no_ff$current_sha1 = $parent_sha1; then
+ if test "$no_ff$current_sha1" = "$parent_sha1"; then
output git reset --hard $sha1
test "a$1" = a-n && output git reset --soft $current_sha1
sha1=$(git rev-parse --short $sha1)
eval "$author_script"
msg="$(git cat-file commit $sha1 | sed -e '1,/^$/d')"
# NEEDSWORK: give rerere a chance
- if ! output git merge $STRATEGY -m "$msg" $new_parents
+ if ! GIT_AUTHOR_NAME="$GIT_AUTHOR_NAME" \
+ GIT_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL" \
+ GIT_AUTHOR_DATE="$GIT_AUTHOR_DATE" \
+ output git merge $STRATEGY -m "$msg" \
+ $new_parents
then
printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG
die Error redoing merge $sha1
'#'*|'')
mark_action_done
;;
- pick)
+ pick|p)
comment_for_reflog pick
mark_action_done
pick_one $sha1 ||
die_with_patch $sha1 "Could not apply $sha1... $rest"
;;
- edit)
+ edit|e)
comment_for_reflog edit
mark_action_done
warn
exit 0
;;
- squash)
+ squash|s)
comment_for_reflog squash
has_action "$DONE" ||
mark_action_done
make_squash_message $sha1 > "$MSG"
case "$(peek_next_command)" in
- squash)
+ squash|s)
EDIT_COMMIT=
USE_OUTPUT=output
cp "$MSG" "$SQUASH_MSG"
esac
failed=f
+ author_script=$(get_author_ident_from_commit HEAD)
output git reset --soft HEAD^
pick_one -n $sha1 || failed=t
- author_script=$(get_author_ident_from_commit $sha1)
echo "$author_script" > "$DOTEST"/author-script
case $failed in
f)
# This is like --amend, but with a different message
eval "$author_script"
- export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
+ GIT_AUTHOR_NAME="$GIT_AUTHOR_NAME" \
+ GIT_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL" \
+ GIT_AUTHOR_DATE="$GIT_AUTHOR_DATE" \
$USE_OUTPUT git commit -F "$MSG" $EDIT_COMMIT
;;
t)
else
NEWHEAD=$(git rev-parse HEAD)
fi &&
- message="$GIT_REFLOG_ACTION: $HEADNAME onto $SHORTONTO)" &&
- git update-ref -m "$message" $HEADNAME $NEWHEAD $OLDHEAD &&
- git symbolic-ref HEAD $HEADNAME && {
+ case $HEADNAME in
+ refs/*)
+ message="$GIT_REFLOG_ACTION: $HEADNAME onto $SHORTONTO)" &&
+ git update-ref -m "$message" $HEADNAME $NEWHEAD $OLDHEAD &&
+ git symbolic-ref HEAD $HEADNAME
+ ;;
+ esac && {
test ! -f "$DOTEST"/verbose ||
- git diff --stat $(cat "$DOTEST"/head)..HEAD
+ git diff-tree --stat $(cat "$DOTEST"/head)..HEAD
} &&
rm -rf "$DOTEST" &&
+ git gc --auto &&
warn "Successfully rebased and updated $HEADNAME."
exit
HEADNAME=$(cat "$DOTEST"/head-name)
HEAD=$(cat "$DOTEST"/head)
- git symbolic-ref HEAD $HEADNAME &&
+ case $HEADNAME in
+ refs/*)
+ git symbolic-ref HEAD $HEADNAME
+ ;;
+ esac &&
output git reset --hard $HEAD &&
rm -rf "$DOTEST"
exit
require_clean_work_tree
- mkdir "$DOTEST" || die "Could not create temporary $DOTEST"
if test ! -z "$2"
then
output git show-ref --verify --quiet "refs/heads/$2" ||
HEAD=$(git rev-parse --verify HEAD) || die "No HEAD?"
UPSTREAM=$(git rev-parse --verify "$1") || die "Invalid base"
+ mkdir "$DOTEST" || die "Could not create temporary $DOTEST"
+
test -z "$ONTO" && ONTO=$UPSTREAM
: > "$DOTEST"/interactive || die "Could not mark as interactive"
- git symbolic-ref HEAD > "$DOTEST"/head-name ||
- die "Could not get HEAD"
+ git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||
+ echo "detached HEAD" > "$DOTEST"/head-name
echo $HEAD > "$DOTEST"/head
echo $UPSTREAM > "$DOTEST"/upstream