# BUG: git diff --name-only ignores --ignore-*

2 messages from 2021-08-26 to 2021-08-26. Participants: Stefan Hoffmeister, Junio C Hamano.
Thread: https://gitlist.dev/t/56381

## Stefan Hoffmeister, 2021-08-26 06:53

Subject: BUG: git diff --name-only ignores --ignore-*
Message-ID: <CALhB_QNZJtUoSEE==xBoX3cTxE4duB+QqsSzuyeY7JFMh7sKhQ@mail.gmail.com>
URL: https://gitlist.dev/e/CALhB_QNZJtUoSEE%3D%3DxBoX3cTxE4duB%2BQqsSzuyeY7JFMh7sKhQ%40mail.gmail.com

```
When using the --name-only option on git diff (git 2.33.0),
command-line parameters such as  --ignore-blank-lines are not
respected.

Instead, git diff behaves as if these options were not specified at all.

This is either an implementation defect, or a documentation defect,
because that (IMHO surprising) behaviour is not spelled out in
https://git-scm.com/docs/git-diff.

IMHO, this is an implementation defect, as --ignore-* is orthogonal to
--name-only. I would like to use --name-only to identify the set of
files which have only(!) --ignore-* changes (by intersecting the set
of files returned by git diff with, and without --ignore-*).

The bash script below reproduces this for --ignore-blank-lines; the
same would extend to the other --ignore-* options as well.

****************************
#!/usr/bin/env bash

set -e

GIT_REPO=repo
TEST_FILE=the_file.txt

rm -rf ./${GIT_REPO}
mkdir ${GIT_REPO}
pushd ${GIT_REPO}

git init --initial-branch=main
git config user.name "myuser"
git config user.email "myuser@example.com"

cat << EOF > ${TEST_FILE}
Hello world.
EOF

git add -A
git commit -m"Initial commit"

# add empty lines
cat << EOF >> ${TEST_FILE}


EOF

without_name_only=$(git diff --ignore-blank-lines)
echo "----
Without --name-only:
${without_name_only}"

with_name_only=$(git diff --ignore-blank-lines --name-only)
echo "----
With --name-only:
${with_name_only}"

if [[ ${without_name_only} != ${with_name_only} ]] ; then
    echo "
fail: expected same data returned
"
    exit 1
else
    echo "
pass: all good
"
    exit 0
fi

```

## Junio C Hamano, 2021-08-26 18:42

Subject: Re: BUG: git diff --name-only ignores --ignore-*
Message-ID: <xmqqwno8dp4b.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqwno8dp4b.fsf%40gitster.g
In-Reply-To: <CALhB_QNZJtUoSEE==xBoX3cTxE4duB+QqsSzuyeY7JFMh7sKhQ@mail.gmail.com>

```
Stefan Hoffmeister <stefan.hoffmeister@gmail.com> writes:

> When using the --name-only option on git diff (git 2.33.0),
> command-line parameters such as  --ignore-blank-lines are not
> respected.

I think I've seen something related this one at around

  https://lore.kernel.org/git/xmqq4kkl1atq.fsf@gitster.c.googlers.com/

(look for mention of --name-only in the message).

It would make things more expensive to make --name-only inspect
changes when these options are in effect (iow, the --name-only
currently is about "are these the same blob object?  if not, show
the path" and nothing else) but it would probably be OK, as the user
expresses their willingness to spend extra cycles by explicitly
giving --ignore-* options.


```
