threads / patch / 52471

patch[Outreachy] commit: display advice hints when commit fails

Subject: [PATCH 0/1] [Outreachy] commit: display advice hints when commit fails

## tl;dr

27 messages between Dec 17, 2019 and Jan 2, 2020. Diffs are folded; open one to read it.

replies: 26people: 5as markdown or json

Heba Waly via GitGitGadget· Dec 17, 2019, 09:17 UTC · lore

Display hints to the user when trying to commit without staging the modified files first (when advice.statusHints is set to true). Change the output of the unsuccessful commit from e.g:

[...] =====

Changes not staged for commit: ==============================

modified: builtin/commit.c ==========================

 #

no changes added to commit ==========================

to:

[...] =====

Changes not staged for commit: ==============================

(use "git add ..." to update what will be committed) ====================================================

(use "git checkout -- ..." to discard changes in working directory) ===================================================================

 #

modified: ../builtin/commit.c =============================

 #

no changes added to commit (use "git add" and/or "git commit -a") =================================================================

In ea9882bfc4 (commit: disable status hints when writing to COMMIT_EDITMSG, 2013-09-12) the intent was to disable status hints when writing to COMMIT_EDITMSG, but in fact the implementation disabled status messages in more locations, e.g in case the commit wasn't successful, status hints will still be disabled and no hints will be displayed to the user although advice.statusHints is set to true.

Signed-off-by: Heba Waly heba.waly@gmail.com [heba.waly@gmail.com]
Heba Waly (1):
  commit: display advice hints when commit fails
 builtin/commit.c                          | 1 +
 t/t7500-commit-template-squash-signoff.sh | 9 +++++++++
 2 files changed, 10 insertions(+)
base-commit: ad05a3d8e5a6a06443836b5e40434262d992889a
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-495%2FHebaWaly%2Fhints-for-unsuccessful-commit-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-495/HebaWaly/hints-for-unsuccessful-commit-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/495
-- 
gitgitgadget
Heba Waly via GitGitGadget· Dec 17, 2019, 09:17 UTC · re: Heba Waly via GitGitGadget · lore

[PATCH 1/1] commit: display advice hints when commit fails

From: Heba Waly <heba.waly@gmail.com>

Display hints to the user when trying to commit without staging the modified files first (when advice.statusHints is set to true). Change the output of the unsuccessful commit from e.g:

  # [...]
  # Changes not staged for commit:
  #   modified:   builtin/commit.c
  #
  # no changes added to commit
to:
  # [...]
  # Changes not staged for commit:
  #   (use "git add <file>..." to update what will be committed)
  #   (use "git checkout -- <file>..." to discard changes in working directory)
  #
  #   modified:   ../builtin/commit.c
  #
  # no changes added to commit (use "git add" and/or "git commit -a")

In ea9882bfc4 (commit: disable status hints when writing to COMMIT_EDITMSG, 2013-09-12) the intent was to disable status hints when writing to COMMIT_EDITMSG, but in fact the implementation disabled status messages in more locations, e.g in case the commit wasn't successful, status hints will still be disabled and no hints will be displayed to the user although advice.statusHints is set to true.

Signed-off-by: Heba Waly <heba.waly@gmail.com>
---
 builtin/commit.c                          | 1 +
 t/t7500-commit-template-squash-signoff.sh | 9 +++++++++
 2 files changed, 10 insertions(+)
Show changes to 2 files +10 −0

builtin/commit.c, t/t7500-commit-template-squash-signoff.sh

diff --git a/builtin/commit.c b/builtin/commit.c
index 2db2ad0de4..4439666465 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -961,6 +961,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 	 */
 	if (!committable && whence != FROM_MERGE && !allow_empty &&
 	    !(amend && is_a_merge(current_head))) {
+		s->hints = advice_status_hints;
 		s->display_comment_prefix = old_display_comment_prefix;
 		run_status(stdout, index_file, prefix, 0, s);
 		if (amend)
diff --git a/t/t7500-commit-template-squash-signoff.sh b/t/t7500-commit-template-squash-signoff.sh
index 46a5cd4b73..3d76e8ebbd 100755
--- a/t/t7500-commit-template-squash-signoff.sh
+++ b/t/t7500-commit-template-squash-signoff.sh
@@ -382,4 +382,13 @@ test_expect_success 'check commit with unstaged rename and copy' '
 	)
 '
 
+test_expect_success 'commit without staging files fails and displays hints' '
+	echo "initial" >>file &&
+	git add file &&
+	git commit -m initial &&
+	echo "changes" >>file &&
+	test_must_fail git commit -m initial >actual &&
+	test_i18ngrep "no changes added to commit (use \"git add\" and/or \"git commit -a\")" actual
+'
+
 test_done
-- 
gitgitgadget
Junio C Hamano· Dec 17, 2019, 22:41 UTC · re: Heba Waly via GitGitGadget · lore

Re: [PATCH 1/1] commit: display advice hints when commit fails

"Heba Waly via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 12 quoted lines
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 2db2ad0de4..4439666465 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -961,6 +961,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>  	 */
>  	if (!committable && whence != FROM_MERGE && !allow_empty &&
>  	    !(amend && is_a_merge(current_head))) {
> +		s->hints = advice_status_hints;
>  		s->display_comment_prefix = old_display_comment_prefix;
>  		run_status(stdout, index_file, prefix, 0, s);
>  		if (amend)

It almost tempts me to say why this is not done inside run_status(), which has other callers, but I think the answer is because we do not want these hints when we are actually committing (iow, the ongoing commit must be aborted before the user can actually say "git add" etc. that are suggested).

So the change makes sense to me.
Will queue.
Show 18 quoted lines
> diff --git a/t/t7500-commit-template-squash-signoff.sh b/t/t7500-commit-template-squash-signoff.sh
> index 46a5cd4b73..3d76e8ebbd 100755
> --- a/t/t7500-commit-template-squash-signoff.sh
> +++ b/t/t7500-commit-template-squash-signoff.sh
> @@ -382,4 +382,13 @@ test_expect_success 'check commit with unstaged rename and copy' '
>  	)
>  '
>  
> +test_expect_success 'commit without staging files fails and displays hints' '
> +	echo "initial" >>file &&
> +	git add file &&
> +	git commit -m initial &&
> +	echo "changes" >>file &&
> +	test_must_fail git commit -m initial >actual &&
> +	test_i18ngrep "no changes added to commit (use \"git add\" and/or \"git commit -a\")" actual
> +'
> +
>  test_done
Emily Shaffer· Dec 17, 2019, 22:45 UTC · re: Heba Waly via GitGitGadget · lore

Re: [PATCH 1/1] commit: display advice hints when commit fails

On Tue, Dec 17, 2019 at 09:17:22AM +0000, Heba Waly via GitGitGadget wrote:
Show 45 quoted lines
> From: Heba Waly <heba.waly@gmail.com>
> 
> Display hints to the user when trying to commit without staging the modified
> files first (when advice.statusHints is set to true). Change the output of the
> unsuccessful commit from e.g:
> 
>   # [...]
>   # Changes not staged for commit:
>   #   modified:   builtin/commit.c
>   #
>   # no changes added to commit
> 
> to:
> 
>   # [...]
>   # Changes not staged for commit:
>   #   (use "git add <file>..." to update what will be committed)
>   #   (use "git checkout -- <file>..." to discard changes in working directory)
>   #
>   #   modified:   ../builtin/commit.c
>   #
>   # no changes added to commit (use "git add" and/or "git commit -a")
> 
> In ea9882bfc4 (commit: disable status hints when writing to COMMIT_EDITMSG,
> 2013-09-12) the intent was to disable status hints when writing to
> COMMIT_EDITMSG, but in fact the implementation disabled status messages in
> more locations, e.g in case the commit wasn't successful, status hints
> will still be disabled and no hints will be displayed to the user although
> advice.statusHints is set to true.
> 
> Signed-off-by: Heba Waly <heba.waly@gmail.com>
> ---
>  builtin/commit.c                          | 1 +
>  t/t7500-commit-template-squash-signoff.sh | 9 +++++++++
>  2 files changed, 10 insertions(+)
> 
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 2db2ad0de4..4439666465 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -961,6 +961,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>  	 */
>  	if (!committable && whence != FROM_MERGE && !allow_empty &&
>  	    !(amend && is_a_merge(current_head))) {
> +		s->hints = advice_status_hints;

Hm. This looks like it turns hints back on specifically for this case, but might not fix other places where ea9882bfc4 turned them off.

I think the intent of that commit was to not put hints into the editor, so does it make sense to instead wrap this guy:

  /*                                                                       
   * Most hints are counter-productive when the commit has                 
   * already started.                                                      
   */                                                                      
  s->hints = 0;  
in "if (use_editor)"?

I didn't try it on my end. Maybe it won't help much, because we think we're going to use the editor right up until we realize it's not committable?

I wonder which other cases that commit got rid of hints for by accident.
 - Emily
Show 23 quoted lines
>  		s->display_comment_prefix = old_display_comment_prefix;
>  		run_status(stdout, index_file, prefix, 0, s);
>  		if (amend)
> diff --git a/t/t7500-commit-template-squash-signoff.sh b/t/t7500-commit-template-squash-signoff.sh
> index 46a5cd4b73..3d76e8ebbd 100755
> --- a/t/t7500-commit-template-squash-signoff.sh
> +++ b/t/t7500-commit-template-squash-signoff.sh
> @@ -382,4 +382,13 @@ test_expect_success 'check commit with unstaged rename and copy' '
>  	)
>  '
>  
> +test_expect_success 'commit without staging files fails and displays hints' '
> +	echo "initial" >>file &&
> +	git add file &&
> +	git commit -m initial &&
> +	echo "changes" >>file &&
> +	test_must_fail git commit -m initial >actual &&
> +	test_i18ngrep "no changes added to commit (use \"git add\" and/or \"git commit -a\")" actual
> +'
> +
>  test_done
> -- 
> gitgitgadget
Heba Waly· Dec 19, 2019, 03:47 UTC · re: Emily Shaffer · lore

