Preserve picked patch name when possible
[stgit.git] / t / t1208-push-and-pop.sh
blob47eeda3f38994e3fa277a316c52b5cbb59a6132c
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>err && grep -e "branch not initialized" err &&
9 command_error stg next 2>err && grep -e "branch not initialized" err &&
10 command_error stg top 2>err && grep -e "branch not initialized" err &&
11 command_error stg pop 2>err && grep -e "branch not initialized" err &&
12 command_error stg push 2>err && grep -e "branch not initialized" err
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>err && grep -e "Not enough applied patches" err &&
21 command_error stg next 2>err && grep -e "No unapplied patches" err &&
22 command_error stg top 2>err && grep -e "No patches applied" err &&
23 command_error stg pop 2>err && grep -e "No patches applied" err &&
24 command_error stg push 2>err && grep -e "No patches to push" err
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>err && grep -e "No unapplied patches" err &&
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>err && grep -e "incorrect number of arguments" err &&
60 command_error stg next bogus_arg 2>err && grep -e "incorrect number of arguments" err &&
61 command_error stg top bogus_arg 2>err && grep -e "incorrect number of arguments" err
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>err &&
70 grep -e "No patches applied" err
73 test_expect_success \
74 'Check prev, next, and top with none applied' '
75 command_error stg prev &&
76 [ "$(echo $(stg next))" = "p0" ] &&
77 command_error stg top
80 test_expect_success \
81 'Push them back' '
82 stg push -a &&
83 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6 p7 p8 p9" ] &&
84 [ "$(echo $(stg series --unapplied --noprefix))" = "" ] &&
85 command_error stg push 2>err &&
86 grep -e "No patches to push" err
89 test_expect_success \
90 'Pop all but seven patches' '
91 stg pop -n -7 &&
92 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6" ] &&
93 [ "$(echo $(stg series --unapplied --noprefix))" = "p7 p8 p9" ] &&
94 [ "$(git notes show)" = "note6" ]
97 test_expect_success \
98 'Pop no patches (quietly)' '
99 [ -z "$(stg pop -n 0 2>&1)" ] &&
100 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6" ] &&
101 [ "$(echo $(stg series --unapplied --noprefix))" = "p7 p8 p9" ]
104 test_expect_success \
105 'Pop remaining seven patches' '
106 stg pop -n 7 &&
107 [ "$(echo $(stg series --applied --noprefix))" = "" ] &&
108 [ "$(echo $(stg series --unapplied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6 p7 p8 p9" ]
111 test_expect_success \
112 'Push two patches' '
113 stg push -n 2 &&
114 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1" ] &&
115 [ "$(echo $(stg series --unapplied --noprefix))" = "p2 p3 p4 p5 p6 p7 p8 p9" ] &&
116 [ "$(git notes show)" = "note1" ]
119 test_expect_success \
120 'Push no patches (quietly)' '
121 [ -z "$(stg push -n 0 2>&1)" ] &&
122 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1" ] &&
123 [ "$(echo $(stg series --unapplied --noprefix))" = "p2 p3 p4 p5 p6 p7 p8 p9" ]
126 test_expect_success \
127 'Push all but three patches' '
128 stg push -n -3 &&
129 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6" ] &&
130 [ "$(echo $(stg series --unapplied --noprefix))" = "p7 p8 p9" ] &&
131 [ "$(git notes show)" = "note6" ]
134 test_expect_success \
135 'Push two patches in reverse' '
136 stg push -n 2 --reverse
137 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6 p8 p7" ] &&
138 [ "$(echo $(stg series --unapplied --noprefix))" = "p9" ] &&
139 [ "$(git notes show)" = "note7" ]
142 test_expect_success \
143 'Attempt to push already applied patches' '
144 command_error stg push p0..p2 2>err && grep -e "Patches already applied" err &&
145 command_error stg push p99999 2>err && grep -e "Unknown patch name: p99999" err
148 test_done