rebase: act on command line outside parsing loop

To later be able to use the command line processing in git-rebase.sh
for both interactive and non-interactive rebases, move anything that
is specific to non-interactive rebase outside of the parsing
loop. Keep only parsing and validation of command line options in the
loop.

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Martin von Zweigbergk 2011-02-06 13:43:35 -05:00 committed by Junio C Hamano
parent 99de0640f2
commit 3426232248
2 changed files with 213 additions and 205 deletions

View File

@ -866,57 +866,63 @@ first and then run 'git rebase --continue' again."
;; ;;
--) --)
shift shift
test -z "$REBASE_ROOT" -a $# -ge 1 -a $# -le 2 || break
test ! -z "$REBASE_ROOT" -a $# -le 1 || usage ;;
test -d "$DOTEST" && esac
shift
done

test -z "$REBASE_ROOT" -a $# -ge 1 -a $# -le 2 ||
test ! -z "$REBASE_ROOT" -a $# -le 1 || usage
test -d "$DOTEST" &&
die "Interactive rebase already started" die "Interactive rebase already started"


git var GIT_COMMITTER_IDENT >/dev/null || git var GIT_COMMITTER_IDENT >/dev/null ||
die "You need to set your committer info first" die "You need to set your committer info first"


if test -z "$REBASE_ROOT" if test -z "$REBASE_ROOT"
then then
UPSTREAM_ARG="$1" UPSTREAM_ARG="$1"
UPSTREAM=$(git rev-parse --verify "$1") || die "Invalid base" UPSTREAM=$(git rev-parse --verify "$1") || die "Invalid base"
test -z "$ONTO" && ONTO=$UPSTREAM test -z "$ONTO" && ONTO=$UPSTREAM
shift shift
else else
UPSTREAM= UPSTREAM=
UPSTREAM_ARG=--root UPSTREAM_ARG=--root
test -z "$ONTO" && test -z "$ONTO" &&
die "You must specify --onto when using --root" die "You must specify --onto when using --root"
fi fi
run_pre_rebase_hook "$UPSTREAM_ARG" "$@" run_pre_rebase_hook "$UPSTREAM_ARG" "$@"


comment_for_reflog start comment_for_reflog start


require_clean_work_tree "rebase" "Please commit or stash them." require_clean_work_tree "rebase" "Please commit or stash them."


if test ! -z "$1" if test ! -z "$1"
then then
output git checkout "$1" -- || output git checkout "$1" -- ||
die "Could not checkout $1" die "Could not checkout $1"
fi fi


HEAD=$(git rev-parse --verify HEAD) || die "No HEAD?" HEAD=$(git rev-parse --verify HEAD) || die "No HEAD?"
mkdir "$DOTEST" || die "Could not create temporary $DOTEST" mkdir "$DOTEST" || die "Could not create temporary $DOTEST"


: > "$DOTEST"/interactive || die "Could not mark as interactive" : > "$DOTEST"/interactive || die "Could not mark as interactive"
git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null || git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||
echo "detached HEAD" > "$DOTEST"/head-name echo "detached HEAD" > "$DOTEST"/head-name


echo $HEAD > "$DOTEST"/head echo $HEAD > "$DOTEST"/head
case "$REBASE_ROOT" in case "$REBASE_ROOT" in
'') '')
rm -f "$DOTEST"/rebase-root ;; rm -f "$DOTEST"/rebase-root ;;
*) *)
: >"$DOTEST"/rebase-root ;; : >"$DOTEST"/rebase-root ;;
esac esac
echo $ONTO > "$DOTEST"/onto echo $ONTO > "$DOTEST"/onto
test -z "$STRATEGY" || echo "$STRATEGY" > "$DOTEST"/strategy test -z "$STRATEGY" || echo "$STRATEGY" > "$DOTEST"/strategy
test t = "$VERBOSE" && : > "$DOTEST"/verbose test t = "$VERBOSE" && : > "$DOTEST"/verbose
if test t = "$PRESERVE_MERGES" if test t = "$PRESERVE_MERGES"
then then
if test -z "$REBASE_ROOT" if test -z "$REBASE_ROOT"
then then
mkdir "$REWRITTEN" && mkdir "$REWRITTEN" &&
@ -935,28 +941,28 @@ first and then run 'git rebase --continue' again."
# prematurely end our probe # prematurely end our probe
MERGES_OPTION= MERGES_OPTION=
first_after_upstream="$(git rev-list --reverse --first-parent $UPSTREAM..$HEAD | head -n 1)" first_after_upstream="$(git rev-list --reverse --first-parent $UPSTREAM..$HEAD | head -n 1)"
else else
MERGES_OPTION="--no-merges --cherry-pick" MERGES_OPTION="--no-merges --cherry-pick"
fi fi


