Add `stg import --message-id` option
[stgit.git] / t / t0006-patches.sh
blob01aff93a8027e35fbf07043ea1771e47958c1872
1 #!/bin/sh
3 test_description='Test stg patches'
5 . ./test-lib.sh
7 test_expect_success 'Create some patches' '
8 echo "*.log" >> .git/info/exclude &&
9 stg init &&
10 mkdir -p dir0/dir1 &&
11 touch even.txt &&
12 touch dir0/dir1/odd.txt &&
13 git add even.txt dir0/dir1/odd.txt &&
14 git commit -m "Add even and odd" &&
15 echo "zero" > even.txt &&
16 echo "one" > dir0/dir1/odd.txt &&
17 stg new -m "p0 message" p0 &&
18 stg refresh &&
19 echo "two" >> even.txt && stg new -m "p1 message" p1 && stg refresh &&
20 echo "three" >> dir0/dir1/odd.txt && stg new -m "p2 message" p2 && stg refresh &&
21 echo "four" >> even.txt && stg new -m "p3 message" p3 && stg refresh &&
22 echo "five" >> dir0/dir1/odd.txt && stg new -m "p4 message" p4 && stg refresh
25 test_expect_success 'No modifications and no file args' '
26 command_error stg patches 2>&1 |
27 grep -e "No files specified or no local changes"
30 cat > expected-evens.log <<EOF
34 EOF
36 cat > expected-odds.log << EOF
40 EOF
42 test_expect_success 'Modifications and no file args' '
43 echo "six" >> even.txt &&
44 stg patches > mod-no-files.log &&
45 test_cmp mod-no-files.log expected-evens.log &&
46 git checkout even.txt
49 test_expect_success 'No patches applied' '
50 stg pop -a &&
51 command_error stg patches even.txt 2>&1 |
52 grep -e "No patches applied"
55 test_expect_success 'Patches relative to dir' '
56 stg push -a &&
58 cd dir0 &&
59 stg patches dir1/odd.txt > relative-odd.log &&
60 test_cmp relative-odd.log ../expected-odds.log &&
61 echo "seven" > dir1/odd.txt &&
62 stg patches > relative-odd-mod.log &&
63 test_cmp relative-odd-mod.log ../expected-odds.log &&
64 stg patches ../even.txt > relative-even.log &&
65 test_cmp relative-even.log ../expected-evens.log &&
66 git checkout dir1/odd.txt &&
67 echo "six" >> ../even.txt &&
68 stg patches > relative-even-mod.log &&
69 test_cmp relative-even-mod.log ../expected-evens.log &&
70 git checkout ../even.txt
74 test_expect_success 'With diff output' '
75 stg patches --diff even.txt > even-diff.log &&
76 test $(cat even-diff.log | grep -c -E b'\\\'') = "0" &&
77 test $(cat even-diff.log | grep -c -E "\+(zero|two|four)") = "3" &&
78 test $(cat even-diff.log | grep -c -E "\+(one|three|five)") = "0" &&
79 test $(cat even-diff.log | grep -c -E "p(0|1|3) message") = "3"
82 test_done