git diff --exit-code returns 0 when binary files differ

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I've encountered an issue with `git diff --exit-code` where it returns
0 for binary files that have actual changes.

> What did you do before the bug happened? (Steps to reproduce your issue)

1. Initialize a new git repository:
```
git init
```

2. Create a binary file and commit it:
```
echo '*.bin binary' > .gitattributes
dd if=/dev/urandom of=a.bin bs=32 count=1
git add .
git commit -m 'commit'
```

3. Modify the binary file:
```
echo a > a.bin
git diff --exit-code  # says "Binary files a/a.bin and b/a.bin differ"
echo $?               # returns 0
```

> What did you expect to happen? (Expected behavior)

`git diff --exit-code` should exit with 1

> What happened instead? (Actual behavior)

`git diff --exit-code` returns 0 even when the binary file is modified.

> Anything else you want to add:

I could not find the exact condition to change exit code. In some
cases, depending on the content of the file, `git diff --exit-code`
does return 1 as expected.
I don't use an external diff tool.


[System Info]
git version:
git version 2.46.1
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
libcurl: 7.68.0
zlib: 1.2.11
uname: Linux 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29
23:14:13 UTC 2024 x86_64
compiler info: gnuc: 9.4
libc info: glibc: 2.31
$SHELL (typically, interactive shell): /bin/bash


[Enabled Hooks]


Best regards,
Kohei




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux