Re: [PATCH 2/2] rebase: add --show-patch

2018-01-26 Thread Phillip Wood
On 26/01/18 09:55, Nguyễn Thái Ngọc Duy wrote:
> 
> 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 [1] 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.
> 
> [1] A conflict caused by git-rebase--am.sh does show the path to this
> patch file so you could copy/paste. But then after some time and
> lots of commands to resolve the conflict, that path is likely
> scrolled out of your terminal.
> 
> Signed-off-by: Nguyễn Thái Ngọc Duy 
> ---
>  Documentation/git-rebase.txt   |  5 +++-
>  contrib/completion/git-completion.bash |  4 +--
>  git-rebase--am.sh  |  3 +++
>  git-rebase--interactive.sh |  4 +++
>  git-rebase--merge.sh   |  4 +++
>  git-rebase.sh  |  7 +-
>  t/t3400-rebase.sh  | 34 ++
>  t/t3404-rebase-interactive.sh  |  6 +
>  8 files changed, 63 insertions(+), 4 deletions(-)
> 
> diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
> index 8a861c1e0d..4fd571d393 100644
> --- a/Documentation/git-rebase.txt
> +++ b/Documentation/git-rebase.txt
> @@ -12,7 +12,7 @@ SYNOPSIS
>   [ []]
>  'git rebase' [-i | --interactive] [options] [--exec ] [--onto ]
>   --root []
> -'git rebase' --continue | --skip | --abort | --quit | --edit-todo
> +'git rebase' --continue | --skip | --abort | --quit | --edit-todo | 
> --show-patch
>  
>  DESCRIPTION
>  ---
> @@ -250,6 +250,9 @@ leave out at most one of A and B, in which case it 
> defaults to HEAD.
>  --edit-todo::
>   Edit the todo list during an interactive rebase.
>  
> +--show-patch::
> + Show the current patch in an interactive rebase.
> +
>  -m::
>  --merge::
>   Use merging strategies to rebase.  When the recursive (default) merge
> diff --git a/contrib/completion/git-completion.bash 
> b/contrib/completion/git-completion.bash
> index 1e9105f6d5..b70da4990f 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -1992,11 +1992,11 @@ _git_rebase ()
>  {
>   __git_find_repo_path
>   if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
> - __gitcomp "--continue --skip --abort --quit --edit-todo"
> + __gitcomp "--continue --skip --abort --quit --edit-todo 
> --show-patch"
>   return
>   elif [ -d "$__git_repo_path"/rebase-apply ] || \
>[ -d "$__git_repo_path"/rebase-merge ]; then
> - __gitcomp "--continue --skip --abort --quit"
> + __gitcomp "--continue --skip --abort --quit --show-patch"
>   return
>   fi
>   __git_complete_strategy && return
> diff --git a/git-rebase--am.sh b/git-rebase--am.sh
> index 14c50782e0..564a4a5830 100644
> --- a/git-rebase--am.sh
> +++ b/git-rebase--am.sh
> @@ -27,6 +27,9 @@ skip)
>   move_to_original_branch
>   return
>   ;;
> +show-patch)
> + exec git am --show-patch
> + ;;
>  esac
>  
>  if test -z "$rebase_root"
> diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
> index d47bd29593..01cc002efd 100644
> --- a/git-rebase--interactive.sh
> +++ b/git-rebase--interactive.sh
> @@ -840,6 +840,10 @@ To continue rebase after editing, run:
>  
>   exit
>   ;;
> +show-patch)
> + cmt="$(cat "$state_dir/stopped-sha")"
> + exec git format-patch --subject-prefix= --stdout "${cmt}^!"
> + ;;
>  esac
>  
>  comment_for_reflog start
> diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh
> index 06a4723d4d..5c513a9736 100644
> --- a/git-rebase--merge.sh
> +++ b/git-rebase--merge.sh
> @@ -137,6 +137,10 @@ skip)
>   finish_rb_merge
>   return
>   ;;
> +show-patch)
> + cmt="$(cat "$state_dir/current")"
> + exec git format-patch --subject-prefix= --stdout "${cmt}^!"
> + ;;
>  esac

Here and in the git-rebase--interactive you have access to the SHA of
the failed pick so you could run git log --patch and git colored output
and it would use the pager in the same way as 'git am --show-patch' does

Best Wishes

Phillip


Re: [PATCH 2/2] rebase: add --show-patch

