Skip to content

Commit 6633529

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent 984913a commit 6633529

File tree

9 files changed

+71
-4
lines changed

9 files changed

+71
-4
lines changed

Documentation/git-rebase.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ SYNOPSIS
1212
[<upstream> [<branch>]]
1313
'git rebase' [-i | --interactive] [options] [--exec <cmd>] [--onto <newbase>]
1414
--root [<branch>]
15-
'git rebase' --continue | --skip | --abort | --quit | --edit-todo
15+
'git rebase' --continue | --skip | --abort | --quit | --edit-todo | --show-current-patch
1616

1717
DESCRIPTION
1818
-----------
@@ -250,6 +250,10 @@ leave out at most one of A and B, in which case it defaults to HEAD.
250250
--edit-todo::
251251
Edit the todo list during an interactive rebase.
252252

253+
--show-current-patch::
254+
Show the current patch in an interactive rebase or when rebase
255+
is stopped because of conflicts.
256+
253257
-m::
254258
--merge::
255259
Use merging strategies to rebase. When the recursive (default) merge

builtin/am.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,6 +2126,17 @@ static int show_patch(struct am_state *state)
21262126
const char *patch_path;
21272127
int len;
21282128

2129+
if (!is_null_oid(&state->orig_commit)) {
2130+
const char *av[4] = { "show", NULL, "--", NULL };
2131+
char *new_oid_str;
2132+
int ret;
2133+
2134+
av[1] = new_oid_str = xstrdup(oid_to_hex(&state->orig_commit));
2135+
ret = run_command_v_opt(av, RUN_GIT_CMD);
2136+
free(new_oid_str);
2137+
return ret;
2138+
}
2139+
21292140
patch_path = am_path(state, msgnum(state));
21302141
len = strbuf_read_file(&sb, patch_path, 0);
21312142
if (len < 0)

contrib/completion/git-completion.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,11 +1992,11 @@ _git_rebase ()
19921992
{
19931993
__git_find_repo_path
19941994
if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
1995-
__gitcomp "--continue --skip --abort --quit --edit-todo"
1995+
__gitcomp "--continue --skip --abort --quit --edit-todo --show-current-patch"
19961996
return
19971997
elif [ -d "$__git_repo_path"/rebase-apply ] || \
19981998
[ -d "$__git_repo_path"/rebase-merge ]; then
1999-
__gitcomp "--continue --skip --abort --quit"
1999+
__gitcomp "--continue --skip --abort --quit --show-current-patch"
20002000
return
20012001
fi
20022002
__git_complete_strategy && return

git-rebase--am.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ skip)
2727
move_to_original_branch
2828
return
2929
;;
30+
show-current-patch)
31+
exec git am --show-current-patch
32+
;;
3033
esac
3134

3235
if test -z "$rebase_root"

git-rebase--interactive.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,9 @@ To continue rebase after editing, run:
840840

841841
exit
842842
;;
843+
show-current-patch)
844+
exec git show "$(cat "$state_dir/stopped-sha")" --
845+
;;
843846
esac
844847

845848
comment_for_reflog start

git-rebase--merge.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ skip)
137137
finish_rb_merge
138138
return
139139
;;
140+
show-current-patch)
141+
exec git show "$(cat "$state_dir/current")" --
142+
;;
140143
esac
141144

142145
mkdir -p "$state_dir"

git-rebase.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ abort! abort and check out the original branch
4545
skip! skip current patch and continue
4646
edit-todo! edit the todo list during an interactive rebase
4747
quit! abort but keep HEAD where it is
48+
show-current-patch! show the patch file being applied or merged
4849
"
4950
. git-sh-setup
5051
set_reflog_action rebase
@@ -245,7 +246,7 @@ do
245246
--verify)
246247
ok_to_skip_pre_rebase=
247248
;;
248-
--continue|--skip|--abort|--quit|--edit-todo)
249+
--continue|--skip|--abort|--quit|--edit-todo|--show-current-patch)
249250
test $total_argc -eq 2 || usage
250251
action=${1##--}
251252
;;
@@ -412,6 +413,10 @@ quit)
412413
edit-todo)
413414
run_specific_rebase
414415
;;
416+
show-current-patch)
417+
run_specific_rebase
418+
die "BUG: run_specific_rebase is not supposed to return here"
419+
;;
415420
esac
416421

417422
# Make sure no rebase is in progress

t/t3400-rebase.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,4 +277,37 @@ EOF
277277
test_cmp From_.msg out
278278
'
279279

280+
test_expect_success 'rebase--am.sh and --show-current-patch' '
281+
test_create_repo conflict-apply &&
282+
(
283+
cd conflict-apply &&
284+
test_commit init &&
285+
echo one >>init.t &&
286+
git commit -a -m one &&
287+
echo two >>init.t &&
288+
git commit -a -m two &&
289+
git tag two &&
290+
test_must_fail git rebase --onto init HEAD^ &&
291+
GIT_TRACE=1 git rebase --show-current-patch >/dev/null 2>stderr &&
292+
grep "show.*$(git rev-parse two)" stderr
293+
)
294+
'
295+
296+
test_expect_success 'rebase--merge.sh and --show-current-patch' '
297+
test_create_repo conflict-merge &&
298+
(
299+
cd conflict-merge &&
300+
test_commit init &&
301+
echo one >>init.t &&
302+
git commit -a -m one &&
303+
echo two >>init.t &&
304+
git commit -a -m two &&
305+
git tag two &&
306+
test_must_fail git rebase --merge --onto init HEAD^ &&
307+
git rebase --show-current-patch >actual.patch &&
308+
GIT_TRACE=1 git rebase --show-current-patch >/dev/null 2>stderr &&
309+
grep "show.*$(git rev-parse two)" stderr
310+
)
311+
'
312+
280313
test_done

t/t3404-rebase-interactive.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ test_expect_success 'stop on conflicting pick' '
225225
test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
226226
'
227227

228+
test_expect_success 'show conflicted patch' '
229+
GIT_TRACE=1 git rebase --show-current-patch >/dev/null 2>stderr &&
230+
grep "show.*$(cat "$state_dir/stopped-sha")" stderr
231+
'
232+
228233
test_expect_success 'abort' '
229234
git rebase --abort &&
230235
test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&

0 commit comments

Comments
 (0)