# Bug report: Undocumented interaction of --exit-code and --ignore-space-change for file move

3 messages from 2024-09-23 to 2024-09-23. Participants: Ian Turner, René Scharfe, Junio C Hamano.
Thread: https://gitlist.dev/t/62175

## Ian Turner, 2024-09-23 16:29

Subject: Bug report: Undocumented interaction of --exit-code and --ignore-space-change for file move
Message-ID: <d8512f2b-400f-4daa-a59f-5d10d4fc3840@vectro.org>
URL: https://gitlist.dev/e/d8512f2b-400f-4daa-a59f-5d10d4fc3840%40vectro.org

```
Hi all,

I noticed that there an undocumented interaction of the --exit-code and 
--ignore-space-change flags to git diff, when the diff only contains 
file moves. Specifically, --ignore-space-change will cause git diff to 
return a zero exit code in this situation.

I am not sure if the problem is with the command behavior, or with the 
documentation.

STEPS TO REPRODUCE:

git init
echo foo > a.txt
git add a.txt
git commit -m "A"
git mv a.txt b.txt
git commit -m "B"
git diff --exit-code HEAD~1..HEAD # returns exit code 1
git diff --exit-code --ignore-space-change HEAD~1..HEAD # returns exit 
status 0

EXPECTED BEHAVIOR:

Both of the last two commands above should return nonzero exit status.

WORKAROUND:

As one might expect --no-renames undoes this behavior, although it also 
changes the diff output if not using --quiet:

git diff --exit-code --ignore-space-change --no-renames HEAD~1..HEAD # 
returns exit status 1

OTHER INFO:

Tested this on git 2.39.2 and git 2.41.0, both on Linux.

Regards,

Ian Turner


```

## René Scharfe, 2024-09-23 18:08

Subject: Re: Bug report: Undocumented interaction of --exit-code and --ignore-space-change for file move
Message-ID: <2c3472d4-ad40-4636-9840-51fa97bca02b@web.de>
URL: https://gitlist.dev/e/2c3472d4-ad40-4636-9840-51fa97bca02b%40web.de
In-Reply-To: <d8512f2b-400f-4daa-a59f-5d10d4fc3840@vectro.org>

```
Am 23.09.24 um 18:29 schrieb Ian Turner:
> I noticed that there an undocumented interaction of the --exit-code
> and --ignore-space-change flags to git diff, when the diff only
> contains file moves. Specifically, --ignore-space-change will cause
> git diff to return a zero exit code in this situation.
>
> I am not sure if the problem is with the command behavior, or with
> the documentation.
>
> STEPS TO REPRODUCE:
>
> git init
> echo foo > a.txt
> git add a.txt
> git commit -m "A"
> git mv a.txt b.txt
> git commit -m "B"
> git diff --exit-code HEAD~1..HEAD # returns exit code 1
> git diff --exit-code --ignore-space-change HEAD~1..HEAD # returns exit status 0
>
> EXPECTED BEHAVIOR:
>
> Both of the last two commands above should return nonzero exit status.
>
> WORKAROUND:
>
> As one might expect --no-renames undoes this behavior, although it
> also changes the diff output if not using --quiet:
>
> git diff --exit-code --ignore-space-change --no-renames HEAD~1..HEAD # returns exit status 1
>
> OTHER INFO:
>
> Tested this on git 2.39.2 and git 2.41.0, both on Linux.

Thank you for the report!  It's a known bug in the code.

d7b97b7185 (diff: let external diffs report that changes are
uninteresting, 2024-06-09) exposed it more widely, unfortunately,
causing v2.46.0 and up to report the wrong exit code even without
--ignore-space-change.

87cf96094a (diff: report copies and renames as changes in
run_diff_cmd(), 2024-09-08) fixes it, but it's not in any release, yet.

René


```

## Junio C Hamano, 2024-09-23 22:32

Subject: Re: Bug report: Undocumented interaction of --exit-code and --ignore-space-change for file move
Message-ID: <xmqqzfnyvw54.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqzfnyvw54.fsf%40gitster.g
In-Reply-To: <2c3472d4-ad40-4636-9840-51fa97bca02b@web.de>

```
René Scharfe <l.s.r@web.de> writes:

> 87cf96094a (diff: report copies and renames as changes in
> run_diff_cmd(), 2024-09-08) fixes it, but it's not in any release, yet.

Thanks.

It should first appear in Git 2.46.2 and would be in Git 2.47.

```
