add a test for diffing binary files; got diff behaves like 'diff -a'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
diff --git a/regress/cmdline/diff.sh b/regress/cmdline/diff.sh
index 4c4531a..40f48b0 100755
--- a/regress/cmdline/diff.sh
+++ b/regress/cmdline/diff.sh
@@ -583,6 +583,65 @@ test_diff_symlinks_in_repo() {
test_done "$testroot" "$ret"
}
+test_diff_binary_files() {
+ local testroot=`test_init diff_binary_files`
+ local head_rev=`git_show_head $testroot/repo`
+
+ got checkout $testroot/repo $testroot/wt > /dev/null
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ printf '\377\377\0\0\377\377\0\0' > $testroot/wt/foo
+ (cd $testroot/wt && got add foo >/dev/null)
+
+ echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
+ echo 'blob - /dev/null' >> $testroot/stdout.expected
+ echo 'file + foo' >> $testroot/stdout.expected
+ echo '--- foo' >> $testroot/stdout.expected
+ echo '+++ foo' >> $testroot/stdout.expected
+ echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
+ printf '+\377\377\0\0\377\377\0\0\n' >> $testroot/stdout.expected
+ echo '\\ No newline at end of file' >> $testroot/stdout.expected
+
+ (cd $testroot/wt && got diff > $testroot/stdout)
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -a -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/wt && got commit -m 'add binary file' > /dev/null)
+ local head_rev=`git_show_head $testroot/repo`
+
+ printf '\377\200\0\0\377\200\0\0' > $testroot/wt/foo
+
+ echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
+ echo -n 'blob - ' >> $testroot/stdout.expected
+ got tree -r $testroot/repo -i | grep 'foo$' | cut -d' ' -f 1 \
+ >> $testroot/stdout.expected
+ echo 'file + foo' >> $testroot/stdout.expected
+ echo '--- foo' >> $testroot/stdout.expected
+ echo '+++ foo' >> $testroot/stdout.expected
+ echo '@@ -1 +1 @@' >> $testroot/stdout.expected
+ printf '-\377\377\0\0\377\377\0\0\n' >> $testroot/stdout.expected
+ echo '\\ No newline at end of file' >> $testroot/stdout.expected
+ printf '+\377\200\0\0\377\200\0\0\n' >> $testroot/stdout.expected
+ echo '\\ No newline at end of file' >> $testroot/stdout.expected
+
+ (cd $testroot/wt && got diff > $testroot/stdout)
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -a -u $testroot/stdout.expected $testroot/stdout
+ fi
+ test_done "$testroot" "$ret"
+}
+
test_parseargs "$@"
run_test test_diff_basic
run_test test_diff_shows_conflict
@@ -592,3 +651,4 @@ run_test test_diff_ignore_whitespace
run_test test_diff_submodule_of_same_repo
run_test test_diff_symlinks_in_work_tree
run_test test_diff_symlinks_in_repo
+run_test test_diff_binary_files