Re: [PATCH 1/1] commit: display advice hints when commit fails

On Wed, Dec 18, 2019 at 11:45 AM Emily Shaffer <emilyshaffer@google.com> wrote:
Show 62 quoted lines
>
> On Tue, Dec 17, 2019 at 09:17:22AM +0000, Heba Waly via GitGitGadget wrote:
> > From: Heba Waly <heba.waly@gmail.com>
> >
> > Display hints to the user when trying to commit without staging the modified
> > files first (when advice.statusHints is set to true). Change the output of the
> > unsuccessful commit from e.g:
> >
> >   # [...]
> >   # Changes not staged for commit:
> >   #   modified:   builtin/commit.c
> >   #
> >   # no changes added to commit
> >
> > to:
> >
> >   # [...]
> >   # Changes not staged for commit:
> >   #   (use "git add <file>..." to update what will be committed)
> >   #   (use "git checkout -- <file>..." to discard changes in working directory)
> >   #
> >   #   modified:   ../builtin/commit.c
> >   #
> >   # no changes added to commit (use "git add" and/or "git commit -a")
> >
> > In ea9882bfc4 (commit: disable status hints when writing to COMMIT_EDITMSG,
> > 2013-09-12) the intent was to disable status hints when writing to
> > COMMIT_EDITMSG, but in fact the implementation disabled status messages in
> > more locations, e.g in case the commit wasn't successful, status hints
> > will still be disabled and no hints will be displayed to the user although
> > advice.statusHints is set to true.
> >
> > Signed-off-by: Heba Waly <heba.waly@gmail.com>
> > ---
> >  builtin/commit.c                          | 1 +
> >  t/t7500-commit-template-squash-signoff.sh | 9 +++++++++
> >  2 files changed, 10 insertions(+)
> >
> > diff --git a/builtin/commit.c b/builtin/commit.c
> > index 2db2ad0de4..4439666465 100644
> > --- a/builtin/commit.c
> > +++ b/builtin/commit.c
> > @@ -961,6 +961,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
> >        */
> >       if (!committable && whence != FROM_MERGE && !allow_empty &&
> >           !(amend && is_a_merge(current_head))) {
> > +             s->hints = advice_status_hints;
>
> Hm. This looks like it turns hints back on specifically for this case,
> but might not fix other places where ea9882bfc4 turned them off.
>
> I think the intent of that commit was to not put hints into the editor,
> so does it make sense to instead wrap this guy:
>
>   /*
>    * Most hints are counter-productive when the commit has
>    * already started.
>    */
>   s->hints = 0;
>
> in "if (use_editor)"?
>
That's a good idea, I tried it and it seems to be working fine.
Show 6 quoted lines
> I didn't try it on my end. Maybe it won't help much, because we think
> we're going to use the editor right up until we realize it's not
> committable?
>
> I wonder which other cases that commit got rid of hints for by accident.
>

The number of cases is quite overwhelming because of all the options that can be passed to the commit command, but hopefully after wrapping it in an if condition as you suggested we'll be more certain of the affected cases. Will send an update shortly.

Show 25 quoted lines
>  - Emily
>
> >               s->display_comment_prefix = old_display_comment_prefix;
> >               run_status(stdout, index_file, prefix, 0, s);
> >               if (amend)
> > diff --git a/t/t7500-commit-template-squash-signoff.sh b/t/t7500-commit-template-squash-signoff.sh
> > index 46a5cd4b73..3d76e8ebbd 100755
> > --- a/t/t7500-commit-template-squash-signoff.sh
> > +++ b/t/t7500-commit-template-squash-signoff.sh
> > @@ -382,4 +382,13 @@ test_expect_success 'check commit with unstaged rename and copy' '
> >       )
> >  '
> >
> > +test_expect_success 'commit without staging files fails and displays hints' '
> > +     echo "initial" >>file &&
> > +     git add file &&
> > +     git commit -m initial &&
> > +     echo "changes" >>file &&
> > +     test_must_fail git commit -m initial >actual &&
> > +     test_i18ngrep "no changes added to commit (use \"git add\" and/or \"git commit -a\")" actual
> > +'
> > +
> >  test_done
> > --
> > gitgitgadget
Thanks,
Heba
Jonathan Tan· Dec 18, 2019, 03:13 UTC · re: Heba Waly via GitGitGadget · lore

Re: [PATCH 1/1] commit: display advice hints when commit fails

Show 5 quoted lines
> From: Heba Waly <heba.waly@gmail.com>
> 
> Display hints to the user when trying to commit without staging the modified
> files first (when advice.statusHints is set to true). Change the output of the
> unsuccessful commit from e.g:
Wrap your commit messages at 72 characters.
Show 14 quoted lines
>   # [...]
>   # Changes not staged for commit:
>   #   modified:   builtin/commit.c
>   #
>   # no changes added to commit
> 
> to:
> 
>   # [...]
>   # Changes not staged for commit:
>   #   (use "git add <file>..." to update what will be committed)
>   #   (use "git checkout -- <file>..." to discard changes in working directory)
>   #
>   #   modified:   ../builtin/commit.c

For tidiness, can this line also be "builtin/commit.c" (that is, without the "../" at the beginning) to match what's before "to:"?

Show 11 quoted lines
> In ea9882bfc4 (commit: disable status hints when writing to COMMIT_EDITMSG,
> 2013-09-12) the intent was to disable status hints when writing to
> COMMIT_EDITMSG, but in fact the implementation disabled status messages in
> more locations, e.g in case the commit wasn't successful, status hints
> will still be disabled and no hints will be displayed to the user although
> advice.statusHints is set to true.
> 
> Signed-off-by: Heba Waly <heba.waly@gmail.com>
> ---
>  builtin/commit.c                          | 1 +
>  t/t7500-commit-template-squash-signoff.sh | 9 +++++++++

I wondered if there was a better place to put the test, but I couldn't find one, so this is fine.

