Skip to content

Commit 2be927f

Browse files
avargitster
authored andcommitted
diff --no-index tests: test mode normalization
When "git diff --no-index X Y" is run the modes of the files being differ are normalized by canon_mode() in fill_filespec(). I recently broke that behavior in a patch of mine[1] which would pass all tests, or not, depending on the umask of the git.git checkout. Let's test for this explicitly. Arguably this should not be the behavior of "git diff --no-index". We aren't diffing our own objects or the index, so it might be useful to show mode differences between files. On the other hand diff(1) does not do that, and it would be needlessly distracting when e.g. diffing an extracted tar archive whose contents is the same, but whose file modes are different. 1. https://lore.kernel.org/git/[email protected]/ Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 271cb30 commit 2be927f

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

t/t4053-diff-no-index.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,59 @@ test_expect_success 'diff --no-index allows external diff' '
149149
test_cmp expect actual
150150
'
151151

152+
test_expect_success 'diff --no-index normalizes mode: no changes' '
153+
echo foo >x &&
154+
cp x y &&
155+
git diff --no-index x y >out &&
156+
test_must_be_empty out
157+
'
158+
159+
test_expect_success POSIXPERM 'diff --no-index normalizes mode: chmod +x' '
160+
chmod +x y &&
161+
cat >expected <<-\EOF &&
162+
diff --git a/x b/y
163+
old mode 100644
164+
new mode 100755
165+
EOF
166+
test_expect_code 1 git diff --no-index x y >actual &&
167+
test_cmp expected actual
168+
'
169+
170+
test_expect_success POSIXPERM 'diff --no-index normalizes: mode not like git mode' '
171+
chmod 666 x &&
172+
chmod 777 y &&
173+
cat >expected <<-\EOF &&
174+
diff --git a/x b/y
175+
old mode 100644
176+
new mode 100755
177+
EOF
178+
test_expect_code 1 git diff --no-index x y >actual &&
179+
test_cmp expected actual
180+
'
181+
182+
test_expect_success POSIXPERM,SYMLINKS 'diff --no-index normalizes: mode not like git mode (symlink)' '
183+
ln -s y z &&
184+
X_OID=$(git hash-object --stdin <x) &&
185+
Z_OID=$(printf y | git hash-object --stdin) &&
186+
cat >expected <<-EOF &&
187+
diff --git a/x b/x
188+
deleted file mode 100644
189+
index $X_OID..$ZERO_OID
190+
--- a/x
191+
+++ /dev/null
192+
@@ -1 +0,0 @@
193+
-foo
194+
diff --git a/z b/z
195+
new file mode 120000
196+
index $ZERO_OID..$Z_OID
197+
--- /dev/null
198+
+++ b/z
199+
@@ -0,0 +1 @@
200+
+y
201+
\ No newline at end of file
202+
EOF
203+
test_expect_code 1 git -c core.abbrev=no diff --no-index x z >actual &&
204+
test_cmp expected actual
205+
'
206+
152207
test_done

0 commit comments

Comments
 (0)