git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] rebase -r: always reword merge -c
@ 2019-04-26 10:33 Phillip Wood
  2019-04-29 16:14 ` Johannes Schindelin
  0 siblings, 1 reply; 8+ messages in thread
From: Phillip Wood @ 2019-04-26 10:33 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Johannes Schindelin, Junio C Hamano, Phillip Wood

From: Phillip Wood <phillip.wood@dunelm.org.uk>

If a merge can be fast-forwarded then make sure that we still edit the
commit message if the user specifies -c. The implementation follows the
same pattern that is used for ordinary rewords that are fast-forwarded.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 sequencer.c              |  5 +++++
 t/t3430-rebase-merges.sh | 10 ++++++++++
 2 files changed, 15 insertions(+)

diff --git a/sequencer.c b/sequencer.c
index 0db410d590..ff8565e7a8 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -3248,6 +3248,10 @@ static int do_merge(struct repository *r,
 		rollback_lock_file(&lock);
 		ret = fast_forward_to(r, &commit->object.oid,
 				      &head_commit->object.oid, 0, opts);
+		if (flags & TODO_EDIT_MERGE_MSG) {
+			run_commit_flags |= AMEND_MSG;
+			goto fast_forward_edit;
+		}
 		goto leave_merge;
 	}
 
@@ -3351,6 +3355,7 @@ static int do_merge(struct repository *r,
 		 * value (a negative one would indicate that the `merge`
 		 * command needs to be rescheduled).
 		 */
+	fast_forward_edit:
 		ret = !!run_git_commit(r, git_path_merge_msg(r), opts,
 				       run_commit_flags);
 
diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh
index 4c69255ee6..3d484a3c72 100755
--- a/t/t3430-rebase-merges.sh
+++ b/t/t3430-rebase-merges.sh
@@ -164,6 +164,16 @@ test_expect_success 'failed `merge <branch>` does not crash' '
 	grep "^Merge branch ${SQ}G${SQ}$" .git/rebase-merge/message
 '
 
+test_expect_success 'fast-forward merge -c still rewords' '
+	git checkout -b fast-forward-merge-c H &&
+	set_fake_editor &&
+	FAKE_COMMIT_MESSAGE=edited GIT_SEQUENCE_EDITOR="echo merge -c H G >" \
+		git rebase -ir @^ &&
+	echo edited >expected &&
+	git log --pretty=format:%B -1 >actual &&
+	test_cmp expected actual
+'
+
 test_expect_success 'with a branch tip that was cherry-picked already' '
 	git checkout -b already-upstream master &&
 	base="$(git rev-parse --verify HEAD)" &&
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] rebase -r: always reword merge -c
  2019-04-26 10:33 [PATCH] rebase -r: always reword merge -c Phillip Wood
@ 2019-04-29 16:14 ` Johannes Schindelin
  2019-04-30  9:01   ` Phillip Wood
  0 siblings, 1 reply; 8+ messages in thread
From: Johannes Schindelin @ 2019-04-29 16:14 UTC (permalink / raw)
  To: Phillip Wood; +Cc: Git Mailing List, Junio C Hamano

Hi Phillip,

On Fri, 26 Apr 2019, Phillip Wood wrote:

> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> If a merge can be fast-forwarded then make sure that we still edit the
> commit message if the user specifies -c. The implementation follows the
> same pattern that is used for ordinary rewords that are fast-forwarded.
>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---

OMG I was bitten twice by this very bug in the past week, and planned on
looking into it next week. Thanks for beating me to it.

Two comments:

> diff --git a/sequencer.c b/sequencer.c
> index 0db410d590..ff8565e7a8 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -3248,6 +3248,10 @@ static int do_merge(struct repository *r,
>  		rollback_lock_file(&lock);
>  		ret = fast_forward_to(r, &commit->object.oid,
>  				      &head_commit->object.oid, 0, opts);
> +		if (flags & TODO_EDIT_MERGE_MSG) {
> +			run_commit_flags |= AMEND_MSG;
> +			goto fast_forward_edit;
> +		}
>  		goto leave_merge;
>  	}
>
> @@ -3351,6 +3355,7 @@ static int do_merge(struct repository *r,
>  		 * value (a negative one would indicate that the `merge`
>  		 * command needs to be rescheduled).
>  		 */
> +	fast_forward_edit:

It is *slightly* awkward that this is an `else` arm of an `if (ret)`, but
I do not necessarily think that it would be better to move the label
before the `if` than what you did; Your version comes out more readable,
still.

>  		ret = !!run_git_commit(r, git_path_merge_msg(r), opts,
>  				       run_commit_flags);
>
> diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh
> index 4c69255ee6..3d484a3c72 100755
> --- a/t/t3430-rebase-merges.sh
> +++ b/t/t3430-rebase-merges.sh
> @@ -164,6 +164,16 @@ test_expect_success 'failed `merge <branch>` does not crash' '
>  	grep "^Merge branch ${SQ}G${SQ}$" .git/rebase-merge/message
>  '
>
> +test_expect_success 'fast-forward merge -c still rewords' '
> +	git checkout -b fast-forward-merge-c H &&
> +	set_fake_editor &&

set_fake_editor affects global state AFAIR (setting and exporting
`EDITOR`), therefore this would need to be run in a subshell, i.e.
enclosed in parentheses.

> +	FAKE_COMMIT_MESSAGE=edited GIT_SEQUENCE_EDITOR="echo merge -c H G >" \
> +		git rebase -ir @^ &&
> +	echo edited >expected &&
> +	git log --pretty=format:%B -1 >actual &&
> +	test_cmp expected actual
> +'
> +

The rest looks good, thank you!
Dscho

>  test_expect_success 'with a branch tip that was cherry-picked already' '
>  	git checkout -b already-upstream master &&
>  	base="$(git rev-parse --verify HEAD)" &&
> --
> 2.21.0
>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] rebase -r: always reword merge -c
  2019-04-29 16:14 ` Johannes Schindelin