Show 8 quoted lines
> @@ -961,6 +961,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>  	 */
>  	if (!committable && whence != FROM_MERGE && !allow_empty &&
>  	    !(amend && is_a_merge(current_head))) {
> +		s->hints = advice_status_hints;
>  		s->display_comment_prefix = old_display_comment_prefix;
>  		run_status(stdout, index_file, prefix, 0, s);
>  		if (amend)

I checked that this undoing of "s->hints = 0" is safe, because s is no longer used in this function nor in the calling function cmd_commit() (which is the one that declared s locally).

Still probably worth a comment, though. For example:
  This status is to be printed to stdout, so hints will be useful to the
  user. Reset s->hints to what the user configured.

The corresponding comment on "s->hints = 0" might need to be tweaked, too, but I can't think of anything at the moment.

Show 6 quoted lines
> +test_expect_success 'commit without staging files fails and displays hints' '
> +	echo "initial" >>file &&
> +	git add file &&
> +	git commit -m initial &&
> +	echo "changes" >>file &&
> +	test_must_fail git commit -m initial >actual &&

Use another commit message for this, since this is no longer "initial". (Maybe "after initial" or something like that.)

Junio C Hamano· Dec 18, 2019, 18:14 UTC · re: Jonathan Tan · lore

Re: [PATCH 1/1] commit: display advice hints when commit fails

Jonathan Tan <jonathantanmy@google.com> writes:
Show 71 quoted lines
>> From: Heba Waly <heba.waly@gmail.com>
>> 
>> Display hints to the user when trying to commit without staging the modified
>> files first (when advice.statusHints is set to true). Change the output of the
>> unsuccessful commit from e.g:
>
> Wrap your commit messages at 72 characters.
>
>>   # [...]
>>   # Changes not staged for commit:
>>   #   modified:   builtin/commit.c
>>   #
>>   # no changes added to commit
>> 
>> to:
>> 
>>   # [...]
>>   # Changes not staged for commit:
>>   #   (use "git add <file>..." to update what will be committed)
>>   #   (use "git checkout -- <file>..." to discard changes in working directory)
>>   #
>>   #   modified:   ../builtin/commit.c
>
> For tidiness, can this line also be "builtin/commit.c" (that is, without
> the "../" at the beginning) to match what's before "to:"?
>
>> In ea9882bfc4 (commit: disable status hints when writing to COMMIT_EDITMSG,
>> 2013-09-12) the intent was to disable status hints when writing to
>> COMMIT_EDITMSG, but in fact the implementation disabled status messages in
>> more locations, e.g in case the commit wasn't successful, status hints
>> will still be disabled and no hints will be displayed to the user although
>> advice.statusHints is set to true.
>> 
>> Signed-off-by: Heba Waly <heba.waly@gmail.com>
>> ---
>>  builtin/commit.c                          | 1 +
>>  t/t7500-commit-template-squash-signoff.sh | 9 +++++++++
>
> I wondered if there was a better place to put the test, but I couldn't
> find one, so this is fine.
>
>> @@ -961,6 +961,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>>  	 */
>>  	if (!committable && whence != FROM_MERGE && !allow_empty &&
>>  	    !(amend && is_a_merge(current_head))) {
>> +		s->hints = advice_status_hints;
>>  		s->display_comment_prefix = old_display_comment_prefix;
>>  		run_status(stdout, index_file, prefix, 0, s);
>>  		if (amend)
>
> I checked that this undoing of "s->hints = 0" is safe, because s is no
> longer used in this function nor in the calling function cmd_commit()
> (which is the one that declared s locally).
>
> Still probably worth a comment, though. For example:
>
>   This status is to be printed to stdout, so hints will be useful to the
>   user. Reset s->hints to what the user configured.
>
> The corresponding comment on "s->hints = 0" might need to be tweaked,
> too, but I can't think of anything at the moment.
>
>> +test_expect_success 'commit without staging files fails and displays hints' '
>> +	echo "initial" >>file &&
>> +	git add file &&
>> +	git commit -m initial &&
>> +	echo "changes" >>file &&
>> +	test_must_fail git commit -m initial >actual &&
>
> Use another commit message for this, since this is no longer "initial".
> (Maybe "after initial" or something like that.)
Thanks for a careful review.
Heba Waly· Dec 19, 2019, 03:48 UTC · re: Jonathan Tan · lore

Re: [PATCH 1/1] commit: display advice hints when commit fails

On Wed, Dec 18, 2019 at 4:13 PM Jonathan Tan <jonathantanmy@google.com> wrote:
Show 9 quoted lines
>
> > From: Heba Waly <heba.waly@gmail.com>
> >
> > Display hints to the user when trying to commit without staging the modified
> > files first (when advice.statusHints is set to true). Change the output of the
> > unsuccessful commit from e.g:
>
> Wrap your commit messages at 72 characters.
>
OK
Show 18 quoted lines
> >   # [...]
> >   # Changes not staged for commit:
> >   #   modified:   builtin/commit.c
> >   #
> >   # no changes added to commit
> >
> > to:
> >
> >   # [...]
> >   # Changes not staged for commit:
> >   #   (use "git add <file>..." to update what will be committed)
> >   #   (use "git checkout -- <file>..." to discard changes in working directory)
> >   #
> >   #   modified:   ../builtin/commit.c
>
> For tidiness, can this line also be "builtin/commit.c" (that is, without
> the "../" at the beginning) to match what's before "to:"?
>
Sure.
Show 33 quoted lines
> > In ea9882bfc4 (commit: disable status hints when writing to COMMIT_EDITMSG,
> > 2013-09-12) the intent was to disable status hints when writing to
> > COMMIT_EDITMSG, but in fact the implementation disabled status messages in
> > more locations, e.g in case the commit wasn't successful, status hints
> > will still be disabled and no hints will be displayed to the user although
> > advice.statusHints is set to true.
> >
> > Signed-off-by: Heba Waly <heba.waly@gmail.com>
> > ---
> >  builtin/commit.c                          | 1 +
> >  t/t7500-commit-template-squash-signoff.sh | 9 +++++++++
>
> I wondered if there was a better place to put the test, but I couldn't
> find one, so this is fine.
>
> > @@ -961,6 +961,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
> >        */
> >       if (!committable && whence != FROM_MERGE && !allow_empty &&
> >           !(amend && is_a_merge(current_head))) {
> > +             s->hints = advice_status_hints;
> >               s->display_comment_prefix = old_display_comment_prefix;
> >               run_status(stdout, index_file, prefix, 0, s);
> >               if (amend)
>
> I checked that this undoing of "s->hints = 0" is safe, because s is no
> longer used in this function nor in the calling function cmd_commit()
> (which is the one that declared s locally).
>
> Still probably worth a comment, though. For example:
>
>   This status is to be printed to stdout, so hints will be useful to the
>   user. Reset s->hints to what the user configured.
>
Ok.
Show 12 quoted lines
> The corresponding comment on "s->hints = 0" might need to be tweaked,
> too, but I can't think of anything at the moment.
>
> > +test_expect_success 'commit without staging files fails and displays hints' '
> > +     echo "initial" >>file &&
> > +     git add file &&
> > +     git commit -m initial &&
> > +     echo "changes" >>file &&
> > +     test_must_fail git commit -m initial >actual &&
>
> Use another commit message for this, since this is no longer "initial".
> (Maybe "after initial" or something like that.)
Makes sense.
Thank you Jonathan.
Heba
Heba
Heba Waly via GitGitGadget· Dec 19, 2019, 09:16 UTC · re: Heba Waly via GitGitGadget · lore

[PATCH v2 0/1] [Outreachy] commit: display advice hints when commit fails

Display hints to the user when trying to commit without staging the modified files first (when advice.statusHints is set to true). Change the output of the unsuccessful commit from e.g:

 . [...] . Changes not staged for commit: . modified: builtin/commit.c . .
no changes added to commit
to:
 . [...] . Changes not staged for commit: . (use "git add ..." to update
what will be committed) . (use "git checkout -- ..." to discard changes in
working directory) . . modified: ../builtin/commit.c . . no changes added to
commit (use "git add" and/or "git commit -a")

In ea9882bfc4 (commit: disable status hints when writing to COMMIT_EDITMSG, 2013-09-12) the intent was to disable status hints when writing to COMMIT_EDITMSG, but in fact the implementation disabled status messages in more locations, e.g in case the commit wasn't successful, status hints will still be disabled and no hints will be displayed to the user although advice.statusHints is set to true.

Signed-off-by: Heba Waly heba.waly@gmail.com [heba.waly@gmail.com]
Heba Waly (1):
  commit: display advice hints when commit fails
 builtin/commit.c                          | 18 ++++++++++++------
 t/t7500-commit-template-squash-signoff.sh |  9 +++++++++
 2 files changed, 21 insertions(+), 6 deletions(-)
base-commit: 12029dc57db23baef008e77db1909367599210ee
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-495%2FHebaWaly%2Fhints-for-unsuccessful-commit-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-495/HebaWaly/hints-for-unsuccessful-commit-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/495
Range-diff vs v1:
 1:  f23477c5a3 ! 1:  ebec237920 commit: display advice hints when commit fails
     @@ -2,9 +2,9 @@
      
          commit: display advice hints when commit fails
      
     -    Display hints to the user when trying to commit without staging the modified
     -    files first (when advice.statusHints is set to true). Change the output of the
     -    unsuccessful commit from e.g:
     +    Display hints to the user when trying to commit without staging the
     +    modified files first (when advice.statusHints is set to true). Change
     +    the output of the unsuccessful commit from e.g:
      
            # [...]
            # Changes not staged for commit:
     @@ -19,16 +19,16 @@
            #   (use "git add <file>..." to update what will be committed)
            #   (use "git checkout -- <file>..." to discard changes in working directory)
            #
     -      #   modified:   ../builtin/commit.c
     +      #   modified:   /builtin/commit.c
            #
            # no changes added to commit (use "git add" and/or "git commit -a")
      
     -    In ea9882bfc4 (commit: disable status hints when writing to COMMIT_EDITMSG,
     -    2013-09-12) the intent was to disable status hints when writing to
     -    COMMIT_EDITMSG, but in fact the implementation disabled status messages in
     -    more locations, e.g in case the commit wasn't successful, status hints
     -    will still be disabled and no hints will be displayed to the user although
     -    advice.statusHints is set to true.
     +    In ea9882bfc4 (commit: disable status hints when writing to
     +    COMMIT_EDITMSG, 2013-09-12) the intent was to disable status hints when
     +    writing to COMMIT_EDITMSG, but in fact the implementation disabled
     +    status messages in more locations, e.g in case the commit wasn't
     +    successful, status hints will still be disabled and no hints will be
     +    displayed to the user although advice.statusHints is set to true.
      
          Signed-off-by: Heba Waly <heba.waly@gmail.com>
      
     @@ -36,13 +36,44 @@
       --- a/builtin/commit.c
       +++ b/builtin/commit.c
      @@
     - 	 */
     - 	if (!committable && whence != FROM_MERGE && !allow_empty &&
     - 	    !(amend && is_a_merge(current_head))) {
     -+		s->hints = advice_status_hints;
     - 		s->display_comment_prefix = old_display_comment_prefix;
     - 		run_status(stdout, index_file, prefix, 0, s);
     - 		if (amend)
     + 	old_display_comment_prefix = s->display_comment_prefix;
     + 	s->display_comment_prefix = 1;
     + 
     +-	/*
     +-	 * Most hints are counter-productive when the commit has
     +-	 * already started.
     +-	 */
     +-	s->hints = 0;
     +-
     + 	if (clean_message_contents)
     + 		strbuf_stripspace(&sb, 0);
     + 
     +@@
     + 		int saved_color_setting;
     + 		struct ident_split ci, ai;
     + 
     ++		/*
     ++		 * Most hints are counter-productive when displayed in
     ++		 * the commit message editor.
     ++		 */
     ++		s->hints = 0;
     ++
     + 		if (whence != FROM_COMMIT) {
     + 			if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS &&
     + 				!merge_contains_scissors)
     +@@
     + 		saved_color_setting = s->use_color;
     + 		s->use_color = 0;
     + 		committable = run_status(s->fp, index_file, prefix, 1, s);
     ++		if(!committable)
     ++			/*
     ++			 Status is to be printed to stdout, so hints will be useful to the
     ++			 user. Reset s->hints to what the user configured
     ++			 */
     ++			s->hints = advice_status_hints;
     + 		s->use_color = saved_color_setting;
     + 		string_list_clear(&s->change, 1);
     + 	} else {
      
       diff --git a/t/t7500-commit-template-squash-signoff.sh b/t/t7500-commit-template-squash-signoff.sh
       --- a/t/t7500-commit-template-squash-signoff.sh
     @@ -56,7 +87,7 @@
      +	git add file &&
      +	git commit -m initial &&
      +	echo "changes" >>file &&
     -+	test_must_fail git commit -m initial >actual &&
     ++	test_must_fail git commit -m update >actual &&
      +	test_i18ngrep "no changes added to commit (use \"git add\" and/or \"git commit -a\")" actual
      +'
      +
-- 
gitgitgadget
Heba Waly via GitGitGadget· Dec 19, 2019, 09:16 UTC · re: Heba Waly via GitGitGadget · lore

[PATCH v2 1/1] commit: display advice hints when commit fails

From: Heba Waly <heba.waly@gmail.com>

Display hints to the user when trying to commit without staging the modified files first (when advice.statusHints is set to true). Change the output of the unsuccessful commit from e.g:

  # [...]
  # Changes not staged for commit:
  #   modified:   builtin/commit.c
  #
  # no changes added to commit
to:
  # [...]
  # Changes not staged for commit:
  #   (use "git add <file>..." to update what will be committed)
  #   (use "git checkout -- <file>..." to discard changes in working directory)
  #
  #   modified:   /builtin/commit.c
  #
  # no changes added to commit (use "git add" and/or "git commit -a")

In ea9882bfc4 (commit: disable status hints when writing to COMMIT_EDITMSG, 2013-09-12) the intent was to disable status hints when writing to COMMIT_EDITMSG, but in fact the implementation disabled status messages in more locations, e.g in case the commit wasn't successful, status hints will still be disabled and no hints will be displayed to the user although advice.statusHints is set to true.

Signed-off-by: Heba Waly <heba.waly@gmail.com>
---
 builtin/commit.c                          | 18 ++++++++++++------
 t/t7500-commit-template-squash-signoff.sh |  9 +++++++++
 2 files changed, 21 insertions(+), 6 deletions(-)
Show changes to 2 files +21 −6

builtin/commit.c, t/t7500-commit-template-squash-signoff.sh

diff --git a/builtin/commit.c b/builtin/commit.c
index e48c1fd90a..868c0d7819 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -811,12 +811,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 	old_display_comment_prefix = s->display_comment_prefix;
 	s->display_comment_prefix = 1;
 
-	/*
-	 * Most hints are counter-productive when the commit has
-	 * already started.
-	 */
-	s->hints = 0;
-
 	if (clean_message_contents)
 		strbuf_stripspace(&sb, 0);
 
@@ -837,6 +831,12 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 		int saved_color_setting;
 		struct ident_split ci, ai;
 
+		/*
+		 * Most hints are counter-productive when displayed in
+		 * the commit message editor.
+		 */
+		s->hints = 0;
+
 		if (whence != FROM_COMMIT) {
 			if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS &&
 				!merge_contains_scissors)
@@ -912,6 +912,12 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 		saved_color_setting = s->use_color;
 		s->use_color = 0;
 		committable = run_status(s->fp, index_file, prefix, 1, s);
+		if(!committable)
+			/*
+			 Status is to be printed to stdout, so hints will be useful to the
+			 user. Reset s->hints to what the user configured
+			 */
+			s->hints = advice_status_hints;
 		s->use_color = saved_color_setting;
 		string_list_clear(&s->change, 1);
 	} else {
diff --git a/t/t7500-commit-template-squash-signoff.sh b/t/t7500-commit-template-squash-signoff.sh
index 46a5cd4b73..a8179e4074 100755
--- a/t/t7500-commit-template-squash-signoff.sh
+++ b/t/t7500-commit-template-squash-signoff.sh
@@ -382,4 +382,13 @@ test_expect_success 'check commit with unstaged rename and copy' '
 	)
 '
 
+test_expect_success 'commit without staging files fails and displays hints' '
+	echo "initial" >>file &&
+	git add file &&
+	git commit -m initial &&
+	echo "changes" >>file &&
+	test_must_fail git commit -m update >actual &&
+	test_i18ngrep "no changes added to commit (use \"git add\" and/or \"git commit -a\")" actual
+'
+
 test_done
-- 
gitgitgadget
Junio C Hamano· Dec 19, 2019, 19:14 UTC · re: Heba Waly via GitGitGadget · lore

Re: [PATCH v2 1/1] commit: display advice hints when commit fails

"Heba Waly via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 14 quoted lines
> diff --git a/builtin/commit.c b/builtin/commit.c
> index e48c1fd90a..868c0d7819 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -811,12 +811,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>  	old_display_comment_prefix = s->display_comment_prefix;
>  	s->display_comment_prefix = 1;
>  
> -	/*
> -	 * Most hints are counter-productive when the commit has
> -	 * already started.
> -	 */
> -	s->hints = 0;
> -
Hmm.
Show 10 quoted lines
> @@ -837,6 +831,12 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>  		int saved_color_setting;
>  		struct ident_split ci, ai;
>  
> +		/*
> +		 * Most hints are counter-productive when displayed in
> +		 * the commit message editor.
> +		 */
> +		s->hints = 0;
> +

We no longer drop s->hints when we are not using editor and not including status (i.e. the "else" side) because these lines are moved inside "if". As this change is not about that "no editor" side, I am not 100% convinced that this is a good change.

Show 5 quoted lines
> @@ -912,6 +912,12 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>  		saved_color_setting = s->use_color;
>  		s->use_color = 0;
>  		committable = run_status(s->fp, index_file, prefix, 1, s);
> +		if(!committable)
Style: SP between "if" and "(".
Show 5 quoted lines
> +			/*
> +			 Status is to be printed to stdout, so hints will be useful to the
> +			 user. Reset s->hints to what the user configured
> +			 */
> +			s->hints = advice_status_hints;

The "if" side has been changed to flip s->hints to the configured advice hints value when !committable here. The "else" side (i.e. when we are not using editor and not including status) does not do anything to s->hints after finding out if committable after this change. Because "s->hints = 0" was moved to "if" with this patch, the "else" side no longer drops s->hints at all.

So the final run_status() called when the attempt to commit is rejected will feed s->hints that is not cleared with this change.

Is that intended?  Is the updated behaviour checked with a test?
>  		s->use_color = saved_color_setting;
>  		string_list_clear(&s->change, 1);
>  	} else {

This fix was about "we do not want to unconditionally drop the advice messages when we reject the attempt to commit and show the output like 'git status'", wasn't it? The earlier single-liner fix in v1 that flips s->hints just before calling run_status() before rejecting the attempt to commit was a lot easier to reason about, as the fix was very focused and to the point. Why are we seeing this many (seemingly unrelated) changes?

Puzzled...
Junio C Hamano· Dec 19, 2019, 19:22 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 1/1] commit: display advice hints when commit fails

Junio C Hamano <gitster@pobox.com> writes:
Show 7 quoted lines
> This fix was about "we do not want to unconditionally drop the
> advice messages when we reject the attempt to commit and show the
> output like 'git status'", wasn't it?  The earlier single-liner fix
> in v1 that flips s->hints just before calling run_status() before
> rejecting the attempt to commit was a lot easier to reason about, as
> the fix was very focused and to the point.  Why are we seeing this
> many (seemingly unrelated) changes?

In any case, here is what I tentatively have in my tree (with heavy rewrite to the proposed log message).

-- >8 --
From: Heba Waly <heba.waly@gmail.com>
Date: Tue, 17 Dec 2019 09:17:22 +0000
Subject: [PATCH] commit: honor advice.statusHints when rejecting an empty
 commit

In ea9882bfc4 (commit: disable status hints when writing to COMMIT_EDITMSG, 2013-09-12) the intent was to disable status hints when writing to COMMIT_EDITMSG, because giving the hints in the "git status" like output in the commit message template are too late to be useful (they say things like "'git add' to stage", but that is only possible after aborting the current "git commit" session).

But there is one case that the hints can be useful: When the current attempt to commit is rejected because no change is recorded in the index. The message is given and "git commit" errors out, so the hints can immediately be followed by the user. Teach the codepath to honor the configuration variable.

Signed-off-by: Heba Waly <heba.waly@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/commit.c                          | 1 +
 t/t7500-commit-template-squash-signoff.sh | 9 +++++++++
 2 files changed, 10 insertions(+)
Show changes to 2 files +10 −0

builtin/commit.c, t/t7500-commit-template-squash-signoff.sh

diff --git a/builtin/commit.c b/builtin/commit.c
index e588bc6ad3..0078faf117 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -944,6 +944,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 	 */
 	if (!committable && whence != FROM_MERGE && !allow_empty &&
 	    !(amend && is_a_merge(current_head))) {
+		s->hints = advice_status_hints;
 		s->display_comment_prefix = old_display_comment_prefix;
 		run_status(stdout, index_file, prefix, 0, s);
 		if (amend)
diff --git a/t/t7500-commit-template-squash-signoff.sh b/t/t7500-commit-template-squash-signoff.sh
index 46a5cd4b73..a8179e4074 100755
--- a/t/t7500-commit-template-squash-signoff.sh
+++ b/t/t7500-commit-template-squash-signoff.sh
@@ -382,4 +382,13 @@ test_expect_success 'check commit with unstaged rename and copy' '
 	)
 '
 
+test_expect_success 'commit without staging files fails and displays hints' '
+	echo "initial" >>file &&
+	git add file &&
+	git commit -m initial &&
+	echo "changes" >>file &&
+	test_must_fail git commit -m update >actual &&
+	test_i18ngrep "no changes added to commit (use \"git add\" and/or \"git commit -a\")" actual
+'
+
 test_done
-- 
2.24.1-732-ga9f9d4909c
Eric Sunshine· Dec 19, 2019, 19:47 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 1/1] commit: display advice hints when commit fails

On Thu, Dec 19, 2019 at 2:22 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 5 quoted lines
> In any case, here is what I tentatively have in my tree (with heavy
> rewrite to the proposed log message).
>
> +test_expect_success 'commit without staging files fails and displays hints' '
> +       echo "initial" >>file &&

The use of '>>' here rather than '>' feels wrong, especially when "initial" is used for both the file body and the commit message, causing a reader of the test to wonder if this test somehow depends upon earlier tests.

Show 6 quoted lines
> +       git add file &&
> +       git commit -m initial &&
> +       echo "changes" >>file &&
> +       test_must_fail git commit -m update >actual &&
> +       test_i18ngrep "no changes added to commit (use \"git add\" and/or \"git commit -a\")" actual
> +'
Junio C Hamano· Dec 19, 2019, 19:57 UTC · re: Eric Sunshine · lore

Re: [PATCH v2 1/1] commit: display advice hints when commit fails

Eric Sunshine <sunshine@sunshineco.com> writes:
Show 11 quoted lines
> On Thu, Dec 19, 2019 at 2:22 PM Junio C Hamano <gitster@pobox.com> wrote:
>> In any case, here is what I tentatively have in my tree (with heavy
>> rewrite to the proposed log message).
>>
>> +test_expect_success 'commit without staging files fails and displays hints' '
>> +       echo "initial" >>file &&
>
> The use of '>>' here rather than '>' feels wrong, especially when
> "initial" is used for both the file body and the commit message,
> causing a reader of the test to wonder if this test somehow depends
> upon earlier tests.

Yeah, makes sense. This was verbatim from v1 but I think starting the file from scratch like you suggest makes it clearer what is going on.

Show 7 quoted lines
>
>> +       git add file &&
>> +       git commit -m initial &&
>> +       echo "changes" >>file &&
>> +       test_must_fail git commit -m update >actual &&
>> +       test_i18ngrep "no changes added to commit (use \"git add\" and/or \"git commit -a\")" actual
>> +'
Emily Shaffer· Dec 20, 2019, 02:31 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 1/1] commit: display advice hints when commit fails

