diff tests: don't ignore "git diff" exit code in "read" loop
Fix a test pattern that originated in f1af60bdba
(Support 'diff=pgm'
attribute, 2007-04-22) so that we'll stop using "git diff" on the
left-hand-side of a pipe, and thus ignoring its exit code.
Rather than use intermediate files let's rewrite these tests to a much
simpler but more exhaustive "test_tmp" where we'll ignore certain
fields in the output.
Note that this is not a faithful conversion of the previous
"read/test" in some cases, as we were ignoring more fields there than
we strictly needed to. Now we'll "test_cmp" everything we can, and
only ignore the likes of paths to $TEMPDIR etc.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
d239ef1cba
commit
5476bdf0e8
@ -24,16 +24,12 @@ test_expect_success setup '
|
||||
'
|
||||
|
||||
test_expect_success 'GIT_EXTERNAL_DIFF environment' '
|
||||
|
||||
GIT_EXTERNAL_DIFF=echo git diff | {
|
||||
read path oldfile oldhex oldmode newfile newhex newmode &&
|
||||
test "z$path" = zfile &&
|
||||
test "z$oldmode" = z100644 &&
|
||||
test "z$newhex" = "z$ZERO_OID" &&
|
||||
test "z$newmode" = z100644 &&
|
||||
oh=$(git rev-parse --verify HEAD:file) &&
|
||||
test "z$oh" = "z$oldhex"
|
||||
}
|
||||
cat >expect <<-EOF &&
|
||||
file $(git rev-parse --verify HEAD:file) 100644 file $(test_oid zero) 100644
|
||||
EOF
|
||||
GIT_EXTERNAL_DIFF=echo git diff >out &&
|
||||
cut -d" " -f1,3- <out >actual &&
|
||||
test_cmp expect actual
|
||||
|
||||
'
|
||||
|
||||
@ -52,15 +48,14 @@ test_expect_success 'GIT_EXTERNAL_DIFF environment and --no-ext-diff' '
|
||||
test_expect_success SYMLINKS 'typechange diff' '
|
||||
rm -f file &&
|
||||
ln -s elif file &&
|
||||
GIT_EXTERNAL_DIFF=echo git diff | {
|
||||
read path oldfile oldhex oldmode newfile newhex newmode &&
|
||||
test "z$path" = zfile &&
|
||||
test "z$oldmode" = z100644 &&
|
||||
test "z$newhex" = "z$ZERO_OID" &&
|
||||
test "z$newmode" = z120000 &&
|
||||
oh=$(git rev-parse --verify HEAD:file) &&
|
||||
test "z$oh" = "z$oldhex"
|
||||
} &&
|
||||
|
||||
cat >expect <<-EOF &&
|
||||
file $(git rev-parse --verify HEAD:file) 100644 $(test_oid zero) 120000
|
||||
EOF
|
||||
GIT_EXTERNAL_DIFF=echo git diff >out &&
|
||||
cut -d" " -f1,3-4,6- <out >actual &&
|
||||
test_cmp expect actual &&
|
||||
|
||||
GIT_EXTERNAL_DIFF=echo git diff --no-ext-diff >actual &&
|
||||
git diff >expect &&
|
||||
test_cmp expect actual
|
||||
@ -70,15 +65,13 @@ test_expect_success 'diff.external' '
|
||||
git reset --hard &&
|
||||
echo third >file &&
|
||||
test_config diff.external echo &&
|
||||
git diff | {
|
||||
read path oldfile oldhex oldmode newfile newhex newmode &&
|
||||
test "z$path" = zfile &&
|
||||
test "z$oldmode" = z100644 &&
|
||||
test "z$newhex" = "z$ZERO_OID" &&
|
||||
test "z$newmode" = z100644 &&
|
||||
oh=$(git rev-parse --verify HEAD:file) &&
|
||||
test "z$oh" = "z$oldhex"
|
||||
}
|
||||
|
||||
cat >expect <<-EOF &&
|
||||
file $(git rev-parse --verify HEAD:file) 100644 $(test_oid zero) 100644
|
||||
EOF
|
||||
git diff >out &&
|
||||
cut -d" " -f1,3-4,6- <out >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success !SANITIZE_LEAK 'diff.external should apply only to diff' '
|
||||
@ -101,16 +94,12 @@ test_expect_success 'diff attribute' '
|
||||
|
||||
echo >.gitattributes "file diff=parrot" &&
|
||||
|
||||
git diff | {
|
||||
read path oldfile oldhex oldmode newfile newhex newmode &&
|
||||
test "z$path" = zfile &&
|
||||
test "z$oldmode" = z100644 &&
|
||||
test "z$newhex" = "z$ZERO_OID" &&
|
||||
test "z$newmode" = z100644 &&
|
||||
oh=$(git rev-parse --verify HEAD:file) &&
|
||||
test "z$oh" = "z$oldhex"
|
||||
}
|
||||
|
||||
cat >expect <<-EOF &&
|
||||
file $(git rev-parse --verify HEAD:file) 100644 $(test_oid zero) 100644
|
||||
EOF
|
||||
git diff >out &&
|
||||
cut -d" " -f1,3-4,6- <out >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success !SANITIZE_LEAK 'diff attribute should apply only to diff' '
|
||||
@ -132,16 +121,12 @@ test_expect_success 'diff attribute' '
|
||||
|
||||
echo >.gitattributes "file diff=color" &&
|
||||
|
||||
git diff | {
|
||||
read path oldfile oldhex oldmode newfile newhex newmode &&
|
||||
test "z$path" = zfile &&
|
||||
test "z$oldmode" = z100644 &&
|
||||
test "z$newhex" = "z$ZERO_OID" &&
|
||||
test "z$newmode" = z100644 &&
|
||||
oh=$(git rev-parse --verify HEAD:file) &&
|
||||
test "z$oh" = "z$oldhex"
|
||||
}
|
||||
|
||||
cat >expect <<-EOF &&
|
||||
file $(git rev-parse --verify HEAD:file) 100644 $(test_oid zero) 100644
|
||||
EOF
|
||||
git diff >out &&
|
||||
cut -d" " -f1,3-4,6- <out >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success !SANITIZE_LEAK 'diff attribute should apply only to diff' '
|
||||
@ -159,14 +144,26 @@ test_expect_success 'diff attribute and --no-ext-diff' '
|
||||
test_expect_success 'GIT_EXTERNAL_DIFF trumps diff.external' '
|
||||
>.gitattributes &&
|
||||
test_config diff.external "echo ext-global" &&
|
||||
GIT_EXTERNAL_DIFF="echo ext-env" git diff | grep ext-env
|
||||
|
||||
cat >expect <<-EOF &&
|
||||
ext-env file $(git rev-parse --verify HEAD:file) 100644 file $(test_oid zero) 100644
|
||||
EOF
|
||||
GIT_EXTERNAL_DIFF="echo ext-env" git diff >out &&
|
||||
cut -d" " -f1-2,4- <out >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'attributes trump GIT_EXTERNAL_DIFF and diff.external' '
|
||||
test_config diff.foo.command "echo ext-attribute" &&
|
||||
test_config diff.external "echo ext-global" &&
|
||||
echo "file diff=foo" >.gitattributes &&
|
||||
GIT_EXTERNAL_DIFF="echo ext-env" git diff | grep ext-attribute
|
||||
|
||||
cat >expect <<-EOF &&
|
||||
ext-attribute file $(git rev-parse --verify HEAD:file) 100644 file $(test_oid zero) 100644
|
||||
EOF
|
||||
GIT_EXTERNAL_DIFF="echo ext-env" git diff >out &&
|
||||
cut -d" " -f1-2,4- <out >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'no diff with -diff' '
|
||||
@ -212,7 +209,12 @@ test_expect_success 'GIT_EXTERNAL_DIFF generates pretty paths' '
|
||||
touch file.ext &&
|
||||
git add file.ext &&
|
||||
echo with extension > file.ext &&
|
||||
GIT_EXTERNAL_DIFF=echo git diff file.ext | grep ......_file\.ext &&
|
||||
|
||||
cat >expect <<-EOF &&
|
||||
file.ext file $(git rev-parse --verify HEAD:file) 100644 file.ext $(test_oid zero) 100644
|
||||
EOF
|
||||
GIT_EXTERNAL_DIFF=echo git diff file.ext >out &&
|
||||
cut -d" " -f1,3- <out >actual &&
|
||||
git update-index --force-remove file.ext &&
|
||||
rm file.ext
|
||||
'
|
||||
|
Loading…
Reference in New Issue
Block a user