chiark / gitweb /
stgit.el: Add "d" for a few diff commands, similar to git.el
[stgit] / t / t2000-sync.sh
CommitLineData
06848fab
CM
1#!/bin/sh
2#
3# Copyright (c) 2006 Catalin Marinas
4#
5
6test_description='Test the sync command.'
7
8. ./test-lib.sh
9
10test_expect_success \
11 'Initialize the StGIT repository' \
12 '
13 stg init
14 '
15
16test_expect_success \
17 'Create some patches' \
18 '
19 stg new p1 -m p1 &&
20 echo foo1 > foo1.txt &&
ea5b7bf3 21 git add foo1.txt &&
06848fab
CM
22 stg refresh &&
23 stg new p2 -m p2 &&
24 echo foo2 > foo2.txt &&
ea5b7bf3 25 git add foo2.txt &&
06848fab
CM
26 stg refresh &&
27 stg new p3 -m p3 &&
28 echo foo3 > foo3.txt &&
ea5b7bf3 29 git add foo3.txt &&
06848fab
CM
30 stg refresh &&
31 stg export &&
fea352bf 32 stg pop &&
f9d9a062
CM
33 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2" ] &&
34 [ "$(echo $(stg series --unapplied --noprefix))" = "p3" ]
06848fab
CM
35 '
36
37test_expect_success \
38 'Create a branch with empty patches' \
39 '
e4560d7e 40 stg branch -c foo {base} &&
06848fab
CM
41 stg new p1 -m p1 &&
42 stg new p2 -m p2 &&
fea352bf 43 stg new p3 -m p3 &&
f9d9a062
CM
44 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" ] &&
45 [ "$(echo $(stg series --unapplied --noprefix))" = "" ]
06848fab
CM
46 '
47
48test_expect_success \
49 'Synchronise second patch with the master branch' \
50 '
6b79a09c 51 stg sync -B master p2 &&
f9d9a062
CM
52 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" ] &&
53 [ "$(echo $(stg series --unapplied --noprefix))" = "" ] &&
89f64744 54 test $(cat foo2.txt) = "foo2"
06848fab
CM
55 '
56
57test_expect_success \
58 'Synchronise the first two patches with the master branch' \
59 '
6b79a09c 60 stg sync -B master -a &&
f9d9a062
CM
61 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" ] &&
62 [ "$(echo $(stg series --unapplied --noprefix))" = "" ] &&
89f64744
KH
63 test $(cat foo1.txt) = "foo1" &&
64 test $(cat foo2.txt) = "foo2"
06848fab
CM
65 '
66
67test_expect_success \
68 'Synchronise all the patches with the exported series' \
69 '
70 stg sync -s patches-master/series -a &&
f9d9a062
CM
71 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" ] &&
72 [ "$(echo $(stg series --unapplied --noprefix))" = "" ] &&
89f64744
KH
73 test $(cat foo1.txt) = "foo1" &&
74 test $(cat foo2.txt) = "foo2" &&
75 test $(cat foo3.txt) = "foo3"
06848fab
CM
76 '
77
78test_expect_success \
79 'Modify the master patches' \
80 '
81 stg branch master &&
f9d9a062
CM
82 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2" ] &&
83 [ "$(echo $(stg series --unapplied --noprefix))" = "p3" ] &&
06848fab
CM
84 stg goto p1 &&
85 echo bar1 >> foo1.txt &&
86 stg refresh &&
87 stg goto p2 &&
88 echo bar2 > bar2.txt &&
ea5b7bf3 89 git add bar2.txt &&
06848fab
CM
90 stg refresh &&
91 stg goto p3 &&
92 echo bar3 >> foo3.txt &&
93 stg refresh &&
f9d9a062
CM
94 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" ] &&
95 [ "$(echo $(stg series --unapplied --noprefix))" = "" ] &&
06848fab
CM
96 stg export &&
97 stg branch foo
98 '
99
100test_expect_success \
101 'Synchronise second patch with the master branch' \
102 '
6b79a09c 103 stg sync -B master p2 &&
f9d9a062
CM
104 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" ] &&
105 [ "$(echo $(stg series --unapplied --noprefix))" = "" ] &&
89f64744 106 test $(cat bar2.txt) = "bar2"
06848fab
CM
107 '
108
5f594e90 109test_expect_success \
06848fab
CM
110 'Synchronise the first two patches with the master branch (to fail)' \
111 '
f03004e2 112 conflict_old stg sync -B master -a
06848fab
CM
113 '
114
115test_expect_success \
116 'Restore the stack status after the failed sync' \
117 '
f9d9a062
CM
118 [ "$(echo $(stg series --applied --noprefix))" = "p1" ] &&
119 [ "$(echo $(stg series --unapplied --noprefix))" = "p2 p3" ] &&
9ab06b98 120 git add --update &&
06848fab
CM
121 stg refresh &&
122 stg goto p3
f9d9a062
CM
123 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" ] &&
124 [ "$(echo $(stg series --unapplied --noprefix))" = "" ]
06848fab
CM
125 '
126
5f594e90 127test_expect_success \
06848fab
CM
128 'Synchronise the third patch with the exported series (to fail)' \
129 '
f03004e2 130 conflict_old stg sync -s patches-master/series p3
06848fab
CM
131 '
132
133test_expect_success \
134 'Restore the stack status after the failed sync' \
135 '
f9d9a062
CM
136 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" ] &&
137 [ "$(echo $(stg series --unapplied --noprefix))" = "" ] &&
9ab06b98 138 git add --update &&
fea352bf 139 stg refresh &&
f9d9a062
CM
140 [ "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" ] &&
141 [ "$(echo $(stg series --unapplied --noprefix))" = "" ]
06848fab
CM
142 '
143
144test_done