3 test_description
='Run "stg diff"'
7 echo "*.diff" >> .git
/info
/exclude
9 test_expect_success
'Diff with no StGit data' '
10 test -z "$(stg diff)" &&
11 test -z "$(stg diff --stat)"
14 test_expect_success
'Make some local changes' '
15 echo foo >> foo.txt &&
19 test_expect_success
'Diff with some local changes' '
20 stg diff > add-foo.diff &&
21 head -n1 add-foo.diff | grep -E "^diff --git a/foo.txt b/foo.txt" &&
22 tail -n1 add-foo.diff | grep -E "\+foo"
25 cat > expected-add-foo-stat.
diff <<EOF
27 1 file changed, 1 insertion(+)
28 create mode 100644 foo.txt
31 test_expect_success
'Diff stat with some local changes' '
32 stg diff --stat > add-foo-stat.diff &&
33 test_cmp add-foo-stat.diff expected-add-foo-stat.diff
36 test_expect_success
'Diff with bad diff-opts' '
37 command_error stg diff --diff-opts=--bad-diff-opt
40 test_expect_success
'Initialize StGit stuff' '
45 test_expect_success
'Diff with some local changes' '
46 stg diff > add-foo2.diff &&
47 test_cmp add-foo.diff add-foo2.diff
50 test_expect_success
'Refresh patch' '
54 test_expect_success
'Diff with no local changes' '
58 test_expect_success
'Add more patches' '
59 echo bar >> bar.txt &&
61 stg diff > bar.diff &&
62 stg diff --stat > bar-stat.diff &&
66 echo baz >> dir0/dir1/baz.txt &&
68 stg add bar.txt dir0/dir1/baz.txt &&
71 echo foo2 >> foo.txt &&
72 echo bar2 >> bar.txt &&
73 echo baz2 >> dir0/dir1/baz.txt &&
78 test_expect_success
'Diff revs parent-child' '
79 stg diff -r foo..bar > foo-bar.diff &&
80 test_cmp foo-bar.diff bar.diff &&
81 stg diff -r foo..bar --stat > foo-bar-stat.diff &&
82 test_cmp foo-bar-stat.diff bar-stat.diff
85 test_expect_success
'Diff invalid rev patch name' '
86 command_error stg diff -r foo..bad-name 2>err &&
87 grep -e "bad-name: Unknown patch or revision name" err
90 test_expect_success
'Diff invalid rev too many ..' '
91 command_error stg diff -r foo..bar..baz 2>err &&
92 grep -e "incorrect parameters to -r" err
95 test_expect_success
'Diff invalid rev no rev1' '
96 command_error stg diff -r ..baz 2>err &&
97 grep -e "incorrect parameters to -r" err
100 cat > expected-bar-head-stat.
diff <<EOF
102 dir0/dir1/baz.txt | 2 ++
104 3 files changed, 5 insertions(+)
105 create mode 100644 dir0/dir1/baz.txt
108 test_expect_success
'Diff range just rev1' '
109 stg diff -r bar.. > bar-head.diff &&
110 stg diff -r bar.. --stat > bar-head-stat.diff &&
111 test_cmp bar-head-stat.diff expected-bar-head-stat.diff &&
112 stg diff -r bar..p4 > bar-p4.diff &&
113 test_cmp bar-head.diff bar-p4.diff &&
114 stg diff -r bar > bar-only.diff &&
115 test_cmp bar-head.diff bar-only.diff
118 test_expect_success
'Diff range with path' '
119 stg diff -r bar..p4 dir0 > bar-p4-dir0.diff &&
120 grep -e "dir0/dir1/baz.txt" bar-p4-dir0.diff &&
121 test $(grep -c -E "foo\.txt|bar\.txt" bar-p4-dir0.diff) = 0
124 test_expect_success
'Diff from dir' '
125 echo foo3 >> foo.txt &&
126 echo bar3 >> bar.txt &&
127 stg diff > threes.diff &&
128 stg diff bar.txt > threes-bar.diff &&
131 stg diff > threes2.diff &&
132 test_cmp ../threes.diff threes2.diff &&
133 stg diff ../bar.txt > threes-bar2.diff &&
134 test_cmp ../threes-bar.diff threes-bar2.diff &&
135 test -z "$(stg diff dir1/baz.txt)"
139 test_expect_success
'Refresh changes' '
144 test_expect_success
'Binary diff' '
145 printf "\000\001\002\003" > num.bin &&
147 stg diff > num.diff &&
148 grep -e "Binary files /dev/null and b/num.bin differ" num.diff
151 test_expect_success
'Binary diff with user --binary' '
152 stg diff -O--binary > num-binary.diff &&
153 grep -e "GIT binary patch" num-binary.diff
156 cat > expected-num-stat.
diff <<EOF
157 num.bin | Bin 0 -> 4 bytes
158 1 file changed, 0 insertions(+), 0 deletions(-)
159 create mode 100644 num.bin
162 test_expect_success
'Binary diff stat' '
163 stg diff --stat > num-stat.diff &&
164 test_cmp num-stat.diff expected-num-stat.diff
167 test_expect_success
'Refresh binary' '
172 test_expect_success
'Binary diff range' '
173 stg diff -r p5..p6 > num2.diff &&
174 test_cmp num.diff num2.diff
177 test_expect_success
'Binary diff range with --binary' '
178 stg diff -r p5..p6 --diff-opts=--binary > num-binary2.diff &&
179 test_cmp num-binary.diff num-binary2.diff