Skip to content

Commit 2959c28

Browse files
Martin von Zweigbergkgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4974c2c commit 2959c28

File tree

2 files changed

+18
-33
lines changed

2 files changed

+18
-33
lines changed

git-rebase--interactive.sh

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,7 @@ do_next () {
509509
test -s "$todo" && return
510510

511511
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) &&
515513
newhead=$(git rev-parse HEAD) &&
516514
case $head_name in
517515
refs/*)
@@ -521,7 +519,7 @@ do_next () {
521519
;;
522520
esac && {
523521
test ! -f "$state_dir"/verbose ||
524-
git diff-tree --stat $(cat "$state_dir"/head)..HEAD
522+
git diff-tree --stat $orig_head..HEAD
525523
} &&
526524
{
527525
test -s "$rewritten_list" &&
@@ -655,14 +653,6 @@ rearrange_squash () {
655653
case "$action" in
656654
continue)
657655
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"
666656

667657
# do we have anything to commit?
668658
if git diff-index --cached --quiet --ignore-submodules HEAD --
@@ -693,30 +683,12 @@ first and then run 'git rebase --continue' again."
693683
require_clean_work_tree "rebase"
694684
do_rest
695685
;;
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-
;;
713686
skip)
714687
get_saved_options
715-
comment_for_reflog skip
716688

717689
git rerere clear
718690

719-
output git reset --hard && do_rest
691+
do_rest
720692
;;
721693
esac
722694

git-rebase.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
7070
read_basic_state () {
7171
head_name=$(cat "$state_dir"/head-name) &&
7272
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 &&
7479
GIT_QUIET=$(cat "$state_dir"/quiet)
7580
}
7681

@@ -262,11 +267,19 @@ test $# -gt 2 && usage
262267
if test -n "$action"
263268
then
264269
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
266276
fi
267277

268278
case "$action" in
269279
continue)
280+
# Sanity check
281+
git rev-parse --verify HEAD >/dev/null ||
282+
die "Cannot read HEAD"
270283
git update-index --ignore-submodules --refresh &&
271284
git diff-files --quiet --ignore-submodules || {
272285
echo "You must edit all merge conflicts and then"

0 commit comments

Comments
 (0)