3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 function test_ref_create {
20 local testroot=`test_init ref_create`
21 local commit_id=`git_show_head $testroot/repo`
23 # Create a ref based on a commit ID
24 got ref -r $testroot/repo refs/heads/commitref $commit_id
26 if [ "$ret" != "0" ]; then
27 echo "got ref command failed unexpectedly"
28 test_done "$testroot" "$ret"
32 # Create a ref based on repository's HEAD reference
33 got ref -r $testroot/repo refs/heads/newref HEAD
35 if [ "$ret" != "0" ]; then
36 echo "got ref command failed unexpectedly"
37 test_done "$testroot" "$ret"
41 # Ensure that Git recognizes the ref Got has created
42 (cd $testroot/repo && git checkout -q newref)
44 if [ "$ret" != "0" ]; then
45 echo "git checkout command failed unexpectedly"
46 test_done "$testroot" "$ret"
50 # Ensure Got recognizes the new ref
51 got checkout -b newref $testroot/repo $testroot/wt >/dev/null
53 if [ "$ret" != "0" ]; then
54 echo "got checkout command failed unexpectedly"
55 test_done "$testroot" "$ret"
59 # Create a head ref based on another specific ref
60 (cd $testroot/wt && got ref refs/heads/anotherref refs/heads/master)
62 if [ "$ret" != "0" ]; then
63 test_done "$testroot" "$ret"
67 (cd $testroot/repo && git checkout -q anotherref)
69 if [ "$ret" != "0" ]; then
70 echo "git checkout command failed unexpectedly"
71 test_done "$testroot" "$ret"
74 # Create a symbolic ref
75 (cd $testroot/wt && got ref -s refs/heads/symbolicref refs/heads/master)
77 if [ "$ret" != "0" ]; then
78 test_done "$testroot" "$ret"
82 (cd $testroot/repo && git checkout -q symbolicref)
84 if [ "$ret" != "0" ]; then
85 echo "git checkout command failed unexpectedly"
86 test_done "$testroot" "$ret"
90 # Attempt to create a symbolic ref pointing at a non-reference
91 (cd $testroot/wt && got ref -s refs/heads/symbolicref $commit_id \
94 if [ "$ret" == "0" ]; then
95 echo "git ref command succeeded unexpectedly"
96 test_done "$testroot" "1"
100 echo "got: reference $commit_id not found" > $testroot/stderr.expected
101 cmp -s $testroot/stderr $testroot/stderr.expected
103 if [ "$ret" != "0" ]; then
104 diff -u $testroot/stderr.expected $testroot/stderr
105 test_done "$testroot" "$ret"
110 got ref -r $testroot/repo -s HEAD refs/heads/newref
112 if [ "$ret" != "0" ]; then
113 echo "got ref command failed unexpectedly"
114 test_done "$testroot" "$ret"
118 # Ensure that Git recognizes the ref Got has created
119 (cd $testroot/repo && git checkout -q HEAD)
121 if [ "$ret" != "0" ]; then
122 echo "git checkout command failed unexpectedly"
123 test_done "$testroot" "$ret"
127 # Ensure Got recognizes the new ref
128 (cd $testroot/wt && got update -b HEAD >/dev/null)
130 if [ "$ret" != "0" ]; then
131 echo "got checkout command failed unexpectedly"
132 test_done "$testroot" "$ret"
135 got ref -r $testroot/repo -l > $testroot/stdout
136 echo "HEAD: refs/heads/newref" > $testroot/stdout.expected
137 echo -n "refs/got/worktree/base-" >> $testroot/stdout.expected
138 cat $testroot/wt/.got/uuid | tr -d '\n' >> $testroot/stdout.expected
139 echo ": $commit_id" >> $testroot/stdout.expected
140 echo "refs/heads/anotherref: $commit_id" >> $testroot/stdout.expected
141 echo "refs/heads/commitref: $commit_id" >> $testroot/stdout.expected
142 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
143 echo "refs/heads/newref: $commit_id" >> $testroot/stdout.expected
144 echo "refs/heads/symbolicref: refs/heads/master" \
145 >> $testroot/stdout.expected
146 cmp -s $testroot/stdout $testroot/stdout.expected
148 if [ "$ret" != "0" ]; then
149 diff -u $testroot/stdout.expected $testroot/stdout
151 test_done "$testroot" "$ret"
154 function test_ref_delete {
155 local testroot=`test_init ref_delete`
156 local commit_id=`git_show_head $testroot/repo`
158 for b in ref1 ref2 ref3; do
159 got ref -r $testroot/repo refs/heads/$b refs/heads/master
161 if [ "$ret" != "0" ]; then
162 echo "got ref command failed unexpectedly"
163 test_done "$testroot" "$ret"
168 got ref -d refs/heads/ref2 -r $testroot/repo > $testroot/stdout
170 if [ "$ret" != "0" ]; then
171 echo "got ref command failed unexpectedly"
172 test_done "$testroot" "$ret"
176 got ref -l -r $testroot/repo > $testroot/stdout
177 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
178 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
179 echo "refs/heads/ref1: $commit_id" >> $testroot/stdout.expected
180 echo "refs/heads/ref3: $commit_id" >> $testroot/stdout.expected
181 cmp -s $testroot/stdout $testroot/stdout.expected
183 if [ "$ret" != "0" ]; then
184 diff -u $testroot/stdout.expected $testroot/stdout
185 test_done "$testroot" "$ret"
189 got ref -d refs/heads/bogus_ref_name -r $testroot/repo \
190 > $testroot/stdout 2> $testroot/stderr
192 if [ "$ret" == "0" ]; then
193 echo "got ref succeeded unexpectedly"
194 test_done "$testroot" "$ret"
198 echo "got: reference refs/heads/bogus_ref_name not found" \
199 > $testroot/stderr.expected
200 cmp -s $testroot/stderr $testroot/stderr.expected
202 if [ "$ret" != "0" ]; then
203 diff -u $testroot/stderr.expected $testroot/stderr
205 test_done "$testroot" "$ret"
208 run_test test_ref_create
209 run_test test_ref_delete