Test for generated patchname with trailing period
[stgit.git] / t / t1208-push-and-pop.sh
blobe2330d513cbfdd9000f8edc8e9b4956c4955b5d4
1 #!/bin/sh
2 # Copyright (c) 2007 Karl Hasselström
3 test_description='Test the push and pop commands'
4 . ./test-lib.sh
6 test_expect_success \
7 'Test behavior on uninitialized repo' '
8 command_error stg prev 2>&1 | grep -e "branch not initialized" &&
9 command_error stg next 2>&1 | grep -e "branch not initialized" &&
10 command_error stg top 2>&1 | grep -e "branch not initialized" &&
11 command_error stg pop 2>&1 | grep -e "branch not initialized" &&
12 command_error stg push 2>&1 | grep -e "branch not initialized"
14 test_expect_success \
15 'Initialize the StGit repository' \
16 'stg init'
18 test_expect_success \
19 'Test behavior on empty repo' '
20 command_error stg prev 2>&1 | grep -e "Not enough applied patches" &&
21 command_error stg next 2>&1 | grep -e "No unapplied patches" &&
22 command_error stg top 2>&1 | grep -e "No patches applied" &&
23 command_error stg pop 2>&1 | grep -e "No patches applied" &&
24 command_error stg push 2>&1 | grep -e "No patches to push"
27 test_expect_success \
28 'Create ten patches' '
29 for i in 0 1 2 3 4 5 6 7 8 9; do
30 stg new p$i -m p$i;
31 git notes add -m note$i;
32 done &&
33 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6 p7 p8 p9" ] &&
34 [ "$(echo $(stg series --unapplied --noprefix))" = "" ]
37 test_expect_success \
38 'Check prev, next, and top with all applied' '
39 command_error stg next 2>&1 | grep -e "No unapplied patches" &&
40 [ "$(echo $(stg prev))" = "p8" ] &&
41 [ "$(echo $(stg top))" = "p9" ]
44 test_expect_success \
45 'Pop three patches' '
46 stg pop -n 3 &&
47 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6" ] &&
48 [ "$(echo $(stg series --unapplied --noprefix))" = "p7 p8 p9" ]
51 test_expect_success \
52 'Check prev, next, and top with some applied' '
53 [ "$(echo $(stg next))" = "p7" ] &&
54 [ "$(echo $(stg prev))" = "p5" ]
57 test_expect_success \
58 'Check prev, next, and top with invalid arguments' '
59 command_error stg prev bogus_arg 2>&1 | grep -e "incorrect number of arguments" &&
60 command_error stg next bogus_arg 2>&1 | grep -e "incorrect number of arguments" &&
61 command_error stg top bogus_arg 2>&1 | grep -e "incorrect number of arguments"
64 test_expect_success \
65 'Pop the remaining patches' '
66 stg pop -a &&
67 [ "$(echo $(stg series --applied --noprefix))" = "" ] &&
68 [ "$(echo $(stg series --unapplied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6 p7 p8 p9" ] &&
69 command_error stg pop 2>&1 | grep -e "No patches applied"
72 test_expect_success \
73 'Check prev, next, and top with none applied' '
74 command_error stg prev &&
75 [ "$(echo $(stg next))" = "p0" ] &&
76 command_error stg top
79 test_expect_success \
80 'Push them back' '
81 stg push -a &&
82 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6 p7 p8 p9" ] &&
83 [ "$(echo $(stg series --unapplied --noprefix))" = "" ] &&
84 command_error stg push 2>&1 | grep -e "No patches to push"
87 test_expect_success \
88 'Pop all but seven patches' '
89 stg pop -n -7 &&
90 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6" ] &&
91 [ "$(echo $(stg series --unapplied --noprefix))" = "p7 p8 p9" ] &&
92 [ "$(git notes show)" = "note6" ]
95 test_expect_success \
96 'Pop no patches (quietly)' '
97 [ -z "$(stg pop -n 0 2>&1)" ] &&
98 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6" ] &&
99 [ "$(echo $(stg series --unapplied --noprefix))" = "p7 p8 p9" ]
102 test_expect_success \
103 'Pop remaining seven patches' '
104 stg pop -n 7 &&
105 [ "$(echo $(stg series --applied --noprefix))" = "" ] &&
106 [ "$(echo $(stg series --unapplied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6 p7 p8 p9" ]
109 test_expect_success \
110 'Push two patches' '
111 stg push -n 2 &&
112 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1" ] &&
113 [ "$(echo $(stg series --unapplied --noprefix))" = "p2 p3 p4 p5 p6 p7 p8 p9" ] &&
114 [ "$(git notes show)" = "note1" ]
117 test_expect_success \
118 'Push no patches (quietly)' '
119 [ -z "$(stg push -n 0 2>&1)" ] &&
120 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1" ] &&
121 [ "$(echo $(stg series --unapplied --noprefix))" = "p2 p3 p4 p5 p6 p7 p8 p9" ]
124 test_expect_success \
125 'Push all but three patches' '
126 stg push -n -3 &&
127 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6" ] &&
128 [ "$(echo $(stg series --unapplied --noprefix))" = "p7 p8 p9" ] &&
129 [ "$(git notes show)" = "note6" ]
132 test_expect_success \
133 'Push two patches in reverse' '
134 stg push -n 2 --reverse
135 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6 p8 p7" ] &&
136 [ "$(echo $(stg series --unapplied --noprefix))" = "p9" ] &&
137 [ "$(git notes show)" = "note7" ]
140 test_expect_success \
141 'Attempt to push already applied patches' '
142 command_error stg push p0..p2 2>&1 | grep -e "Patches already applied" &&
143 command_error stg push p99999 2>&1 | grep -e "Unknown patch name: p99999"
146 test_done