Restore `stg sink --nopush` capability
[stgit.git] / t / t3600-fold.sh
blobcebb2badcaaa4383af6f77a1c2c61017ecad7a94
1 #!/bin/sh
3 test_description='Test the fold command.'
5 . ./test-lib.sh
7 test_expect_success 'Initialize StGit repository' '
8 stg init &&
9 echo hello > foo.txt &&
10 git add foo.txt &&
11 git commit -m "add foo.txt" &&
12 echo "preface" > foo.txt &&
13 echo "hello" >> foo.txt &&
14 git diff > threeway.diff &&
15 git checkout foo.txt &&
16 stg new -m p1 &&
17 echo "hello" > foo.txt &&
18 echo "from p1" >> foo.txt &&
19 stg refresh &&
20 echo "hello" > foo.txt &&
21 echo "from p1" >> foo.txt &&
22 echo "and fold1" >> foo.txt &&
23 git diff > fold1.diff &&
24 git checkout foo.txt
27 test_expect_success 'Attempt fold more than one patch' '
28 command_error stg fold fold1.diff fold2.diff 2>&1 |
29 grep -e "incorrect number of arguments"
32 test_expect_success 'Attempt fold with local changes' '
33 echo "hello dirty" > foo.txt &&
34 test_when_finished "stg reset --hard" &&
35 command_error stg fold fold1.diff 2>&1 |
36 grep -e "local changes in the tree"
39 test_expect_success 'Attempt fold with non-existant patch file' '
40 command_error stg fold non-existant.diff 2>&1 |
41 grep "No such file"
44 test_expect_success 'Attempt fold with no applied patches' '
45 stg pop -a &&
46 test_when_finished "stg push -a" &&
47 command_error stg fold fold1.diff 2>&1 |
48 grep "No patches applied"
51 test_expect_success 'Fold a patch file' '
52 stg fold fold1.diff &&
53 test_when_finished "stg reset --hard" &&
54 test "hello from p1 and fold1" = "$(echo $(cat foo.txt))" &&
55 stg status --porcelain foo.txt | grep -e "M foo.txt"
58 test_expect_success 'Fold a patch from stdin' '
59 cat fold1.diff | stg fold &&
60 test_when_finished "stg reset --hard" &&
61 test "hello from p1 and fold1" = "$(echo $(cat foo.txt))" &&
62 stg status --porcelain foo.txt | grep -e "M foo.txt"
65 test_expect_success 'Threeway fold' '
66 stg fold --threeway threeway.diff &&
67 test_when_finished "stg reset --hard" &&
68 test "preface hello from p1" = "$(echo $(cat foo.txt))" &&
69 stg status --porcelain foo.txt | grep -e "M foo.txt"
72 test_expect_success 'Attempt to fold conflicting patch' '
73 stg new -m p2 &&
74 test_when_finished "stg delete p2" &&
75 echo "hello" > foo.txt &&
76 echo "from p2" >> foo.txt &&
77 stg refresh &&
78 command_error stg fold fold1.diff 2>&1 |
79 grep "Patch does not apply cleanly" &&
80 test -z "$(echo $(stg status --porcelain foo.txt))"
81 test ! -e foo.txt.rej
84 test_expect_success 'Attempt to fold conflicting patch with rejects' '
85 stg new -m p2 &&
86 echo "hello" > foo.txt &&
87 echo "from p2" >> foo.txt &&
88 stg refresh &&
89 command_error stg fold --reject fold1.diff 2>&1 |
90 grep "Patch does not apply cleanly" &&
91 test -z "$(echo $(stg status --porcelain foo.txt))" &&
92 test -e foo.txt.rej &&
93 rm foo.txt.rej
96 test_expect_success 'Attempt to fold conflicting patch with -C0' '
97 stg fold -C0 --reject fold1.diff &&
98 stg status --porcelain foo.txt | grep -e "M foo.txt" &&
99 test "$(tail -n 1 foo.txt)" = "and fold1" &&
100 git reset -- foo.txt &&
101 git checkout foo.txt
104 test_expect_success 'Fold with base' '
105 stg fold --base p1 threeway.diff &&
106 test "preface hello from p2" = "$(echo $(cat foo.txt))" &&
107 stg status --porcelain foo.txt | grep -e "M foo.txt"
110 test_done