Better diagnostic for wrong branch configuration.
[stgit/ydirson.git] / t / t2000-sync.sh
blob484dbabb75702d2c38ca0b73e84c0a1f3d9930a4
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 applied))" = "p1 p2" ] &&
34 [ "$(echo $(stg unapplied))" = "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 applied))" = "p1 p2 p3" ] &&
45 [ "$(echo $(stg unapplied))" = "" ]
48 test_expect_success \
49 'Synchronise second patch with the master branch' \
51 stg sync -B master p2 &&
52 [ "$(echo $(stg applied))" = "p1 p2 p3" ] &&
53 [ "$(echo $(stg unapplied))" = "" ] &&
54 test $(cat foo2.txt) = "foo2"
57 test_expect_success \
58 'Synchronise the first two patches with the master branch' \
60 stg sync -B master -a &&
61 [ "$(echo $(stg applied))" = "p1 p2 p3" ] &&
62 [ "$(echo $(stg unapplied))" = "" ] &&
63 test $(cat foo1.txt) = "foo1" &&
64 test $(cat foo2.txt) = "foo2"
67 test_expect_success \
68 'Synchronise all the patches with the exported series' \
70 stg sync -s patches-master/series -a &&
71 [ "$(echo $(stg applied))" = "p1 p2 p3" ] &&
72 [ "$(echo $(stg unapplied))" = "" ] &&
73 test $(cat foo1.txt) = "foo1" &&
74 test $(cat foo2.txt) = "foo2" &&
75 test $(cat foo3.txt) = "foo3"
78 test_expect_success \
79 'Modify the master patches' \
81 stg branch master &&
82 [ "$(echo $(stg applied))" = "p1 p2" ] &&
83 [ "$(echo $(stg unapplied))" = "p3" ] &&
84 stg goto p1 &&
85 echo bar1 >> foo1.txt &&
86 stg refresh &&
87 stg goto p2 &&
88 echo bar2 > bar2.txt &&
89 stg add bar2.txt &&
90 stg refresh &&
91 stg goto p3 &&
92 echo bar3 >> foo3.txt &&
93 stg refresh &&
94 [ "$(echo $(stg applied))" = "p1 p2 p3" ] &&
95 [ "$(echo $(stg unapplied))" = "" ] &&
96 stg export &&
97 stg branch foo
100 test_expect_success \
101 'Synchronise second patch with the master branch' \
103 stg sync -B master p2 &&
104 [ "$(echo $(stg applied))" = "p1 p2 p3" ] &&
105 [ "$(echo $(stg unapplied))" = "" ] &&
106 test $(cat bar2.txt) = "bar2"
109 test_expect_success \
110 'Synchronise the first two patches with the master branch (to fail)' \
112 ! stg sync -B master -a
115 test_expect_success \
116 'Restore the stack status after the failed sync' \
118 [ "$(echo $(stg applied))" = "p1" ] &&
119 [ "$(echo $(stg unapplied))" = "p2 p3" ] &&
120 stg resolved -a &&
121 stg refresh &&
122 stg goto p3
123 [ "$(echo $(stg applied))" = "p1 p2 p3" ] &&
124 [ "$(echo $(stg unapplied))" = "" ]
127 test_expect_success \
128 'Synchronise the third patch with the exported series (to fail)' \
130 ! stg sync -s patches-master/series p3
133 test_expect_success \
134 'Restore the stack status after the failed sync' \
136 [ "$(echo $(stg applied))" = "p1 p2 p3" ] &&
137 [ "$(echo $(stg unapplied))" = "" ] &&
138 stg resolved -a &&
139 stg refresh &&
140 [ "$(echo $(stg applied))" = "p1 p2 p3" ] &&
141 [ "$(echo $(stg unapplied))" = "" ]
144 test_done