Tests redirect to err file when grepping stderr
[stgit.git] / t / t2000-sync.sh
bloba1d3f8acb7dc573904f0de75b25c583c1ff78fe3
1 #!/bin/sh
3 # Copyright (c) 2006 Catalin Marinas
6 test_description='Test the sync command.'
8 . ./test-lib.sh
10 test_expect_success \
11 'Initialize the StGit repository' \
13 stg init
16 test_expect_success \
17 'Create some patches' \
19 stg new p1 -m p1 &&
20 echo foo1 > foo1.txt &&
21 stg add foo1.txt &&
22 stg refresh &&
23 stg new p2 -m p2 &&
24 echo foo2 > foo2.txt &&
25 stg add foo2.txt &&
26 stg refresh &&
27 stg new p3 -m p3 &&
28 echo foo3 > foo3.txt &&
29 stg add foo3.txt &&
30 stg refresh &&
31 stg export &&
32 stg pop &&
33 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2" ] &&
34 [ "$(echo $(stg series --unapplied --noprefix))" = "p3" ]
37 test_expect_success \
38 'Create a branch with empty patches' \
40 stg branch -c foo {base} &&
41 stg new p1 -m p1 &&
42 stg new p2 -m p2 &&
43 stg new p3 -m p3 &&
44 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" ] &&
45 [ "$(echo $(stg series --unapplied --noprefix))" = "" ]
48 test_expect_success \
49 'Attempt sync with current branch' \
51 command_error stg sync -B foo 2>err &&
52 grep -e "Cannot synchronise with the current branch" err
55 test_expect_success \
56 'Attempt sync without remote branch or series' \
58 command_error stg sync -a 2>err &&
59 grep -e "No remote branch or series specified" err
62 test_expect_success \
63 'Attempt apply top patch without any applied' \
65 test_when_finished "stg goto p3" &&
66 stg pop -a &&
67 command_error stg sync -B master 2>err &&
68 grep -e "no patches applied" err
71 test_expect_success \
72 'Attempt to sync patch not in ref branch' \
74 stg new -m p4 &&
75 test_when_finished "stg delete p4" &&
76 command_error stg sync -B master 2>err &&
77 grep -e "No common patches to be synchronised" err
80 test_expect_success \
81 'Synchronise second patch with the master branch' \
83 stg sync -B master p2 &&
84 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" ] &&
85 [ "$(echo $(stg series --unapplied --noprefix))" = "" ] &&
86 test "$(cat foo2.txt)" = "foo2"
89 test_expect_success \
90 'Synchronise the first two patches with the master branch' \
92 stg sync -B master -a &&
93 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" ] &&
94 [ "$(echo $(stg series --unapplied --noprefix))" = "" ] &&
95 test "$(cat foo1.txt)" = "foo1" &&
96 test "$(cat foo2.txt)" = "foo2"
99 test_expect_success \
100 'Synchronise all the patches with the exported series' \
102 stg sync -s patches-master/series -a &&
103 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" ] &&
104 [ "$(echo $(stg series --unapplied --noprefix))" = "" ] &&
105 test "$(cat foo1.txt)" = "foo1" &&
106 test "$(cat foo2.txt)" = "foo2" &&
107 test "$(cat foo3.txt)" = "foo3"
110 test_expect_success \
111 'Modify the master patches' \
113 stg branch master &&
114 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2" ] &&
115 [ "$(echo $(stg series --unapplied --noprefix))" = "p3" ] &&
116 stg goto p1 &&
117 echo bar1 >> foo1.txt &&
118 stg refresh &&
119 stg goto p2 &&
120 echo bar2 > bar2.txt &&
121 stg add bar2.txt &&
122 stg refresh &&
123 stg goto p3 &&
124 echo bar3 >> foo3.txt &&
125 stg refresh &&
126 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" ] &&
127 [ "$(echo $(stg series --unapplied --noprefix))" = "" ] &&
128 stg export &&
129 stg branch foo
132 test_expect_success \
133 'Synchronise second patch with the master branch' \
135 stg goto p1 &&
136 stg sync -B master p2 &&
137 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2" ] &&
138 [ "$(echo $(stg series --unapplied --noprefix))" = "p3" ] &&
139 test "$(cat bar2.txt)" = "bar2"
142 test_expect_success \
143 'Synchronise the first two patches with the master branch (to fail)' \
145 conflict stg sync -B master -a
148 test_expect_success \
149 'Restore the stack status after the failed sync' \
151 [ "$(echo $(stg series --applied --noprefix))" = "p1" ] &&
152 [ "$(echo $(stg series --unapplied --noprefix))" = "p2 p3" ] &&
153 stg add --update &&
154 stg refresh &&
155 stg goto p3
156 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" ] &&
157 [ "$(echo $(stg series --unapplied --noprefix))" = "" ]
160 test_expect_success \
161 'Synchronise the third patch with the exported series (to fail)' \
163 conflict stg sync -s patches-master/series p3
166 test_expect_success \
167 'Restore the stack status after the failed sync' \
169 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" ] &&
170 [ "$(echo $(stg series --unapplied --noprefix))" = "" ] &&
171 stg add --update &&
172 stg refresh &&
173 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" ] &&
174 [ "$(echo $(stg series --unapplied --noprefix))" = "" ]
177 test_done