On Thu, Dec 19, 2019 at 11:22:38AM -0800, Junio C Hamano wrote:
Show 12 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
> 
> > This fix was about "we do not want to unconditionally drop the
> > advice messages when we reject the attempt to commit and show the
> > output like 'git status'", wasn't it?  The earlier single-liner fix
> > in v1 that flips s->hints just before calling run_status() before
> > rejecting the attempt to commit was a lot easier to reason about, as
> > the fix was very focused and to the point.  Why are we seeing this
> > many (seemingly unrelated) changes?
> 
> In any case, here is what I tentatively have in my tree (with heavy
> rewrite to the proposed log message).

Hm. I'm surprised to see this feedback come in the form of a local change when making the topic branch, rather than in a reply to the v1 patch. What's the reasoning? (Or is this scissors patch intended to be the feedback?)

I ask because out of all of us, it seems the Outreachy interns can benefit the most from advice on how and why to write their commit messages - that is, part of the point of an internship is to learn best practices and cultural norms in addition to coding practice. (Plus, I find being asked to rewrite a commit message tends to force me to understand my own change even better than before.)

I'll go ahead and look through the changes to the commit message so I can learn what you're looking for too :)

Show 13 quoted lines
> 
> -- >8 --
> From: Heba Waly <heba.waly@gmail.com>
> Date: Tue, 17 Dec 2019 09:17:22 +0000
> Subject: [PATCH] commit: honor advice.statusHints when rejecting an empty
>  commit
> 
> In ea9882bfc4 (commit: disable status hints when writing to
> COMMIT_EDITMSG, 2013-09-12) the intent was to disable status hints
> when writing to COMMIT_EDITMSG, because giving the hints in the "git
> status" like output in the commit message template are too late to
> be useful (they say things like "'git add' to stage", but that is
> only possible after aborting the current "git commit" session).

