2 # Copyright (c) 2007 Karl Hasselström
3 test_description
='Test the push and pop commands'
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"
15 'Initialize the StGit repository' \
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"
28 'Create ten patches' '
29 for i in 0 1 2 3 4 5 6 7 8 9; do
31 git notes add -m note$i;
33 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6 p7 p8 p9" ] &&
34 [ "$(echo $(stg series --unapplied --noprefix))" = "" ]
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" ]
47 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2 p3 p4 p5 p6" ] &&
48 [ "$(echo $(stg series --unapplied --noprefix))" = "p7 p8 p9" ]
52 'Check prev, next, and top with some applied' '
53 [ "$(echo $(stg next))" = "p7" ] &&
54 [ "$(echo $(stg prev))" = "p5" ]
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"
65 'Pop the remaining patches' '
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"
73 'Check prev, next, and top with none applied' '
74 command_error stg prev &&
75 [ "$(echo $(stg next))" = "p0" ] &&
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"
88 'Pop all but seven patches' '
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" ]
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' '
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 \
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' '
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"