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/20210316155829.31242-2-avarab@gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Mar 21, 2021 at 23:36 UTC 2be927f3d1c64217ac5f4d3139ad73c1f59c173b
1 file changed +55
t/t4053-diff-no-index.sh
+55
@@ -149,4 +149,59 @@ test_expect_success 'diff --no-index allows external diff' '
149 test_cmp expect actual
150 '
151
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 +
207 test_done