2018-01-26 Thread Duy Nguyen
On Fri, Jan 26, 2018 at 6:12 PM, Phillip Wood  wrote:
>> diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh
>> index 06a4723d4d..5c513a9736 100644
>> --- a/git-rebase--merge.sh
>> +++ b/git-rebase--merge.sh
>> @@ -137,6 +137,10 @@ skip)
>>   finish_rb_merge
>>   return
>>   ;;
>> +show-patch)
>> + cmt="$(cat "$state_dir/current")"
>> + exec git format-patch --subject-prefix= --stdout "${cmt}^!"
>> + ;;
>>  esac
>
> Here and in the git-rebase--interactive you have access to the SHA of
> the failed pick so you could run git log --patch and git colored output

Yes. My first revision I actually did "git diff" here. The only
problem is inconsistency because we can't color "git am --show-patch"
the same way, the patch source is in text format, not in the repo. But
if people are ok with that I sure would switch to "git show".

> and it would use the pager in the same way as 'git am --show-patch' does

format-patch does set up pager. If it does not I would be very
annoyed. I added this for convenience after all.
-- 
Duy


Re: [PATCH 2/2] rebase: add --show-patch

2018-01-26 Thread Eric Sunshine
On Fri, Jan 26, 2018 at 4:55 AM, Nguyễn Thái Ngọc Duy  wrote:
> 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 [1] 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 
> ---
> diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
> @@ -840,6 +840,10 @@ To continue rebase after editing, run:
> +show-patch)
> +   cmt="$(cat "$state_dir/stopped-sha")"
> +   exec git format-patch --subject-prefix= --stdout "${cmt}^!"
> +   ;;

What is the behavior if a rebase (or conflicted rebase) is not in
progress? Stated differently, do we only make it this far if
$state_dir/stopped_sha exists?


Re: [PATCH 2/2] rebase: add --show-patch

2018-01-26 Thread Duy Nguyen
On Sat, Jan 27, 2018 at 2:11 AM, Eric Sunshine  wrote:
> On Fri, Jan 26, 2018 at 4:55 AM, Nguyễn Thái Ngọc Duy  
> wrote:
>> 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 [1] 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 
>> ---
>> diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
>> @@ -840,6 +840,10 @@ To continue rebase after editing, run:
>> +show-patch)
>> +   cmt="$(cat "$state_dir/stopped-sha")"
>> +   exec git format-patch --subject-prefix= --stdout "${cmt}^!"
>> +   ;;
>
> What is the behavior if a rebase (or conflicted rebase) is not in
> progress? Stated differently, do we only make it this far if
> $state_dir/stopped_sha exists?

It belongs to the same --continue/--skip/--abort group and won't reach
here unless a rebase is in progress (i.e. $state_dir exists).
-- 
Duy


Re: [PATCH 2/2] rebase: add --show-patch

2018-01-30 Thread Phillip Wood
On 26/01/18 11:22, Duy Nguyen wrote:
> On Fri, Jan 26, 2018 at 6:12 PM, Phillip Wood  
> wrote:
>>> diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh
>>> index 06a4723d4d..5c513a9736 100644
>>> --- a/git-rebase--merge.sh
>>> +++ b/git-rebase--merge.sh
>>> @@ -137,6 +137,10 @@ skip)
>>>   finish_rb_merge
>>>   return
>>>   ;;
>>> +show-patch)
>>> + cmt="$(cat "$state_dir/current")"
>>> + exec git format-patch --subject-prefix= --stdout "${cmt}^!"
>>> + ;;
>>>  esac
>>
>> Here and in the git-rebase--interactive you have access to the SHA of
>> the failed pick so you could run git log --patch and git colored output
> 
> Yes. My first revision I actually did "git diff" here. The only
> problem is inconsistency because we can't color "git am --show-patch"
> the same way, the patch source is in text format, not in the repo. But
> if people are ok with that I sure would switch to "git show".
> 
>> and it would use the pager in the same way as 'git am --show-patch' does
> 
> format-patch does set up pager. If it does not I would be very
> annoyed. I added this for convenience after all.
> 
Ah, I didn't realize that (now I come to think of it I've only ever used
--stdout to redirect the output). As my perceived lack of pager was the
main reason I suggested using log I'd ignore me.

I think the suggestion of having a ref for 'rebase -i' and 'rebase -m'
could be good as it'd be more flexible though I'm not sure what you'd do
about plain old rebase.

Best Wishes

Phillip