rebase: add --show-current-patch
It is useful to see the full patch while resolving conflicts in a rebase. The only way to do it now is less .git/rebase-*/patch which could turn out to be a lot longer to type if you are in a linked worktree, or not at top-dir. On top of that, an ordinary user should not need to peek into .git directory. The new option is provided to examine the patch. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
984913a210
commit
66335298a4
@ -12,7 +12,7 @@ SYNOPSIS
|
|||||||
[<upstream> [<branch>]]
|
[<upstream> [<branch>]]
|
||||||
'git rebase' [-i | --interactive] [options] [--exec <cmd>] [--onto <newbase>]
|
'git rebase' [-i | --interactive] [options] [--exec <cmd>] [--onto <newbase>]
|
||||||
--root [<branch>]
|
--root [<branch>]
|
||||||
'git rebase' --continue | --skip | --abort | --quit | --edit-todo
|
'git rebase' --continue | --skip | --abort | --quit | --edit-todo | --show-current-patch
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
@ -250,6 +250,10 @@ leave out at most one of A and B, in which case it defaults to HEAD.
|
|||||||
--edit-todo::
|
--edit-todo::
|
||||||
Edit the todo list during an interactive rebase.
|
Edit the todo list during an interactive rebase.
|
||||||
|
|
||||||
|
--show-current-patch::
|
||||||
|
Show the current patch in an interactive rebase or when rebase
|
||||||
|
is stopped because of conflicts.
|
||||||
|
|
||||||
-m::
|
-m::
|
||||||
--merge::
|
--merge::
|
||||||
Use merging strategies to rebase. When the recursive (default) merge
|
Use merging strategies to rebase. When the recursive (default) merge
|
||||||
|
11
builtin/am.c
11
builtin/am.c
@ -2126,6 +2126,17 @@ static int show_patch(struct am_state *state)
|
|||||||
const char *patch_path;
|
const char *patch_path;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
|
if (!is_null_oid(&state->orig_commit)) {
|
||||||
|
const char *av[4] = { "show", NULL, "--", NULL };
|
||||||
|
char *new_oid_str;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
av[1] = new_oid_str = xstrdup(oid_to_hex(&state->orig_commit));
|
||||||
|
ret = run_command_v_opt(av, RUN_GIT_CMD);
|
||||||
|
free(new_oid_str);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
patch_path = am_path(state, msgnum(state));
|
patch_path = am_path(state, msgnum(state));
|
||||||
len = strbuf_read_file(&sb, patch_path, 0);
|
len = strbuf_read_file(&sb, patch_path, 0);
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
|
@ -1992,11 +1992,11 @@ _git_rebase ()
|
|||||||
{
|
{
|
||||||
__git_find_repo_path
|
__git_find_repo_path
|
||||||
if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
|
if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
|
||||||
__gitcomp "--continue --skip --abort --quit --edit-todo"
|
__gitcomp "--continue --skip --abort --quit --edit-todo --show-current-patch"
|
||||||
return
|
return
|
||||||
elif [ -d "$__git_repo_path"/rebase-apply ] || \
|
elif [ -d "$__git_repo_path"/rebase-apply ] || \
|
||||||
[ -d "$__git_repo_path"/rebase-merge ]; then
|
[ -d "$__git_repo_path"/rebase-merge ]; then
|
||||||
__gitcomp "--continue --skip --abort --quit"
|
__gitcomp "--continue --skip --abort --quit --show-current-patch"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
__git_complete_strategy && return
|
__git_complete_strategy && return
|
||||||
|
@ -27,6 +27,9 @@ skip)
|
|||||||
move_to_original_branch
|
move_to_original_branch
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
|
show-current-patch)
|
||||||
|
exec git am --show-current-patch
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if test -z "$rebase_root"
|
if test -z "$rebase_root"
|
||||||
|
@ -840,6 +840,9 @@ To continue rebase after editing, run:
|
|||||||
|
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
|
show-current-patch)
|
||||||
|
exec git show "$(cat "$state_dir/stopped-sha")" --
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
comment_for_reflog start
|
comment_for_reflog start
|
||||||
|
@ -137,6 +137,9 @@ skip)
|
|||||||
finish_rb_merge
|
finish_rb_merge
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
|
show-current-patch)
|
||||||
|
exec git show "$(cat "$state_dir/current")" --
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
mkdir -p "$state_dir"
|
mkdir -p "$state_dir"
|
||||||
|
@ -45,6 +45,7 @@ abort! abort and check out the original branch
|
|||||||
skip! skip current patch and continue
|
skip! skip current patch and continue
|
||||||
edit-todo! edit the todo list during an interactive rebase
|
edit-todo! edit the todo list during an interactive rebase
|
||||||
quit! abort but keep HEAD where it is
|
quit! abort but keep HEAD where it is
|
||||||
|
show-current-patch! show the patch file being applied or merged
|
||||||
"
|
"
|
||||||
. git-sh-setup
|
. git-sh-setup
|
||||||
set_reflog_action rebase
|
set_reflog_action rebase
|
||||||
@ -245,7 +246,7 @@ do
|
|||||||
--verify)
|
--verify)
|
||||||
ok_to_skip_pre_rebase=
|
ok_to_skip_pre_rebase=
|
||||||
;;
|
;;
|
||||||
--continue|--skip|--abort|--quit|--edit-todo)
|
--continue|--skip|--abort|--quit|--edit-todo|--show-current-patch)
|
||||||
test $total_argc -eq 2 || usage
|
test $total_argc -eq 2 || usage
|
||||||
action=${1##--}
|
action=${1##--}
|
||||||
;;
|
;;
|
||||||
@ -412,6 +413,10 @@ quit)
|
|||||||
edit-todo)
|
edit-todo)
|
||||||
run_specific_rebase
|
run_specific_rebase
|
||||||
;;
|
;;
|
||||||
|
show-current-patch)
|
||||||
|
run_specific_rebase
|
||||||
|
die "BUG: run_specific_rebase is not supposed to return here"
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Make sure no rebase is in progress
|
# Make sure no rebase is in progress
|
||||||
|
@ -277,4 +277,37 @@ EOF
|
|||||||
test_cmp From_.msg out
|
test_cmp From_.msg out
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'rebase--am.sh and --show-current-patch' '
|
||||||
|
test_create_repo conflict-apply &&
|
||||||
|
(
|
||||||
|
cd conflict-apply &&
|
||||||
|
test_commit init &&
|
||||||
|
echo one >>init.t &&
|
||||||
|
git commit -a -m one &&
|
||||||
|
echo two >>init.t &&
|
||||||
|
git commit -a -m two &&
|
||||||
|
git tag two &&
|
||||||
|
test_must_fail git rebase --onto init HEAD^ &&
|
||||||
|
GIT_TRACE=1 git rebase --show-current-patch >/dev/null 2>stderr &&
|
||||||
|
grep "show.*$(git rev-parse two)" stderr
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'rebase--merge.sh and --show-current-patch' '
|
||||||
|
test_create_repo conflict-merge &&
|
||||||
|
(
|
||||||
|
cd conflict-merge &&
|
||||||
|
test_commit init &&
|
||||||
|
echo one >>init.t &&
|
||||||
|
git commit -a -m one &&
|
||||||
|
echo two >>init.t &&
|
||||||
|
git commit -a -m two &&
|
||||||
|
git tag two &&
|
||||||
|
test_must_fail git rebase --merge --onto init HEAD^ &&
|
||||||
|
git rebase --show-current-patch >actual.patch &&
|
||||||
|
GIT_TRACE=1 git rebase --show-current-patch >/dev/null 2>stderr &&
|
||||||
|
grep "show.*$(git rev-parse two)" stderr
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
@ -225,6 +225,11 @@ test_expect_success 'stop on conflicting pick' '
|
|||||||
test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
|
test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'show conflicted patch' '
|
||||||
|
GIT_TRACE=1 git rebase --show-current-patch >/dev/null 2>stderr &&
|
||||||
|
grep "show.*$(cat "$state_dir/stopped-sha")" stderr
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'abort' '
|
test_expect_success 'abort' '
|
||||||
git rebase --abort &&
|
git rebase --abort &&
|
||||||
test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
|
test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
|
||||||
|
Reference in New Issue
Block a user