threads / bug / 56381

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

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

## tl;dr

2 messages between Aug 26, 2021 and Aug 26, 2021.

replies: 1people: 2as markdown or json

Stefan Hoffmeister· Aug 26, 2021, 06:53 UTC · lore

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· Aug 26, 2021, 18:42 UTC · re: Stefan Hoffmeister · lore

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

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.

← back to recent threads