Add the 'sync' command
[stgit] / t / t2000-sync.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Catalin Marinas
4 #
5
6 test_description='Test the sync command.'
7
8 . ./test-lib.sh
9
10 test_expect_success \
11 'Initialize the StGIT repository' \
12 '
13 stg init
14 '
15
16 test_expect_success \
17 'Create some patches' \
18 '
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 '
34
35 test_expect_success \
36 'Create a branch with empty patches' \
37 '
38 stg branch -c foo base &&
39 stg new p1 -m p1 &&
40 stg new p2 -m p2 &&
41 stg new p3 -m p3
42 test $(stg applied -c) -eq 3
43 '
44
45 test_expect_success \
46 'Synchronise second patch with the master branch' \
47 '
48 stg sync -b master p2 &&
49 test $(stg applied -c) -eq 3 &&
50 test $(cat foo2.txt) == "foo2"
51 '
52
53 test_expect_success \
54 'Synchronise the first two patches with the master branch' \
55 '
56 stg sync -b master -a &&
57 test $(stg applied -c) -eq 3 &&
58 test $(cat foo1.txt) == "foo1" &&
59 test $(cat foo2.txt) == "foo2"
60 '
61
62 test_expect_success \
63 'Synchronise all the patches with the exported series' \
64 '
65 stg sync -s patches-master/series -a &&
66 test $(stg applied -c) -eq 3 &&
67 test $(cat foo1.txt) == "foo1" &&
68 test $(cat foo2.txt) == "foo2" &&
69 test $(cat foo3.txt) == "foo3"
70 '
71
72 test_expect_success \
73 'Modify the master patches' \
74 '
75 stg branch master &&
76 stg goto p1 &&
77 echo bar1 >> foo1.txt &&
78 stg refresh &&
79 stg goto p2 &&
80 echo bar2 > bar2.txt &&
81 stg add bar2.txt &&
82 stg refresh &&
83 stg goto p3 &&
84 echo bar3 >> foo3.txt &&
85 stg refresh &&
86 stg export &&
87 stg branch foo
88 '
89
90 test_expect_success \
91 'Synchronise second patch with the master branch' \
92 '
93 stg sync -b master p2 &&
94 test $(stg applied -c) -eq 3 &&
95 test $(cat bar2.txt) == "bar2"
96 '
97
98 test_expect_failure \
99 'Synchronise the first two patches with the master branch (to fail)' \
100 '
101 stg sync -b master -a
102 '
103
104 test_expect_success \
105 'Restore the stack status after the failed sync' \
106 '
107 test $(stg applied -c) -eq 1 &&
108 stg resolved -a &&
109 stg refresh &&
110 stg goto p3
111 '
112
113 test_expect_failure \
114 'Synchronise the third patch with the exported series (to fail)' \
115 '
116 stg sync -s patches-master/series p3
117 '
118
119 test_expect_success \
120 'Restore the stack status after the failed sync' \
121 '
122 test $(stg applied -c) -eq 3 &&
123 stg resolved -a &&
124 stg refresh
125 '
126
127 test_done