Skip to contentSkip to conversation

Test case for "git diff" outside a git repo

PATCH In review Steven Grimm 3 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Test case for "git diff" outside a git repo

---
git-diff --quiet is pretty broken right now. If you do "strace git diff --quiet file1 file2" you will see that it never calls open() on either file! And it always returns a zero exit code whether or not the files are different.

I'm trying to follow the code to figure out what's going on, but meanwhile, here's a test case. Perhaps someone more familiar with the diff code will beat me to a fix.

 t/t4021-diff-norepo.sh |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)
 create mode 100755 t/t4021-diff-norepo.sh
t/t4021-diff-norepo.sh new file +26 -0
new file mode 100755
index 0000000..dfee3d7
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+test_description='test git diff outside a repo'
+
+. ./test-lib.sh
+
+rm -rf .git
+
+test_expect_success setup '
+
+	echo content1 >file1a &&
+	echo content1 >file1b &&
+	echo content2 >file2
+'
+
+test_expect_success 'zero return value with --quiet for different files' '
+
+	git diff --quiet file1a file2
+'
+
+test_expect_success 'nonzero return value with --quiet for identical files' '
+
+	! git diff --quiet file1a file1b >/dev/null
+'
+
+test_done
Signature · 1 line
1.5.3.rc2.4.g726f9
#1 lore raw
Quoted 10 lines · Junio C Hamano
Quoted 8 lines · Steven Grimm

---
git-diff --quiet is pretty broken right now. If you do "strace git diff --quiet file1 file2" you will see that it never calls open() on either file! And it always returns a zero exit code whether or not the files are different.

Quoted 3 lines
Quoted 3 lines

I'm trying to follow the code to figure out what's going on, but meanwhile, here's a test case. Perhaps someone more familiar with the diff code will beat me to a fix.

The code to do "untracked diff" is an ugly stepchild and not really part of git-diff proper. In fact, --quiet also is an afterthought and I would not be too surprised if the "untracked diff" code does not work with it.

Quoted 5 lines
Quoted 5 lines
t/t4021-diff-norepo.sh new file +0 -0
new file mode 100755
index 0000000..dfee3d7
Quoted 8 lines

t/t4021-diff-norepo.sh line 7

Quoted 8 lines
t/t4021-diff-norepo.sh new file +7 -0
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+test_description='test git diff outside a repo'
+
+. ./test-lib.sh
+
+rm -rf .git

Unless you are testing the t/ directory and git.git suite from a tarball, the only effect of this is to make t/trash controlled by its ../../.git repository (i.e. the git.git repository). You are still inside a git repository.

#2 lore raw

Hi,

Quoted 12 lines · Junio C Hamano
Quoted 10 lines · Junio C Hamano
Quoted 8 lines · Steven Grimm

---
git-diff --quiet is pretty broken right now. If you do "strace git diff --quiet file1 file2" you will see that it never calls open() on either file! And it always returns a zero exit code whether or not the files are different.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

I'm trying to follow the code to figure out what's going on, but meanwhile, here's a test case. Perhaps someone more familiar with the diff code will beat me to a fix.

The code to do "untracked diff" is an ugly stepchild and not really part of git-diff proper. In fact, --quiet also is an afterthought and I would not be too surprised if the "untracked diff" code does not work with it.

Not that ugly, mind you. Every third day or so I congratulate myself for having "git diff --color-words" or "git diff -M", without having to suffer initialising a git repository.

But yes, I agree, the --quiet code came after the --no-index code, and thus it is well possible that the latter ignores the former.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
t/t4021-diff-norepo.sh new file +4 -0
new file mode 100755
index 0000000..dfee3d7
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+test_description='test git diff outside a repo'
+
Quoted 8 lines
Quoted 3 lines

t/t4021-diff-norepo.sh line 7

Quoted 3 lines
t/t4021-diff-norepo.sh new file +3 -0
+. ./test-lib.sh
+
+rm -rf .git

Unless you are testing the t/ directory and git.git suite from a tarball, the only effect of this is to make t/trash controlled by its ../../.git repository (i.e. the git.git repository). You are still inside a git repository.

Yes, this is no good.

However, you can force --no-index. IMHO that is the way to go.

Ciao,
Dscho