SHORTHEAD=$(git rev-parse --short $HEAD) SHORTHEAD=$(git rev-parse --short $HEAD)
SHORTONTO=$(git rev-parse --short $ONTO) SHORTONTO=$(git rev-parse --short $ONTO)
if test -z "$REBASE_ROOT" if test -z "$REBASE_ROOT"
# this is now equivalent to ! -z "$UPSTREAM" # this is now equivalent to ! -z "$UPSTREAM"
then then
SHORTUPSTREAM=$(git rev-parse --short $UPSTREAM) SHORTUPSTREAM=$(git rev-parse --short $UPSTREAM)
REVISIONS=$UPSTREAM...$HEAD REVISIONS=$UPSTREAM...$HEAD
SHORTREVISIONS=$SHORTUPSTREAM..$SHORTHEAD SHORTREVISIONS=$SHORTUPSTREAM..$SHORTHEAD
else else
REVISIONS=$ONTO...$HEAD REVISIONS=$ONTO...$HEAD
SHORTREVISIONS=$SHORTHEAD SHORTREVISIONS=$SHORTHEAD
fi fi
git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \ git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \
--abbrev=7 --reverse --left-right --topo-order \ --abbrev=7 --reverse --left-right --topo-order \
$REVISIONS | \ $REVISIONS | \
sed -n "s/^>//p" | sed -n "s/^>//p" |
while read -r shortsha1 rest while read -r shortsha1 rest
do do
if test t != "$PRESERVE_MERGES" if test t != "$PRESERVE_MERGES"
then then
printf '%s\n' "pick $shortsha1 $rest" >> "$TODO" printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
@ -981,11 +987,11 @@ first and then run 'git rebase --continue' again."
printf '%s\n' "pick $shortsha1 $rest" >> "$TODO" printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
fi fi
fi fi
done done


# Watch for commits that been dropped by --cherry-pick # Watch for commits that been dropped by --cherry-pick
if test t = "$PRESERVE_MERGES" if test t = "$PRESERVE_MERGES"
then then
mkdir "$DROPPED" mkdir "$DROPPED"
# Save all non-cherry-picked changes # Save all non-cherry-picked changes
git rev-list $REVISIONS --left-right --cherry-pick | \ git rev-list $REVISIONS --left-right --cherry-pick | \
@ -1007,11 +1013,11 @@ first and then run 'git rebase --continue' again."
rm "$REWRITTEN"/$rev rm "$REWRITTEN"/$rev
fi fi
done done
fi fi


test -s "$TODO" || echo noop >> "$TODO" test -s "$TODO" || echo noop >> "$TODO"
test -n "$AUTOSQUASH" && rearrange_squash "$TODO" test -n "$AUTOSQUASH" && rearrange_squash "$TODO"
cat >> "$TODO" << EOF cat >> "$TODO" << EOF


# Rebase $SHORTREVISIONS onto $SHORTONTO # Rebase $SHORTREVISIONS onto $SHORTONTO
# #
@ -1028,22 +1034,18 @@ first and then run 'git rebase --continue' again."
# #
EOF EOF


has_action "$TODO" || has_action "$TODO" ||
die_abort "Nothing to do" die_abort "Nothing to do"


cp "$TODO" "$TODO".backup cp "$TODO" "$TODO".backup
git_editor "$TODO" || git_editor "$TODO" ||
die_abort "Could not execute editor" die_abort "Could not execute editor"