More context on why the previous change was made - "by the time the editor was open, it was too late to apply hints anyways". Sure.

Show 6 quoted lines
> 
> But there is one case that the hints can be useful: When the current
> attempt to commit is rejected because no change is recorded in the
> index.  The message is given and "git commit" errors out, so the
> hints can immediately be followed by the user.  Teach the codepath
> to honor the configuration variable.

Expanding the "but" to supply the specific story this commit touches, including "what happens instead" and "how are we gonna fix it".

And the copy-paste of the output before and the output now is different. For me, I don't particularly see why we'd want to be rid of it - it sort of feels like "a picture is worth a thousand words" to include the actual use case in the commit message. Is there style guidance suggesting not to do that that I missed?

 - Emily
Show 41 quoted lines
> 
> Signed-off-by: Heba Waly <heba.waly@gmail.com>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>  builtin/commit.c                          | 1 +
>  t/t7500-commit-template-squash-signoff.sh | 9 +++++++++
>  2 files changed, 10 insertions(+)
> 
> diff --git a/builtin/commit.c b/builtin/commit.c
> index e588bc6ad3..0078faf117 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -944,6 +944,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>  	 */
>  	if (!committable && whence != FROM_MERGE && !allow_empty &&
>  	    !(amend && is_a_merge(current_head))) {
> +		s->hints = advice_status_hints;
>  		s->display_comment_prefix = old_display_comment_prefix;
>  		run_status(stdout, index_file, prefix, 0, s);
>  		if (amend)
> diff --git a/t/t7500-commit-template-squash-signoff.sh b/t/t7500-commit-template-squash-signoff.sh
> index 46a5cd4b73..a8179e4074 100755
> --- a/t/t7500-commit-template-squash-signoff.sh
> +++ b/t/t7500-commit-template-squash-signoff.sh
> @@ -382,4 +382,13 @@ test_expect_success 'check commit with unstaged rename and copy' '
>  	)
>  '
>  
> +test_expect_success 'commit without staging files fails and displays hints' '
> +	echo "initial" >>file &&
> +	git add file &&
> +	git commit -m initial &&
> +	echo "changes" >>file &&
> +	test_must_fail git commit -m update >actual &&
> +	test_i18ngrep "no changes added to commit (use \"git add\" and/or \"git commit -a\")" actual
> +'
> +
>  test_done
> -- 
> 2.24.1-732-ga9f9d4909c
> 
Junio C Hamano· Dec 20, 2019, 18:34 UTC · re: Emily Shaffer · lore

