* BUG: git diff --name-only ignores --ignore-*
@ 2021-08-26 6:53 Stefan Hoffmeister
2021-08-26 18:42 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Stefan Hoffmeister @ 2021-08-26 6:53 UTC (permalink / raw)
To: git
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: BUG: git diff --name-only ignores --ignore-*
@ 2021-08-26 9:05 Stefan Hoffmeister
0 siblings, 0 replies; 3+ messages in thread
From: Stefan Hoffmeister @ 2021-08-26 9:05 UTC (permalink / raw)
To: stefan.hoffmeister; +Cc: git
A quick peek suggests options to tackle this:
a) by including XDF_IGNORE_BLANK_LINES as an option that also forces a
content check
b) adjusting the implementation in diff_flush to better take into
account the specified --ignore-* flags
Now, looking closely at diff_flush it would seem as if all of the
command-line options
--raw
--name-only
--name-status
might benefit from taking into account --ignore-*
So, in the end this is a matter intent and requirements - what should
happen whenever a user provided --ignore*?
From my point of view, git diff --raw, --name-only, name-status all
should honour --ignore-whitespace*, and all should also honour
--ignore-blank-lines
Below please find a patch which shows the code areas affected;
implementation quality is not acceptable as-is (logic distributed
across the function), because I'd love to get some feedback on --raw
and --name-status and the general approach.
*********************
diff --git a/diff.c b/diff.c
index a8113f1707..7b19cfa5f0 100644
--- a/diff.c
+++ b/diff.c
@@ -4645,11 +4645,13 @@ void diff_setup_done(struct diff_options *options)
/*
* Most of the time we can say "there are changes"
* only by checking if there are changed paths, but
- * --ignore-whitespace* options force us to look
- * inside contents.
+ * options
+ * --ignore-whitespace*
+ * --ignore-blank-lines
+ * force us to look inside contents.
*/
- if ((options->xdl_opts & XDF_WHITESPACE_FLAGS) ||
+ if ((options->xdl_opts & (XDF_WHITESPACE_FLAGS | XDF_IGNORE_BLANK_LINES)) ||
options->ignore_regex_nr)
options->flags.diff_from_contents = 1;
else
@@ -6408,10 +6410,10 @@ void diff_flush(struct diff_options *options)
if (!q->nr)
goto free_queue;
- if (output_format & (DIFF_FORMAT_RAW |
- DIFF_FORMAT_NAME |
+ if ((output_format & (DIFF_FORMAT_RAW |
DIFF_FORMAT_NAME_STATUS |
- DIFF_FORMAT_CHECKDIFF)) {
+ DIFF_FORMAT_CHECKDIFF)) ||
+ (output_format & DIFF_FORMAT_NAME && !options->flags.diff_from_contents)) {
for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i];
if (check_pair_status(p))
@@ -6449,9 +6451,10 @@ void diff_flush(struct diff_options *options)
separator++;
}
- if (output_format & DIFF_FORMAT_NO_OUTPUT &&
+ if ((output_format & DIFF_FORMAT_NO_OUTPUT &&
options->flags.exit_with_status &&
- options->flags.diff_from_contents) {
+ options->flags.diff_from_contents)) ||
+ (output_format & DIFF_FORMAT_NAME && options->flags.diff_from_contents) {
/*
* run diff_flush_patch for the exit status. setting
* options->file to /dev/null should be safe, because we
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-08-26 18:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-26 6:53 BUG: git diff --name-only ignores --ignore-* Stefan Hoffmeister
2021-08-26 18:42 ` Junio C Hamano
-- strict thread matches above, loose matches on Subject: below --
2021-08-26 9:05 Stefan Hoffmeister
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).