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"
109 got ref -r $testroot/repo -l > $testroot/stdout
110 echo "HEAD: refs/heads/symbolicref" > $testroot/stdout.expected
111 echo -n "refs/got/worktree/base-" >> $testroot/stdout.expected
112 cat $testroot/wt/.got/uuid | tr -d '\n' >> $testroot/stdout.expected
113 echo ": $commit_id" >> $testroot/stdout.expected
114 echo "refs/heads/anotherref: $commit_id" >> $testroot/stdout.expected
115 echo "refs/heads/commitref: $commit_id" >> $testroot/stdout.expected
116 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
117 echo "refs/heads/newref: $commit_id" >> $testroot/stdout.expected
118 echo "refs/heads/symbolicref: refs/heads/master" \
119 >> $testroot/stdout.expected
120 cmp -s $testroot/stdout $testroot/stdout.expected
122 if [ "$ret" != "0" ]; then
123 diff -u $testroot/stdout.expected $testroot/stdout
125 test_done "$testroot" "$ret"
128 function test_ref_delete {
129 local testroot=`test_init ref_delete`
130 local commit_id=`git_show_head $testroot/repo`
132 for b in ref1 ref2 ref3; do
133 got ref -r $testroot/repo refs/heads/$b refs/heads/master
135 if [ "$ret" != "0" ]; then
136 echo "got ref command failed unexpectedly"
137 test_done "$testroot" "$ret"
142 got ref -d refs/heads/ref2 -r $testroot/repo > $testroot/stdout
144 if [ "$ret" != "0" ]; then
145 echo "got ref command failed unexpectedly"
146 test_done "$testroot" "$ret"
150 got ref -l -r $testroot/repo > $testroot/stdout
151 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
152 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
153 echo "refs/heads/ref1: $commit_id" >> $testroot/stdout.expected
154 echo "refs/heads/ref3: $commit_id" >> $testroot/stdout.expected
155 cmp -s $testroot/stdout $testroot/stdout.expected
157 if [ "$ret" != "0" ]; then
158 diff -u $testroot/stdout.expected $testroot/stdout
159 test_done "$testroot" "$ret"
163 got ref -d refs/heads/bogus_ref_name -r $testroot/repo \
164 > $testroot/stdout 2> $testroot/stderr
166 if [ "$ret" == "0" ]; then
167 echo "got ref succeeded unexpectedly"
168 test_done "$testroot" "$ret"
172 echo "got: reference refs/heads/bogus_ref_name not found" \
173 > $testroot/stderr.expected
174 cmp -s $testroot/stderr $testroot/stderr.expected
176 if [ "$ret" != "0" ]; then
177 diff -u $testroot/stderr.expected $testroot/stderr
179 test_done "$testroot" "$ret"
182 run_test test_ref_create
183 run_test test_ref_delete