has_action "$TODO" || has_action "$TODO" ||
die_abort "Nothing to do" die_abort "Nothing to do"


test -d "$REWRITTEN" || test -n "$NEVER_FF" || skip_unnecessary_picks test -d "$REWRITTEN" || test -n "$NEVER_FF" || skip_unnecessary_picks


output git checkout $ONTO || die_abort "could not detach HEAD" output git checkout $ONTO || die_abort "could not detach HEAD"
git update-ref ORIG_HEAD $HEAD git update-ref ORIG_HEAD $HEAD
do_rest do_rest
;;
esac
shift
done

View File

@ -62,6 +62,8 @@ in_progress=
type= type=
# One of {"$GIT_DIR"/rebase-apply, "$GIT_DIR"/rebase-merge} # One of {"$GIT_DIR"/rebase-apply, "$GIT_DIR"/rebase-merge}
state_dir= state_dir=
# One of {'', continue, skip, abort}, as parsed from command line
action=


read_state () { read_state () {
if test "$type" = merge if test "$type" = merge
@ -236,66 +238,10 @@ do
--verify) --verify)
OK_TO_SKIP_PRE_REBASE= OK_TO_SKIP_PRE_REBASE=
;; ;;
--continue) --continue|--skip|--abort)
test -z "$in_progress" && die "No rebase in progress?" action=${1##--}

shift
git update-index --ignore-submodules --refresh && break
git diff-files --quiet --ignore-submodules || {
echo "You must edit all merge conflicts and then"
echo "mark them as resolved using git add"
exit 1
}
read_state
if test -d "$merge_dir"
then
continue_merge
while test "$msgnum" -le "$end"
do
call_merge "$msgnum"
continue_merge
done
finish_rb_merge
exit
fi
git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
move_to_original_branch
exit
;;
--skip)
test -z "$in_progress" && die "No rebase in progress?"

git reset --hard HEAD || exit $?
read_state
if test -d "$merge_dir"
then
git rerere clear
msgnum=$(($msgnum + 1))
while test "$msgnum" -le "$end"
do
call_merge "$msgnum"
continue_merge
done
finish_rb_merge
exit
fi
git am -3 --skip --resolvemsg="$RESOLVEMSG" &&
move_to_original_branch
exit
;;
--abort)
test -z "$in_progress" && die "No rebase in progress?"

git rerere clear
read_state
case "$head_name" in
refs/*)
git symbolic-ref HEAD $head_name ||
die "Could not move back to $head_name"
;;
esac
git reset --hard $orig_head
rm -r "$state_dir"
exit
;; ;;
--onto) --onto)
test 2 -le "$#" || usage test 2 -le "$#" || usage
@ -391,6 +337,66 @@ do
done done
test $# -gt 2 && usage test $# -gt 2 && usage


test -n "$action" && test -z "$in_progress" && die "No rebase in progress?"

case "$action" in
continue)
git update-index --ignore-submodules --refresh &&
git diff-files --quiet --ignore-submodules || {
echo "You must edit all merge conflicts and then"
echo "mark them as resolved using git add"
exit 1
}
read_state
if test -d "$merge_dir"
then
continue_merge
while test "$msgnum" -le "$end"
do
call_merge "$msgnum"
continue_merge
done
finish_rb_merge
exit
fi
git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
move_to_original_branch
exit
;;
skip)
git reset --hard HEAD || exit $?
read_state
if test -d "$merge_dir"
then
git rerere clear
msgnum=$(($msgnum + 1))
while test "$msgnum" -le "$end"
do
call_merge "$msgnum"
continue_merge
done
finish_rb_merge
exit
fi
git am -3 --skip --resolvemsg="$RESOLVEMSG" &&
move_to_original_branch
exit
;;
abort)
git rerere clear
read_state
case "$head_name" in
refs/*)
git symbolic-ref HEAD $head_name ||
die "Could not move back to $head_name"
;;
esac
git reset --hard $orig_head
rm -r "$state_dir"
exit
;;
esac

# Make sure no rebase is in progress # Make sure no rebase is in progress
if test -n "$in_progress" if test -n "$in_progress"
then then