Re: [PATCH v2 1/1] commit: display advice hints when commit fails

Emily Shaffer <emilyshaffer@google.com> writes:
> Hm. I'm surprised to see this feedback come in the form of a local
> change when making the topic branch, rather than in a reply to the v1
> patch. What's the reasoning? (Or is this scissors patch intended to be
> the feedback?)
You haven't seen a suggestion in the form of counter-proposal?
Show 6 quoted lines
> I ask because out of all of us, it seems the Outreachy interns can
> benefit the most from advice on how and why to write their commit
> messages - that is, part of the point of an internship is to learn best
> practices and cultural norms in addition to coding practice. (Plus, I
> find being asked to rewrite a commit message tends to force me to
> understand my own change even better than before.)

It's something Mentors can help doing (I do not necessarily have time for that myself), and you're welcome to use the "tenatively queued" version as an example.

> I'll go ahead and look through the changes to the commit message so I
> can learn what you're looking for too :)
Nice.

One thing you missed in your review of the "tentatively queued" version is the reversal of the order of presentation. Instead of starting with "I decided to do this" without explanation, give the picture of status quo to set the stage, explain what issue exists in the current behaviour, and then describe what approach was chosen to solve the issue.

> For me, I don't particularly see why we'd want to be rid of it - it sort
> of feels like "a picture is worth a thousand words" to include the
> actual use case in the commit message.

Output coming from commands and/or options that are used only in a bit more advanced workflow and the ones that are rarely seen, I do agree that showing example is a good way to illustrate exactly what you are talking about.

On the other hand, for behaviour of basic local commands like "git add", "git commit", "git diff", ..., I do not necessarily agree, as these should be obvious and clear to all the intended audiences, which would be "anybody who has used Git for say more than two weeks.

Emily Shaffer· Dec 20, 2019, 21:39 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 1/1] commit: display advice hints when commit fails

On Fri, Dec 20, 2019 at 10:34:28AM -0800, Junio C Hamano wrote:
Show 8 quoted lines
> Emily Shaffer <emilyshaffer@google.com> writes:
> 
> > Hm. I'm surprised to see this feedback come in the form of a local
> > change when making the topic branch, rather than in a reply to the v1
> > patch. What's the reasoning? (Or is this scissors patch intended to be
> > the feedback?)
> 
> You haven't seen a suggestion in the form of counter-proposal?

I actually have only seen the scissors-patch as a "yes, and" in practice. I think this is a sign I should be doing more reviews ;)

Show 23 quoted lines
> 
> > I ask because out of all of us, it seems the Outreachy interns can
> > benefit the most from advice on how and why to write their commit
> > messages - that is, part of the point of an internship is to learn best
> > practices and cultural norms in addition to coding practice. (Plus, I
> > find being asked to rewrite a commit message tends to force me to
> > understand my own change even better than before.)
> 
> It's something Mentors can help doing (I do not necessarily have
> time for that myself), and you're welcome to use the "tenatively
> queued" version as an example.
> 
> > I'll go ahead and look through the changes to the commit message so I
> > can learn what you're looking for too :)
> 
> Nice.
> 
> One thing you missed in your review of the "tentatively queued"
> version is the reversal of the order of presentation.  Instead of
> starting with "I decided to do this" without explanation, give the
> picture of status quo to set the stage, explain what issue exists in
> the current behaviour, and then describe what approach was chosen to
> solve the issue.
Thanks for explaining this - that's a good point for me to take home.
Show 15 quoted lines
> 
> > For me, I don't particularly see why we'd want to be rid of it - it sort
> > of feels like "a picture is worth a thousand words" to include the
> > actual use case in the commit message.
> 
> Output coming from commands and/or options that are used only in a
> bit more advanced workflow and the ones that are rarely seen, I do
> agree that showing example is a good way to illustrate exactly what
> you are talking about.
> 
> On the other hand, for behaviour of basic local commands like "git
> add", "git commit", "git diff", ..., I do not necessarily agree, as
> these should be obvious and clear to all the intended audiences,
> which would be "anybody who has used Git for say more than two
> weeks.
Hm, I see. Thanks for clarifying.
 - Emily
Jonathan Tan· Dec 31, 2019, 00:04 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 1/1] commit: display advice hints when commit fails

Show 10 quoted lines
> > This fix was about "we do not want to unconditionally drop the
> > advice messages when we reject the attempt to commit and show the
> > output like 'git status'", wasn't it?  The earlier single-liner fix
> > in v1 that flips s->hints just before calling run_status() before
> > rejecting the attempt to commit was a lot easier to reason about, as
> > the fix was very focused and to the point.  Why are we seeing this
> > many (seemingly unrelated) changes?
> 
> In any case, here is what I tentatively have in my tree (with heavy
> rewrite to the proposed log message).

Junio, what are your plans over what you have in your tree? If you'd like to hear Heba's opinion on it, then she can chime in; if you'd like a review, then I think it's good to go in.

I think the main area of discussion is whether we should go with Heba's attempt to address Emily's comment [1]:

Show 14 quoted lines
> I think the intent of that commit was to not put hints into the editor,
> so does it make sense to instead wrap this guy:
> 
>   /*                                                                       
>    * Most hints are counter-productive when the commit has                 
>    * already started.                                                      
>    */                                                                      
>   s->hints = 0;  
> 
> in "if (use_editor)"?
> 
> I didn't try it on my end. Maybe it won't help much, because we think
> we're going to use the editor right up until we realize it's not
> committable?

And I think the answer to that is "s" is used throughout the function in various ways (in particular, used to print statuses both to stdout and to the message template) so any wrapping or corralling of scope would just make things more complicated. In particular, the way Heba did it in v2 is more unclear - at the time of setting s->hints = 0, it's done within a "if (use_editor && include_status)" block, but (as far as I can tell) the commit message template might also be used when there is no editor - for example, as input to a hook. And more importantly, when s->hints is reset to the config, we don't know at that point that the next status is going to stdout. So I think it's better just to use the v1 way.

The second area of discussion I see is in the commit message. Commit messages have to balance brevity and comprehensiveness, and this can be a subjective matter, but I think Junio's strikes a good balance.

[1] https://lore.kernel.org/git/20191217224541.GA230678@google.com/
Junio C Hamano· Dec 31, 2019, 19:06 UTC · re: Jonathan Tan · lore

Re: [PATCH v2 1/1] commit: display advice hints when commit fails

Jonathan Tan <jonathantanmy@google.com> writes:
Show 6 quoted lines
>> In any case, here is what I tentatively have in my tree (with heavy
>> rewrite to the proposed log message).
>
> Junio, what are your plans over what you have in your tree? If you'd
> like to hear Heba's opinion on it, then she can chime in; if you'd like
> a review, then I think it's good to go in.
On hold until anything like those happens ;-) 