@ 2019-04-30  9:01   ` Phillip Wood
  2019-04-30 22:51     ` Johannes Schindelin
  2019-05-02 10:22     ` [PATCH v2] " Phillip Wood
  0 siblings, 2 replies; 8+ messages in thread
From: Phillip Wood @ 2019-04-30  9:01 UTC (permalink / raw)
  To: Johannes Schindelin, Phillip Wood; +Cc: Git Mailing List, Junio C Hamano

Hi Dscho

On 29/04/2019 17:14, Johannes Schindelin wrote:
> Hi Phillip,
> 
> On Fri, 26 Apr 2019, Phillip Wood wrote:
> 
>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>>
>> If a merge can be fast-forwarded then make sure that we still edit the
>> commit message if the user specifies -c. The implementation follows the
>> same pattern that is used for ordinary rewords that are fast-forwarded.
>>
>> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
>> ---
> 
> OMG I was bitten twice by this very bug in the past week, and planned on
> looking into it next week. Thanks for beating me to it.
> 
> Two comments:
> 
>> diff --git a/sequencer.c b/sequencer.c
>> index 0db410d590..ff8565e7a8 100644
>> --- a/sequencer.c
>> +++ b/sequencer.c
>> @@ -3248,6 +3248,10 @@ static int do_merge(struct repository *r,
>>   		rollback_lock_file(&lock);
>>   		ret = fast_forward_to(r, &commit->object.oid,
>>   				      &head_commit->object.oid, 0, opts);
>> +		if (flags & TODO_EDIT_MERGE_MSG) {
>> +			run_commit_flags |= AMEND_MSG;
>> +			goto fast_forward_edit;
>> +		}
>>   		goto leave_merge;
>>   	}
>>
>> @@ -3351,6 +3355,7 @@ static int do_merge(struct repository *r,
>>   		 * value (a negative one would indicate that the `merge`
>>   		 * command needs to be rescheduled).
>>   		 */
>> +	fast_forward_edit:
> 
> It is *slightly* awkward that this is an `else` arm of an `if (ret)`, but
> I do not necessarily think that it would be better to move the label
> before the `if` than what you did; Your version comes out more readable,
> still.

I did wonder about adding braces but I'm not sure that makes it any 
clearer. I agree having the label before the `if (ret)` would be less 
clear as the reader has to then think what ret will be in that case to 
work out what will happen.

>>   		ret = !!run_git_commit(r, git_path_merge_msg(r), opts,
>>   				       run_commit_flags);
>>
>> diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh
>> index 4c69255ee6..3d484a3c72 100755
>> --- a/t/t3430-rebase-merges.sh
>> +++ b/t/t3430-rebase-merges.sh
>> @@ -164,6 +164,16 @@ test_expect_success 'failed `merge <branch>` does not crash' '
>>   	grep "^Merge branch ${SQ}G${SQ}$" .git/rebase-merge/message
>>   '
>>
>> +test_expect_success 'fast-forward merge -c still rewords' '
>> +	git checkout -b fast-forward-merge-c H &&
>> +	set_fake_editor &&
> 
> set_fake_editor affects global state AFAIR (setting and exporting
> `EDITOR`), therefore this would need to be run in a subshell, i.e.
> enclosed in parentheses.

The other test files are not very consistent about that. I'll re-roll. 
Note that I do not export any FAKE_* variables, so later tests should 
not be affected even if the fake editor runs.

Best Wishes

Phillip
>> +	FAKE_COMMIT_MESSAGE=edited GIT_SEQUENCE_EDITOR="echo merge -c H G >" \
>> +		git rebase -ir @^ &&
>> +	echo edited >expected &&
>> +	git log --pretty=format:%B -1 >actual &&
>> +	test_cmp expected actual
>> +'
>> +
> 
> The rest looks good, thank you!
> Dscho
> 
>>   test_expect_success 'with a branch tip that was cherry-picked already' '
>>   	git checkout -b already-upstream master &&
>>   	base="$(git rev-parse --verify HEAD)" &&
>> --
>> 2.21.0
>>
>>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] rebase -r: always reword merge -c
  2019-04-30  9:01   ` Phillip Wood
