tg.sh: handle help -h
[topgit/pro.git] / t / t2300-annihilate.sh
blobeb478492477de6cc5a5e198fa48d58506d3536c4
1 #!/bin/sh
3 test_description='tg annihilate tests'
5 . ./test-lib.sh
7 test_plan 7
9 # true if $1 is contained by (or the same as) $2
10 # this is never slower than merge-base --is-ancestor and is often slightly faster
11 contained_by() {
12 [ "$(git rev-list --count --max-count=1 "$1" --not "$2" --)" = "0" ]
15 uctmp="$(test_get_temp update-check)" || die
17 branch_is_up_to_date() {
18 needs_update_check "$@" >"$uctmp" &&
20 read -r uc_processed &&
21 read -r uc_behind &&
22 read -r uc_ahead &&
23 read -r uc_partial
24 } <"$uctmp" &&
25 test z"$uc_behind" = z":"
28 expfile="$(test_get_temp expected)" || die
29 actfile="$(test_get_temp actual)" || die
31 test_expect_success 'setup' '
32 tg_test_create_branches <<-EOT &&
33 t/lefta
36 t/leftb
39 t/righta
42 t/rightb
44 EOT
45 git checkout -f t/lefta &&
46 test_commit "left eh" lefta.txt &&
47 git checkout -f t/leftb &&
48 test_commit "left be" leftb.txt &&
49 git checkout -f t/righta &&
50 test_commit "right eh" righta.txt &&
51 git checkout -f t/rightb &&
52 test_commit "right be" rightb.txt &&
53 tg_test_create_branches <<-EOT &&
54 t/int0
55 t/lefta
56 t/leftb
58 t/int1
59 t/righta
60 t/rightb
61 EOT
62 git checkout -f t/int0 &&
63 test_tick &&
64 tg update --no-stash &&
65 test_tick &&
66 git commit --amend --reset-author --no-edit --only -- &&
67 git checkout -f t/int1 &&
68 test_tick &&
69 tg update --no-stash &&
70 test_tick &&
71 git commit --amend --reset-author --no-edit --only -- &&
72 test_commit "int won" int1.txt &&
73 tg_test_create_branch stage -m "[STAGE] all together now" t/int0 t/int1 &&
74 git checkout -f stage &&
75 test_tick &&
76 tg update --no-stash &&
77 test_tick &&
78 git commit --amend --reset-author --no-edit --only -- &&
79 printf "%s\n" stage t/int0 t/int1 t/lefta t/leftb t/righta t/rightb >"$expfile" &&
80 tg summary --terse >"$actfile" &&
81 test_cmp "$actfile" "$expfile" &&
82 branch_is_up_to_date stage &&
83 test_when_finished test_tick=$test_tick &&
84 test_when_finished test_set_prereq SETUP
87 test_expect_success SETUP 'modify t/leftb' '
88 branch_is_up_to_date stage &&
89 git checkout -f t/leftb &&
90 test_commit "left ex" leftx.txt &&
91 test_must_fail branch_is_up_to_date stage &&
92 test_when_finished test_tick=$test_tick
95 test_expect_success SETUP 'annihilate int0 works' '
96 test_tick &&
97 tg annihilate --no-stash t/int0 &&
98 printf "%s\n" stage t/int1 t/lefta t/leftb t/righta t/rightb >"$expfile" &&
99 tg summary --terse >"$actfile" &&
100 test_cmp "$actfile" "$expfile" &&
101 branch_is_up_to_date stage &&
102 test_when_finished test_tick=$test_tick
105 test_expect_success SETUP 'annihilate int1 fails' '
106 test_must_fail tg annihilate --no-stash t/int1 &&
107 printf "%s\n" stage t/int1 t/lefta t/leftb t/righta t/rightb >"$expfile" &&
108 tg summary --terse >"$actfile" &&
109 test_cmp "$actfile" "$expfile"
112 test_expect_success SETUP 'modify t/rightb' '
113 branch_is_up_to_date stage &&
114 git checkout -f t/rightb &&
115 test_commit "right ex" rightx.txt &&
116 test_must_fail branch_is_up_to_date stage &&
117 test_when_finished test_tick=$test_tick
120 test_expect_success SETUP 'anniliate --force int1 succeeds' '
121 test_tick &&
122 tg annihilate --no-stash --force t/int1 &&
123 printf "%s\n" stage t/lefta t/leftb t/righta t/rightb >"$expfile" &&
124 tg summary --terse >"$actfile" &&
125 test_cmp "$actfile" "$expfile" &&
126 branch_is_up_to_date stage &&
127 test_when_finished test_tick=$test_tick
130 test_expect_success SETUP 'verify branch up-to-date containment' '
131 topbases="$(tg --top-bases)" &&
132 test -n "$topbases" &&
133 contained_by "$topbases/t/lefta" refs/heads/t/lefta &&
134 contained_by "$topbases/t/leftb" refs/heads/t/leftb &&
135 contained_by "$topbases/t/righta" refs/heads/t/righta &&
136 contained_by "$topbases/t/rightb" refs/heads/t/rightb &&
137 contained_by refs/heads/t/lefta "$topbases/stage" &&
138 contained_by refs/heads/t/leftb "$topbases/stage" &&
139 contained_by refs/heads/t/righta "$topbases/stage" &&
140 contained_by refs/heads/t/rightb "$topbases/stage" &&
141 contained_by "$topbases/stage" refs/heads/stage
144 test_done