git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: David Hull <david.hull@friendbuy.com>, git@vger.kernel.org
Subject: Re: Bug in "git diff" exit code with submodule and `--submodule=log`
Date: Wed, 4 Sep 2024 00:14:09 +0200	[thread overview]
Message-ID: <73fc18f3-9d2f-43fe-b0a1-2f3680f09ce6@web.de> (raw)
In-Reply-To: <CALpyDwE12kHV--NkbcSgxLacsYw_w1wdBhzM21-JO1yYKW2PwA@mail.gmail.com>

Am 03.09.24 um 16:38 schrieb David Hull:
> What did you do before the bug happened? (Steps to reproduce your issue)
>
> Create a git repository that has a submodule.  The git repository
> itself should be clean but the submodule should have changes that have
> been staged in the main repository.  Then run:
> `git diff --exit-code --cached --submodule=log --; echo $?`
>
> This shell script will reproduce the bug:
>
> ```shell
> #! /bin/sh
>
> set -x
>
> (mkdir sm; cd sm; git init .; git commit --allow-empty -m 'initial')
> mkdir test
> cd test
> git init .
> git commit --allow-empty -m 'initial'
> git submodule init
> git -c protocol.file.allow=always submodule add ../sm
> git add .gitmodules sm
> git commit -m 'add submodule sm'
> (cd sm; echo "hello" >greeting; git add greeting; git commit -m 'add greeting')
> git add sm
> # This exit code is correct:
> git diff --quiet --cached --submodule=short --; echo $?
> # This exit code is wrong:
> git diff --quiet --cached --submodule=log --; echo $?
> ```

Very helpful, thank you!

The misbehavior occurs with --exit-code instead of --quiet.  And with
--submodule=diff.

> What did you expect to happen? (Expected behavior)
>
> The output of this "git diff" command should be `1`:
> ```
> git diff --quiet --cached --submodule=log --; echo $?
> ```
>
> What happened instead? (Actual behavior)
>
> The output is `0`.  The output is correct if the `--submodule=log`
> option is omitted.
>
> ```
> % git diff --quiet --cached --submodule=log --; echo $?
> 0
> % git diff --quiet --cached --submodule=short --; echo $?
> 1
> ```
>
> Anything else you want to add:
>
> I believe this bug was introduced in git 2.46.0 or shortly before.

Bisects to d7b97b7185 (diff: let external diffs report that changes are
uninteresting, 2024-06-09).

So enabling diff_from_contents breaks the exit code of submodule diffs?
Then the options -b/-w/... and --ignore-matching-lines breaks it as
well, as they set this option, too.

I guess we have to do something like this, plus add a ton of tests to
cover the option combinations:

---
 diff.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/diff.c b/diff.c
index 4035a9374d..bc2e559ce9 100644
--- a/diff.c
+++ b/diff.c
@@ -3565,6 +3565,7 @@ static void builtin_diff(const char *name_a,
 		show_submodule_diff_summary(o, one->path ? one->path : two->path,
 				&one->oid, &two->oid,
 				two->dirty_submodule);
+		o->found_changes = 1;
 		return;
 	} else if (o->submodule_format == DIFF_SUBMODULE_INLINE_DIFF &&
 		   (!one->mode || S_ISGITLINK(one->mode)) &&
@@ -3573,6 +3574,7 @@ static void builtin_diff(const char *name_a,
 		show_submodule_inline_diff(o, one->path ? one->path : two->path,
 				&one->oid, &two->oid,
 				two->dirty_submodule);
+		o->found_changes = 1;
 		return;
 	}

--
2.46.0


      reply	other threads:[~2024-09-03 22:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-03 14:38 Bug in "git diff" exit code with submodule and `--submodule=log` David Hull
2024-09-03 22:14 ` René Scharfe [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=73fc18f3-9d2f-43fe-b0a1-2f3680f09ce6@web.de \
    --to=l.s.r@web.de \
    --cc=david.hull@friendbuy.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).