BUG: git diff --name-only ignores --ignore-*
- From
- Stefan Hoffmeister <stefan.hoffmeister@gmail.com>
- Date
- Aug 26, 2021, 06:53 UTC
- Message-ID
- <CALhB_QNZJtUoSEE==xBoX3cTxE4duB+QqsSzuyeY7JFMh7sKhQ@mail.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