@ 2019-04-30 22:51     ` Johannes Schindelin
  2019-05-02 10:22     ` [PATCH v2] " Phillip Wood
  1 sibling, 0 replies; 8+ messages in thread
From: Johannes Schindelin @ 2019-04-30 22:51 UTC (permalink / raw)
  To: Phillip Wood; +Cc: Git Mailing List, Junio C Hamano

Hi Phillip,

On Tue, 30 Apr 2019, Phillip Wood wrote:

> On 29/04/2019 17:14, Johannes Schindelin wrote:
> > Hi Phillip,
> >
> > On Fri, 26 Apr 2019, Phillip Wood wrote:
> >
> > >     ret = !!run_git_commit(r, git_path_merge_msg(r), opts,
> > >              run_commit_flags);
> > >
> > > diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh
> > > index 4c69255ee6..3d484a3c72 100755
> > > --- a/t/t3430-rebase-merges.sh
> > > +++ b/t/t3430-rebase-merges.sh
> > > @@ -164,6 +164,16 @@ test_expect_success 'failed `merge <branch>` does not
> > > crash' '
> > >   	grep "^Merge branch ${SQ}G${SQ}$" .git/rebase-merge/message
> > >   '
> > >
> > > +test_expect_success 'fast-forward merge -c still rewords' '
> > > +	git checkout -b fast-forward-merge-c H &&
> > > +	set_fake_editor &&
> >
> > set_fake_editor affects global state AFAIR (setting and exporting
> > `EDITOR`), therefore this would need to be run in a subshell, i.e.
> > enclosed in parentheses.
>
> The other test files are not very consistent about that. I'll re-roll. Note
> that I do not export any FAKE_* variables, so later tests should not be
> affected even if the fake editor runs.

AFAIR I tried my best to avoid `set_fake_editor` altogether and instead
preferred `write_script`/`test_config core.editor` combos in t3430.

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2] rebase -r: always reword merge -c
  2019-04-30  9:01   ` Phillip Wood
  2019-04-30 22:51     ` Johannes Schindelin
