tg.sh: handle help -h
[topgit/pro.git] / t / t6101-tag-reflog0.sh
blob32b1669e648bcb166e0596f092d1eff0fcba77ba
1 #!/bin/sh
3 test_description='check tg tag reflog @{0} drops'
5 TEST_NO_CREATE_REPO=1
7 . ./test-lib.sh
9 if vcmp "$git_version" '>=' "2.5"; then
10 test_set_prereq "GIT_2_5"
13 git_231_plus=
14 if vcmp "$git_version" '>=' "2.31"; then
15 git_231_plus=1
18 test_plan 7
20 # replace `git symbolic-ref HEAD refs/heads/foo`
21 # with `sane_reattach_ref HEAD refs/heads/foo`
22 sane_reattach_ref() {
23 _rlc="$(git reflog show "$1" -- | wc -l)" &&
24 git symbolic-ref "$1" "$2" &&
25 _rlc2="$(git reflog show "$1" -- | wc -l)" &&
26 if test x"$_rlc" != x"$_rlc2"; then
27 git reflog delete "$1@{0}" &&
28 _rlc2="$(git reflog show "$1" -- | wc -l)" &&
29 test x"$_rlc" = x"$_rlc2"
33 test_expect_success 'setup main' '
34 test_create_repo main &&
35 cd main &&
36 git checkout --orphan slithy &&
37 test_commit sfile1 &&
38 test_commit sfile2 &&
39 test_commit sfile3 &&
40 test_commit sfile4 &&
41 test_commit sfile5 &&
42 rlcnt=$(git log --oneline -g slithy | wc -l) &&
43 test $rlcnt -eq 5 &&
44 git reflog delete slithy@{4} &&
45 git reflog delete slithy@{2} &&
46 git reflog delete slithy@{0} &&
47 rlcnt=$(git log --oneline -g slithy | wc -l) &&
48 test $rlcnt -eq 2 &&
49 while git rev-parse --verify --quiet HEAD@{1} --; do
50 git reflog delete HEAD@{0} >/dev/null 2>&1 || :
51 done &&
52 { git reflog delete HEAD@{0} >/dev/null 2>&1 || :; } &&
53 git checkout --orphan frabjous &&
54 # there might, or might not be a garbage @{0} entry in the reflog for HEAD
55 { git reflog delete HEAD@{0} >/dev/null 2>&1 || :; } &&
56 test_commit file1 &&
57 test_commit file2 &&
58 test_commit file3 &&
59 test_commit file4 &&
60 test_commit file5 &&
61 rlcnt=$(git log --oneline -g HEAD | wc -l) &&
62 test $rlcnt -eq 5 &&
63 git reflog delete HEAD@{4} &&
64 git reflog delete HEAD@{2} &&
65 git reflog delete HEAD@{0} &&
66 rlcnt=$(git log --oneline -g HEAD | wc -l) &&
67 test $rlcnt -eq 2 &&
68 test_when_finished test_tick=$test_tick
71 test_expect_success 'LASTOK GIT_2_5' 'setup linked' '
72 cd main &&
73 mttree="$(git mktree </dev/null)" &&
74 test -n "$mttree" &&
75 test_tick &&
76 mtcommit="$(git commit-tree -m "empty commit" "$mttree")" &&
77 test -n "$mtcommit" &&
78 cd .. &&
79 git --git-dir=main/.git worktree add --detach linked "$mtcommit" &&
80 cd linked &&
81 # there might, or might not be a garbage @{0} entry in the reflog for HEAD
82 { git reflog delete HEAD@{0} >/dev/null 2>&1 || :; } &&
83 git checkout --orphan outgrabe &&
84 test_commit ofile1 &&
85 test_commit ofile2 &&
86 test_commit ofile3 &&
87 test_commit ofile4 &&
88 test_commit ofile5 &&
89 rlcnt=$(git log --oneline -g outgrabe | wc -l) &&
90 test $rlcnt -eq 5 &&
91 git reflog delete outgrabe@{4} &&
92 git reflog delete outgrabe@{2} &&
93 git reflog delete outgrabe@{0} &&
94 rlcnt=$(git log --oneline -g outgrabe | wc -l) &&
95 test $rlcnt -eq 2 &&
96 while git rev-parse --verify --quiet HEAD@{1} --; do
97 git reflog delete HEAD@{0} >/dev/null 2>&1 || :
98 done &&
99 { git reflog delete HEAD@{0} >/dev/null 2>&1 || :; } &&
100 git checkout --orphan linked &&
101 # there might, or might not be a garbage @{0} entry in the reflog for HEAD
102 { git reflog delete HEAD@{0} >/dev/null 2>&1 || :; } &&
103 test_commit lfile1 &&
104 test_commit lfile2 &&
105 test_commit lfile3 &&
106 test_commit lfile4 &&
107 test_commit lfile5 &&
108 rlcnt=$(git log --oneline -g HEAD | wc -l) &&
109 test $rlcnt -eq 5 &&
110 git reflog delete HEAD@{4} &&
111 git reflog delete HEAD@{2} &&
112 git reflog delete HEAD@{0} &&
113 rlcnt=$(git log --oneline -g HEAD | wc -l) &&
114 test $rlcnt -eq 2 &&
115 test_when_finished test_tick=$test_tick
118 test_expect_success LASTOK 'verify setup' '
119 cd main &&
120 mh="$(git rev-parse --verify HEAD --)" &&
121 test -n "$mh" &&
122 mh0="$(git rev-parse --verify HEAD@{0} --)" &&
123 test -n "$mh0" &&
124 sh="$(git rev-parse --verify slithy --)" &&
125 test -n "$sh" &&
126 sh0="$(git rev-parse --verify slithy@{0} --)" &&
127 test -n "$sh0" &&
128 if test_have_prereq GIT_2_5; then
129 cd ../linked &&
130 lh="$(git rev-parse --verify HEAD --)" &&
131 test -n "$lh" &&
132 lh0="$(git rev-parse --verify HEAD@{0} --)" &&
133 test -n "$lh0" &&
134 oh="$(git rev-parse --verify outgrabe --)" &&
135 test -n "$oh" &&
136 oh0="$(git rev-parse --verify outgrabe@{0} --)" &&
137 test -n "$oh0" &&
138 cd ../main
139 else
140 lh="not" &&
141 lh0="available" &&
142 oh="no" &&
143 oh0="linked worktrees"
144 fi &&
146 test "$mh0" != "$mh" && test "$sh0" != "$sh" &&
147 test "$lh0" != "$lh" && test "$oh0" != "$oh"
148 then
149 test_when_finished test_set_prereq AT0DISTINCT
153 test_expect_success AT0DISTINCT 'ref [symref] preserved when dropping different @{0}' '
154 cd main &&
155 h="$(git rev-parse --verify HEAD --)" &&
156 test -n "$h" &&
157 h0="$(git rev-parse --verify HEAD@{0} --)" &&
158 test -n "$h0" &&
159 test "$h" != "$h0" &&
160 tgx tag --drop HEAD@{0} &&
161 hp="$(git rev-parse --verify HEAD --)" &&
162 test -n "$hp" &&
163 h0p="$(git rev-parse --verify HEAD@{0} --)" &&
164 test -n "$h0p" &&
165 test "$h" = "$hp" &&
166 test "$h0p" != "$h0"
169 test_expect_success AT0DISTINCT,GIT_2_5 'ref [symref] preserved when dropping different @{0} [linked]' '
170 cd linked &&
171 h="$(git rev-parse --verify HEAD --)" &&
172 test -n "$h" &&
173 h0="$(git rev-parse --verify HEAD@{0} --)" &&
174 test -n "$h0" &&
175 test "$h" != "$h0" &&
176 tg tag --drop HEAD@{0} &&
177 hp="$(git rev-parse --verify HEAD --)" &&
178 test -n "$hp" &&
179 h0p="$(git rev-parse --verify HEAD@{0} --)" &&
180 test -n "$h0p" &&
181 test "$h" = "$hp" &&
182 test "$h0p" != "$h0"
185 test_expect_success AT0DISTINCT 'ref [actual] preserved when dropping different @{0}' '
186 cd main &&
187 h="$(git rev-parse --verify slithy --)" &&
188 test -n "$h" &&
189 h0="$(git rev-parse --verify slithy@{0} --)" &&
190 test -n "$h0" &&
191 test "$h" != "$h0" &&
192 tgx tag --drop slithy@{0} &&
193 hp="$(git rev-parse --verify slithy --)" &&
194 test -n "$hp" &&
195 h0p="$(git rev-parse --verify slithy@{0} --)" &&
196 test -n "$h0p" &&
197 test "$h" = "$hp" &&
198 test "$h0p" != "$h0"
201 test_expect_success AT0DISTINCT,GIT_2_5 'ref [actual] preserved when dropping different @{0} [linked]' '
202 cd linked &&
203 h="$(git rev-parse --verify outgrabe --)" &&
204 test -n "$h" &&
205 h0="$(git rev-parse --verify outgrabe@{0} --)" &&
206 test -n "$h0" &&
207 test "$h" != "$h0" &&
208 tg tag --drop outgrabe@{0} &&
209 hp="$(git rev-parse --verify outgrabe --)" &&
210 test -n "$hp" &&
211 h0p="$(git rev-parse --verify outgrabe@{0} --)" &&
212 test -n "$h0p" &&
213 test "$h" = "$hp" &&
214 test "$h0p" != "$h0"
217 test_done