3 # Copyright (c) 2006 Catalin Marinas
6 test_description
='Test the sync command.'
11 'Initialize the StGit repository' \
17 'Create some patches' \
20 echo foo1 > foo1.txt &&
24 echo foo2 > foo2.txt &&
28 echo foo3 > foo3.txt &&
33 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2" ] &&
34 [ "$(echo $(stg series --unapplied --noprefix))" = "p3" ]
38 'Create a branch with empty patches' \
40 stg branch -c foo {base} &&
44 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" ] &&
45 [ "$(echo $(stg series --unapplied --noprefix))" = "" ]
49 'Attempt sync with current branch' \
51 command_error stg sync -B foo 2>&1 |
52 grep -e "Cannot synchronise with the current branch"
56 'Attempt sync without remote branch or series' \
58 command_error stg sync -a 2>&1 |
59 grep -e "No remote branch or series specified"
63 'Attempt apply top patch without any applied' \
65 test_when_finished "stg goto p3" &&
67 command_error stg sync -B master 2>&1 |
68 grep -e "no patches applied"
72 'Attempt to sync patch not in ref branch' \
75 test_when_finished "stg delete p4" &&
76 command_error stg sync -B master 2>&1 |
77 grep -e "No common patches to be synchronised"
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"
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"
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' \
114 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2" ] &&
115 [ "$(echo $(stg series --unapplied --noprefix))" = "p3" ] &&
117 echo bar1 >> foo1.txt &&
120 echo bar2 > bar2.txt &&
124 echo bar3 >> foo3.txt &&
126 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" ] &&
127 [ "$(echo $(stg series --unapplied --noprefix))" = "" ] &&
132 test_expect_success \
133 'Synchronise second patch with the master branch' \
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" ] &&
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))" = "" ] &&
173 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" ] &&
174 [ "$(echo $(stg series --unapplied --noprefix))" = "" ]