A random reviewer mentioning something on a patch (either in a line-by-line critique form or "how about doing it this way instead" counterproposal form) without getting followed up by others (including the original author) is a stall review thread, and it does not change the equation if the random reviewer happens to be me.

Show 9 quoted lines
>> I didn't try it on my end. Maybe it won't help much, because we think
>> we're going to use the editor right up until we realize it's not
>> committable?
>
> And I think the answer to that is "s" is used throughout the function in
> various ways (in particular, used to print statuses both to stdout and
> to the message template) so any wrapping or corralling of scope would
> just make things more complicated. In particular, the way Heba did it in
> v2 is more unclear - at the time of setting s->hints = 0, it's done
You mean "less clear" (just double checking if I got the negation right)?
Show 6 quoted lines
> within a "if (use_editor && include_status)" block, but (as far as I can
> tell) the commit message template might also be used when there is no
> editor - for example, as input to a hook. And more importantly, when
> s->hints is reset to the config, we don't know at that point that the
> next status is going to stdout. So I think it's better just to use the
> v1 way.

Yeah, thanks for going back to compare v1 and v2, and I agree with your assessment.

> The second area of discussion I see is in the commit message. Commit
> messages have to balance brevity and comprehensiveness, and this can be
> a subjective matter, but I think Junio's strikes a good balance.

As one side of the comparison is my own, I won't be a good judge on this, but yes I tried to strick a good balance as much as possible.

I think I've merged it to 'next' yesterday, but it does not mean that much as we are in -rc and it is not such an urgent "oops we broke it in this cycle, let's fix it" issue. If we see a v3 that improves it, I do not mind at all reverting what I merged to 'next' and use the updated one instead (either way, it will be in 'master' during the next cycle at the earliest).

Thanks.
Jonathan Tan· Jan 2, 2020, 19:56 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 1/1] commit: display advice hints when commit fails

Show 11 quoted lines
> > Junio, what are your plans over what you have in your tree? If you'd
> > like to hear Heba's opinion on it, then she can chime in; if you'd like
> > a review, then I think it's good to go in.
> 
> On hold until anything like those happens ;-) 
> 
> A random reviewer mentioning something on a patch (either in a
> line-by-line critique form or "how about doing it this way instead"
> counterproposal form) without getting followed up by others
> (including the original author) is a stall review thread, and it
> does not change the equation if the random reviewer happens to be me.
OK :-)
Show 7 quoted lines
> > And I think the answer to that is "s" is used throughout the function in
> > various ways (in particular, used to print statuses both to stdout and
> > to the message template) so any wrapping or corralling of scope would
> > just make things more complicated. In particular, the way Heba did it in
> > v2 is more unclear - at the time of setting s->hints = 0, it's done
> 
> You mean "less clear" (just double checking if I got the negation right)?
Yes, less clear - v2 is less clear than v1.
Show 6 quoted lines
> I think I've merged it to 'next' yesterday, but it does not mean
> that much as we are in -rc and it is not such an urgent "oops we
> broke it in this cycle, let's fix it" issue.  If we see a v3 that
> improves it, I do not mind at all reverting what I merged to 'next'
> and use the updated one instead (either way, it will be in 'master'
> during the next cycle at the earliest).
Sounds good - thanks.
Junio C Hamano· Dec 19, 2019, 18:26 UTC · re: Heba Waly via GitGitGadget · lore

Re: [PATCH v2 0/1] [Outreachy] commit: display advice hints when commit fails

"Heba Waly via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 6 quoted lines
>      @@ -19,16 +19,16 @@
>             #   (use "git add <file>..." to update what will be committed)
>             #   (use "git checkout -- <file>..." to discard changes in working directory)
>             #
>      -      #   modified:   ../builtin/commit.c
>      +      #   modified:   /builtin/commit.c
Really?
Emily Shaffer· Dec 19, 2019, 18:54 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 0/1] [Outreachy] commit: display advice hints when commit fails

On Thu, Dec 19, 2019 at 10:26:40AM -0800, Junio C Hamano wrote:
Show 10 quoted lines
> "Heba Waly via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 
> >      @@ -19,16 +19,16 @@
> >             #   (use "git add <file>..." to update what will be committed)
> >             #   (use "git checkout -- <file>..." to discard changes in working directory)
> >             #
> >      -      #   modified:   ../builtin/commit.c
> >      +      #   modified:   /builtin/commit.c
> 
> Really?
It's hard to know what this cryptic comment means.. :)

This was a recommended change: https://lore.kernel.org/git/20191218031338.203382-1-jonathantanmy@google.com

Since other changes were being made at the same time, I personally don't mind a little nit fix in the commit message.

Or, do you mean that "now it looks like the file is at the filesystem root, which is wrong"? It is indeed wrong now when it wasn't before. But I, for one, can't tell what you mean by just the one word.

 - Emily
Junio C Hamano· Dec 19, 2019, 19:23 UTC · re: Emily Shaffer · lore

Re: [PATCH v2 0/1] [Outreachy] commit: display advice hints when commit fails

Emily Shaffer <emilyshaffer@google.com> writes:
Show 23 quoted lines
> On Thu, Dec 19, 2019 at 10:26:40AM -0800, Junio C Hamano wrote:
>> "Heba Waly via GitGitGadget" <gitgitgadget@gmail.com> writes:
>> 
>> >      @@ -19,16 +19,16 @@
>> >             #   (use "git add <file>..." to update what will be committed)
>> >             #   (use "git checkout -- <file>..." to discard changes in working directory)
>> >             #
>> >      -      #   modified:   ../builtin/commit.c
>> >      +      #   modified:   /builtin/commit.c
>> 
>> Really?
>
> It's hard to know what this cryptic comment means.. :)
>
> This was a recommended change:
> https://lore.kernel.org/git/20191218031338.203382-1-jonathantanmy@google.com
>
> Since other changes were being made at the same time, I personally don't
> mind a little nit fix in the commit message.
>
> Or, do you mean that "now it looks like the file is at the filesystem
> root, which is wrong"? It is indeed wrong now when it wasn't before. But
> I, for one, can't tell what you mean by just the one word.

That is exactly the point. I am not in the business of spoon feeding answers. I want my contributors to *think*.

Junio C Hamano· Dec 19, 2019, 19:45 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 0/1] [Outreachy] commit: display advice hints when commit fails

Junio C Hamano <gitster@pobox.com> writes:
Show 28 quoted lines
> Emily Shaffer <emilyshaffer@google.com> writes:
>
>> On Thu, Dec 19, 2019 at 10:26:40AM -0800, Junio C Hamano wrote:
>>> "Heba Waly via GitGitGadget" <gitgitgadget@gmail.com> writes:
>>> 
>>> >      @@ -19,16 +19,16 @@
>>> >             #   (use "git add <file>..." to update what will be committed)
>>> >             #   (use "git checkout -- <file>..." to discard changes in working directory)
>>> >             #
>>> >      -      #   modified:   ../builtin/commit.c
>>> >      +      #   modified:   /builtin/commit.c
>>> 
>>> Really?
>>
>> It's hard to know what this cryptic comment means.. :)
>>
>> This was a recommended change:
>> https://lore.kernel.org/git/20191218031338.203382-1-jonathantanmy@google.com
>>
>> Since other changes were being made at the same time, I personally don't
>> mind a little nit fix in the commit message.
>>
>> Or, do you mean that "now it looks like the file is at the filesystem
>> root, which is wrong"? It is indeed wrong now when it wasn't before. But
>> I, for one, can't tell what you mean by just the one word.
>
> That is exactly the point.  I am not in the business of spoon
> feeding answers.  I want my contributors to *think*.

And I am not being unnecessarily cryptic. If anybody thought a bit about what the topic was about, looking at it it would immediately be obvious that the sample output shown there is totally bogus, due to the leading slash.

Any contributor working on this topic should be competent enough to realize/notice it once it is pointed out---even though lack of proof-reading before sending may cause such a mistake by carelessness. And that is what I wanted to convey by deliberately a short response.

Heba Waly· Dec 21, 2019, 04:37 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 0/1] [Outreachy] commit: display advice hints when commit fails

On Fri, Dec 20, 2019 at 8:45 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> That is exactly the point.  I am not in the business of spoon
> feeding answers.

Why would pointing out a typo clearly to the author be considered as spoon feeding answers? Rather than simply reviewing and pointing out mistakes in a clear and a respectful way?

> I want my contributors to *think*.

