rebase: factor out sub command handling
Factor out the common parts of the handling of the sub commands '--continue', '--skip' and '--abort'. The '--abort' handling can handled completely in git-rebase.sh. After this refactoring, the calls to git-rebase--am.sh, git-rebase--merge.sh and git-rebase--interactive.sh will be better aligned. There will only be one call to interactive rebase that will shortcut the very last part of git-rebase.sh. Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Martin von Zweigbergk committed
Feb 6, 2011 at 13:43 UTC
2959c283662c62e90d08d3795073534f278deee6
2 files changed
+18
-33
git-rebase--interactive.sh
+3
-31
@@ -509,9 +509,7 @@ do_next () {
509
test -s "$todo" && return
510
511
comment_for_reflog finish &&
512
- head_name=$(cat "$state_dir"/head-name) &&
513
- orig_head=$(cat "$state_dir"/head) &&
514
- shortonto=$(git rev-parse --short $(cat "$state_dir"/onto)) &&
512
+ shortonto=$(git rev-parse --short $onto) &&
513
newhead=$(git rev-parse HEAD) &&
514
case $head_name in
515
refs/*)
@@ -521,7 +519,7 @@ do_next () {
519
;;
520
esac && {
521
test ! -f "$state_dir"/verbose ||
524
- git diff-tree --stat $(cat "$state_dir"/head)..HEAD
522
+ git diff-tree --stat $orig_head..HEAD
523
} &&
524
{
525
test -s "$rewritten_list" &&
@@ -655,14 +653,6 @@ rearrange_squash () {
653
case "$action" in
654
continue)
655
get_saved_options
658
- comment_for_reflog continue
659
-
660
- # Sanity check
661
- git rev-parse --verify HEAD >/dev/null ||
662
- die "Cannot read HEAD"
663
- git update-index --ignore-submodules --refresh &&
664
- git diff-files --quiet --ignore-submodules ||
665
- die "Working tree is dirty"
656
657
# do we have anything to commit?
658
if git diff-index --cached --quiet --ignore-submodules HEAD --
@@ -693,30 +683,12 @@ first and then run 'git rebase --continue' again."
683
require_clean_work_tree "rebase"
684
do_rest
685
;;
696
-abort)
697
- get_saved_options
698
- comment_for_reflog abort
699
-
700
- git rerere clear
701
-
702
- head_name=$(cat "$state_dir"/head-name)
703
- orig_head=$(cat "$state_dir"/head)
704
- case $head_name in
705
- refs/*)
706
- git symbolic-ref HEAD $head_name
707
- ;;
708
- esac &&
709
- output git reset --hard $orig_head &&
710
- rm -rf "$state_dir"
711
- exit
712
- ;;
686
skip)
687
get_saved_options
715
- comment_for_reflog skip
688
689
git rerere clear
690
719
- output git reset --hard && do_rest
691
+ do_rest
692
;;
693
esac
694
git-rebase.sh
+15
-2
@@ -70,7 +70,12 @@ test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
70
read_basic_state () {
71
head_name=$(cat "$state_dir"/head-name) &&
72
onto=$(cat "$state_dir"/onto) &&
73
- orig_head=$(cat "$state_dir"/orig-head) &&
73
+ if test "$type" = interactive
74
+ then
75
+ orig_head=$(cat "$state_dir"/head)
76
+ else
77
+ orig_head=$(cat "$state_dir"/orig-head)
78
+ fi &&
79
GIT_QUIET=$(cat "$state_dir"/quiet)
80
}
81
@@ -262,11 +267,19 @@ test $# -gt 2 && usage
267
if test -n "$action"
268
then
269
test -z "$in_progress" && die "No rebase in progress?"
265
- test "$type" = interactive && run_specific_rebase
270
+ # Only interactive rebase uses detailed reflog messages
271
+ if test "$type" = interactive && test "$GIT_REFLOG_ACTION" = rebase
272
+ then
273
+ GIT_REFLOG_ACTION="rebase -i ($action)"
274
+ export GIT_REFLOG_ACTION
275
+ fi
276
fi
277
278
case "$action" in
279
continue)
280
+ # Sanity check
281
+ git rev-parse --verify HEAD >/dev/null ||
282
+ die "Cannot read HEAD"
283
git update-index --ignore-submodules --refresh &&
284
git diff-files --quiet --ignore-submodules || {
285
echo "You must edit all merge conflicts and then"