@ 2019-05-02 10:22     ` Phillip Wood
  2019-05-03  9:23       ` Johannes Schindelin
  2019-05-17  6:56       ` Johannes Schindelin
  1 sibling, 2 replies; 8+ messages in thread
From: Phillip Wood @ 2019-05-02 10:22 UTC (permalink / raw)
  To: Git Mailing List, Johannes Schindelin; +Cc: Junio C Hamano, Phillip Wood

From: Phillip Wood <phillip.wood@dunelm.org.uk>

If a merge can be fast-forwarded then make sure that we still edit the
commit message if the user specifies -c. The implementation follows the
same pattern that is used for ordinary rewords that are fast-forwarded.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
Thanks to Dscho for his comments on v1, I've changed the test as he suggested.

Range-diff:
1:  0532b70644 ! 1:  738799241a rebase -r: always reword merge -c
    @@ -40,9 +40,12 @@
      
     +test_expect_success 'fast-forward merge -c still rewords' '
     +  git checkout -b fast-forward-merge-c H &&
    -+  set_fake_editor &&
    -+  FAKE_COMMIT_MESSAGE=edited GIT_SEQUENCE_EDITOR="echo merge -c H G >" \
    -+          git rebase -ir @^ &&
    ++  (
    ++          set_fake_editor &&
    ++          FAKE_COMMIT_MESSAGE=edited \
    ++                  GIT_SEQUENCE_EDITOR="echo merge -c H G >" \
    ++                  git rebase -ir @^
    ++  ) &&
     +  echo edited >expected &&
     +  git log --pretty=format:%B -1 >actual &&
     +  test_cmp expected actual

 sequencer.c              |  5 +++++
 t/t3430-rebase-merges.sh | 13 +++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/sequencer.c b/sequencer.c
index 0db410d590..ff8565e7a8 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -3248,6 +3248,10 @@ static int do_merge(struct repository *r,
 		rollback_lock_file(&lock);
 		ret = fast_forward_to(r, &commit->object.oid,
 				      &head_commit->object.oid, 0, opts);
+		if (flags & TODO_EDIT_MERGE_MSG) {
+			run_commit_flags |= AMEND_MSG;
+			goto fast_forward_edit;
+		}
 		goto leave_merge;
 	}
 
@@ -3351,6 +3355,7 @@ static int do_merge(struct repository *r,
 		 * value (a negative one would indicate that the `merge`
 		 * command needs to be rescheduled).
 		 */
+	fast_forward_edit:
 		ret = !!run_git_commit(r, git_path_merge_msg(r), opts,
 				       run_commit_flags);
 
diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh
index 4c69255ee6..01238d4b6e 100755
--- a/t/t3430-rebase-merges.sh
+++ b/t/t3430-rebase-merges.sh
@@ -164,6 +164,19 @@ test_expect_success 'failed `merge <branch>` does not crash' '
 	grep "^Merge branch ${SQ}G${SQ}$" .git/rebase-merge/message
 '
 
+test_expect_success 'fast-forward merge -c still rewords' '
+	git checkout -b fast-forward-merge-c H &&
+	(
+		set_fake_editor &&
+		FAKE_COMMIT_MESSAGE=edited \
+			GIT_SEQUENCE_EDITOR="echo merge -c H G >" \
+			git rebase -ir @^
+	) &&
+	echo edited >expected &&
+	git log --pretty=format:%B -1 >actual &&
+	test_cmp expected actual
+'
+
 test_expect_success 'with a branch tip that was cherry-picked already' '
 	git checkout -b already-upstream master &&
 	base="$(git rev-parse --verify HEAD)" &&
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] rebase -r: always reword merge -c
  2019-05-02 10:22     ` [PATCH v2] " Phillip Wood
@ 2019-05-03  9:23       ` Johannes Schindelin
  2019-05-17  6:56       ` Johannes Schindelin
  1 sibling, 0 replies; 8+ messages in thread
From: Johannes Schindelin @ 2019-05-03  9:23 UTC (permalink / raw)
  To: Phillip Wood; +Cc: Git Mailing List, Junio C Hamano

Hi Phillip,

On Thu, 2 May 2019, Phillip Wood wrote:

> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> If a merge can be fast-forwarded then make sure that we still edit the
> commit message if the user specifies -c. The implementation follows the
> same pattern that is used for ordinary rewords that are fast-forwarded.
>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---

ACK!

Thank you,
Dscho

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] rebase -r: always reword merge -c
  2019-05-02 10:22     ` [PATCH v2] " Phillip Wood
  2019-05-03  9:23       ` Johannes Schindelin
@ 2019-05-17  6:56       ` Johannes Schindelin
  2019-05-19  1:32         ` Junio C Hamano
  1 sibling, 1 reply; 8+ messages in thread
From: Johannes Schindelin @ 2019-05-17  6:56 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Phillip Wood, Git Mailing List

Hi Junio,

I think this one fell through the cracks (at least I failed to find it in
`pu`), but I deem it a bug fix worthy of including in v2.22.0.

Ciao,
Dscho


On Thu, 2 May 2019, Phillip Wood wrote:

> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> If a merge can be fast-forwarded then make sure that we still edit the
> commit message if the user specifies -c. The implementation follows the
> same pattern that is used for ordinary rewords that are fast-forwarded.
>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
> Thanks to Dscho for his comments on v1, I've changed the test as he suggested.
>
> Range-diff:
> 1:  0532b70644 ! 1:  738799241a rebase -r: always reword merge -c
>     @@ -40,9 +40,12 @@
>
>      +test_expect_success 'fast-forward merge -c still rewords' '
>      +  git checkout -b fast-forward-merge-c H &&
>     -+  set_fake_editor &&
>     -+  FAKE_COMMIT_MESSAGE=edited GIT_SEQUENCE_EDITOR="echo merge -c H G >" \
>     -+          git rebase -ir @^ &&
>     ++  (
>     ++          set_fake_editor &&
>     ++          FAKE_COMMIT_MESSAGE=edited \
>     ++                  GIT_SEQUENCE_EDITOR="echo merge -c H G >" \
>     ++                  git rebase -ir @^
>     ++  ) &&
>      +  echo edited >expected &&
>      +  git log --pretty=format:%B -1 >actual &&
>      +  test_cmp expected actual
>
>  sequencer.c              |  5 +++++
>  t/t3430-rebase-merges.sh | 13 +++++++++++++
>  2 files changed, 18 insertions(+)
>
> diff --git a/sequencer.c b/sequencer.c
> index 0db410d590..ff8565e7a8 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -3248,6 +3248,10 @@ static int do_merge(struct repository *r,
>  		rollback_lock_file(&lock);
>  		ret = fast_forward_to(r, &commit->object.oid,
>  				      &head_commit->object.oid, 0, opts);
> +		if (flags & TODO_EDIT_MERGE_MSG) {
> +			run_commit_flags |= AMEND_MSG;
> +			goto fast_forward_edit;
> +		}
>  		goto leave_merge;
>  	}
>
> @@ -3351,6 +3355,7 @@ static int do_merge(struct repository *r,
>  		 * value (a negative one would indicate that the `merge`
>  		 * command needs to be rescheduled).
>  		 */
> +	fast_forward_edit:
>  		ret = !!run_git_commit(r, git_path_merge_msg(r), opts,
>  				       run_commit_flags);
>
> diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh
> index 4c69255ee6..01238d4b6e 100755
> --- a/t/t3430-rebase-merges.sh
> +++ b/t/t3430-rebase-merges.sh
> @@ -164,6 +164,19 @@ test_expect_success 'failed `merge <branch>` does not crash' '
>  	grep "^Merge branch ${SQ}G${SQ}$" .git/rebase-merge/message
>  '
>
> +test_expect_success 'fast-forward merge -c still rewords' '
> +	git checkout -b fast-forward-merge-c H &&
> +	(
> +		set_fake_editor &&
> +		FAKE_COMMIT_MESSAGE=edited \
> +			GIT_SEQUENCE_EDITOR="echo merge -c H G >" \
> +			git rebase -ir @^
> +	) &&
> +	echo edited >expected &&
> +	git log --pretty=format:%B -1 >actual &&
> +	test_cmp expected actual
> +'
> +
>  test_expect_success 'with a branch tip that was cherry-picked already' '
>  	git checkout -b already-upstream master &&
>  	base="$(git rev-parse --verify HEAD)" &&
> --
> 2.21.0
>
>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] rebase -r: always reword merge -c
  2019-05-17  6:56       ` Johannes Schindelin
@ 2019-05-19  1:32         ` Junio C Hamano
  0 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2019-05-19  1:32 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Phillip Wood, Git Mailing List

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> I think this one fell through the cracks (at least I failed to find it in
> `pu`),

Thanks, I think I was waiting for an Ack or two, but then the thread
was buried.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-05-19  1:32 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-26 10:33 [PATCH] rebase -r: always reword merge -c Phillip Wood
2019-04-29 16:14 ` Johannes Schindelin
2019-04-30  9:01   ` Phillip Wood
2019-04-30 22:51     ` Johannes Schindelin
2019-05-02 10:22     ` [PATCH v2] " Phillip Wood
2019-05-03  9:23       ` Johannes Schindelin
2019-05-17  6:56       ` Johannes Schindelin
2019-05-19  1:32         ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).