Nobody is against *thinking*, and I'm sure an author who found an issue and implemented a fix had his/her share of thinking to get the job done. So I hope a typo is not standing in the way of acknowledging the author's effort.

> Any contributor working on this topic should be competent enough to
> realize/notice it once it is pointed out---even though lack of
> proof-reading before sending may cause such a mistake by
> carelessness.

I have no reason not to believe that this is crossing the line. No matter how much a reviewer disagrees with the proposed changes, I'd appreciate keeping a mutually respectful discussion during the review process.

Heba
Junio C Hamano· Dec 21, 2019, 23:54 UTC · re: Heba Waly · lore

Re: [PATCH v2 0/1] [Outreachy] commit: display advice hints when commit fails

Heba Waly <heba.waly@gmail.com> writes:
Show 9 quoted lines
>> Any contributor working on this topic should be competent enough to
>> realize/notice it once it is pointed out---even though lack of
>> proof-reading before sending may cause such a mistake by
>> carelessness.
>
> I have no reason not to believe that this is crossing the line.
> No matter how much a reviewer disagrees with the proposed changes, I'd
> appreciate
> keeping a mutually respectful discussion during the review process.

I do not see any lack of respect in saying that I believed you are competent enough that a short "Huh?" answer was sufficient.

Heba Waly· Dec 21, 2019, 05:02 UTC · re: Heba Waly via GitGitGadget · lore

Re: [PATCH v2 0/1] [Outreachy] commit: display advice hints when commit fails

It was brought to my attention that I should've elaborated in the cover letter the difference between v1 and v2 and the reason behind the change. So I'll elaborate that here:

As pointed out by this review on v1 https://lore.kernel.org/git/xmqq36dgayma.fsf@gitster-ct.c.googlers.com/T/#m3adc84664e907bd8fcc13ac22c8702ae15925f8f

By default git honors the user's selection of displaying hints, but in the specific case of using the editor to write a commit message ea9882bfc4 wanted to turn it off temporarily because while the editor is open and the commit is in-progress, the user can't run these hints anyway (list discussion for reference https://lore.kernel.org/git/vpq4n9tghk5.fsf@anie.imag.fr/)

So it makes more sense to see the change made for this specific editor case inside an if condition rather than applying it to all the commit cases, and then flip it back once the commit fails.

Please correct me if I'm wrong, but I think for the rest of the cases, as long as there's no editor with status displayed inside (hints displayed while commit in progress), there's no need to turn off the hints.

Heba

On Thu, Dec 19, 2019 at 10:16 PM Heba Waly via GitGitGadget <gitgitgadget@gmail.com> wrote:

Show 141 quoted lines
>
> Display hints to the user when trying to commit without staging the modified
> files first (when advice.statusHints is set to true). Change the output of
> the unsuccessful commit from e.g:
>
>  . [...] . Changes not staged for commit: . modified: builtin/commit.c . .
> no changes added to commit
>
> to:
>
>  . [...] . Changes not staged for commit: . (use "git add ..." to update
> what will be committed) . (use "git checkout -- ..." to discard changes in
> working directory) . . modified: ../builtin/commit.c . . no changes added to
> commit (use "git add" and/or "git commit -a")
>
> In ea9882bfc4 (commit: disable status hints when writing to COMMIT_EDITMSG,
> 2013-09-12) the intent was to disable status hints when writing to
> COMMIT_EDITMSG, but in fact the implementation disabled status messages in
> more locations, e.g in case the commit wasn't successful, status hints will
> still be disabled and no hints will be displayed to the user although
> advice.statusHints is set to true.
>
> Signed-off-by: Heba Waly heba.waly@gmail.com [heba.waly@gmail.com]
>
> Heba Waly (1):
>   commit: display advice hints when commit fails
>
>  builtin/commit.c                          | 18 ++++++++++++------
>  t/t7500-commit-template-squash-signoff.sh |  9 +++++++++
>  2 files changed, 21 insertions(+), 6 deletions(-)
>
>
> base-commit: 12029dc57db23baef008e77db1909367599210ee
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-495%2FHebaWaly%2Fhints-for-unsuccessful-commit-v2
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-495/HebaWaly/hints-for-unsuccessful-commit-v2
> Pull-Request: https://github.com/gitgitgadget/git/pull/495
>
> Range-diff vs v1:
>
>  1:  f23477c5a3 ! 1:  ebec237920 commit: display advice hints when commit fails
>      @@ -2,9 +2,9 @@
>
>           commit: display advice hints when commit fails
>
>      -    Display hints to the user when trying to commit without staging the modified
>      -    files first (when advice.statusHints is set to true). Change the output of the
>      -    unsuccessful commit from e.g:
>      +    Display hints to the user when trying to commit without staging the
>      +    modified files first (when advice.statusHints is set to true). Change
>      +    the output of the unsuccessful commit from e.g:
>
>             # [...]
>             # Changes not staged for commit:
>      @@ -19,16 +19,16 @@
>             #   (use "git add <file>..." to update what will be committed)
>             #   (use "git checkout -- <file>..." to discard changes in working directory)
>             #
>      -      #   modified:   ../builtin/commit.c
>      +      #   modified:   /builtin/commit.c
>             #
>             # no changes added to commit (use "git add" and/or "git commit -a")
>
>      -    In ea9882bfc4 (commit: disable status hints when writing to COMMIT_EDITMSG,
>      -    2013-09-12) the intent was to disable status hints when writing to
>      -    COMMIT_EDITMSG, but in fact the implementation disabled status messages in
>      -    more locations, e.g in case the commit wasn't successful, status hints
>      -    will still be disabled and no hints will be displayed to the user although
>      -    advice.statusHints is set to true.
>      +    In ea9882bfc4 (commit: disable status hints when writing to
>      +    COMMIT_EDITMSG, 2013-09-12) the intent was to disable status hints when
>      +    writing to COMMIT_EDITMSG, but in fact the implementation disabled
>      +    status messages in more locations, e.g in case the commit wasn't
>      +    successful, status hints will still be disabled and no hints will be
>      +    displayed to the user although advice.statusHints is set to true.
>
>           Signed-off-by: Heba Waly <heba.waly@gmail.com>
>
>      @@ -36,13 +36,44 @@
>        --- a/builtin/commit.c
>        +++ b/builtin/commit.c
>       @@
>      -   */
>      -  if (!committable && whence != FROM_MERGE && !allow_empty &&
>      -      !(amend && is_a_merge(current_head))) {
>      -+         s->hints = advice_status_hints;
>      -          s->display_comment_prefix = old_display_comment_prefix;
>      -          run_status(stdout, index_file, prefix, 0, s);
>      -          if (amend)
>      +  old_display_comment_prefix = s->display_comment_prefix;
>      +  s->display_comment_prefix = 1;
>      +
>      +- /*
>      +-  * Most hints are counter-productive when the commit has
>      +-  * already started.
>      +-  */
>      +- s->hints = 0;
>      +-
>      +  if (clean_message_contents)
>      +          strbuf_stripspace(&sb, 0);
>      +
>      +@@
>      +          int saved_color_setting;
>      +          struct ident_split ci, ai;
>      +
>      ++         /*
>      ++          * Most hints are counter-productive when displayed in
>      ++          * the commit message editor.
>      ++          */
>      ++         s->hints = 0;
>      ++
>      +          if (whence != FROM_COMMIT) {
>      +                  if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS &&
>      +                          !merge_contains_scissors)
>      +@@
>      +          saved_color_setting = s->use_color;
>      +          s->use_color = 0;
>      +          committable = run_status(s->fp, index_file, prefix, 1, s);
>      ++         if(!committable)
>      ++                 /*
>      ++                  Status is to be printed to stdout, so hints will be useful to the
>      ++                  user. Reset s->hints to what the user configured
>      ++                  */
>      ++                 s->hints = advice_status_hints;
>      +          s->use_color = saved_color_setting;
>      +          string_list_clear(&s->change, 1);
>      +  } else {
>
>        diff --git a/t/t7500-commit-template-squash-signoff.sh b/t/t7500-commit-template-squash-signoff.sh
>        --- a/t/t7500-commit-template-squash-signoff.sh
>      @@ -56,7 +87,7 @@
>       + git add file &&
>       + git commit -m initial &&
>       + echo "changes" >>file &&
>      -+ test_must_fail git commit -m initial >actual &&
>      ++ test_must_fail git commit -m update >actual &&
>       + test_i18ngrep "no changes added to commit (use \"git add\" and/or \"git commit -a\")" actual
>       +'
>       +
>
> --
> gitgitgadget

← back to recent threads