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 head ref based on repository's HEAD reference
24 got ref -r $testroot/repo refs/heads/newref HEAD
26 if [ "$ret" != "0" ]; then
27 echo "got ref command failed unexpectedly"
28 test_done "$testroot" "$ret"
32 # Ensure that Git recognizes the ref Got has created
33 (cd $testroot/repo && git checkout -q newref)
35 if [ "$ret" != "0" ]; then
36 echo "git checkout command failed unexpectedly"
37 test_done "$testroot" "$ret"
41 # Ensure Got recognizes the new ref
42 got checkout -b newref $testroot/repo $testroot/wt >/dev/null
44 if [ "$ret" != "0" ]; then
45 echo "got checkout command failed unexpectedly"
46 test_done "$testroot" "$ret"
50 # Create a head ref based on another specific ref
51 (cd $testroot/wt && got ref refs/heads/anotherref refs/heads/master)
53 if [ "$ret" != "0" ]; then
54 test_done "$testroot" "$ret"
58 (cd $testroot/repo && git checkout -q anotherref)
60 if [ "$ret" != "0" ]; then
61 echo "git checkout command failed unexpectedly"
62 test_done "$testroot" "$ret"
65 # Create a symbolic ref
66 (cd $testroot/wt && got ref -s refs/heads/symbolicref refs/heads/master)
68 if [ "$ret" != "0" ]; then
69 test_done "$testroot" "$ret"
73 (cd $testroot/repo && git checkout -q symbolicref)
75 if [ "$ret" != "0" ]; then
76 echo "git checkout command failed unexpectedly"
77 test_done "$testroot" "$ret"
81 # Attempt to create a symbolic ref pointing at a non-reference
82 (cd $testroot/wt && got ref -s refs/heads/symbolicref $commit_id \
85 if [ "$ret" == "0" ]; then
86 echo "git ref command succeeded unexpectedly"
87 test_done "$testroot" "1"
91 echo "got: reference $commit_id not found" > $testroot/stderr.expected
92 cmp -s $testroot/stderr $testroot/stderr.expected
94 if [ "$ret" != "0" ]; then
95 diff -u $testroot/stderr.expected $testroot/stderr
96 test_done "$testroot" "$ret"
100 got ref -r $testroot/repo -l > $testroot/stdout
101 echo "HEAD: refs/heads/symbolicref" > $testroot/stdout.expected
102 echo -n "refs/got/worktree/base-" >> $testroot/stdout.expected
103 cat $testroot/wt/.got/uuid | tr -d '\n' >> $testroot/stdout.expected
104 echo ": $commit_id" >> $testroot/stdout.expected
105 echo "refs/heads/anotherref: $commit_id" >> $testroot/stdout.expected
106 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
107 echo "refs/heads/newref: $commit_id" >> $testroot/stdout.expected
108 echo "refs/heads/symbolicref: refs/heads/master" \
109 >> $testroot/stdout.expected
110 cmp -s $testroot/stdout $testroot/stdout.expected
112 if [ "$ret" != "0" ]; then
113 diff -u $testroot/stdout.expected $testroot/stdout
115 test_done "$testroot" "$ret"
118 function test_ref_delete {
119 local testroot=`test_init ref_delete`
120 local commit_id=`git_show_head $testroot/repo`
122 for b in ref1 ref2 ref3; do
123 got ref -r $testroot/repo refs/heads/$b refs/heads/master
125 if [ "$ret" != "0" ]; then
126 echo "got ref command failed unexpectedly"
127 test_done "$testroot" "$ret"
132 got ref -d refs/heads/ref2 -r $testroot/repo > $testroot/stdout
134 if [ "$ret" != "0" ]; then
135 echo "got ref command failed unexpectedly"
136 test_done "$testroot" "$ret"
140 got ref -l -r $testroot/repo > $testroot/stdout
141 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
142 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
143 echo "refs/heads/ref1: $commit_id" >> $testroot/stdout.expected
144 echo "refs/heads/ref3: $commit_id" >> $testroot/stdout.expected
145 cmp -s $testroot/stdout $testroot/stdout.expected
147 if [ "$ret" != "0" ]; then
148 diff -u $testroot/stdout.expected $testroot/stdout
149 test_done "$testroot" "$ret"
153 got ref -d refs/heads/bogus_ref_name -r $testroot/repo \
154 > $testroot/stdout 2> $testroot/stderr
156 if [ "$ret" == "0" ]; then
157 echo "got ref succeeded unexpectedly"
158 test_done "$testroot" "$ret"
162 echo "got: reference refs/heads/bogus_ref_name not found" \
163 > $testroot/stderr.expected
164 cmp -s $testroot/stderr $testroot/stderr.expected
166 if [ "$ret" != "0" ]; then
167 diff -u $testroot/stderr.expected $testroot/stderr
169 test_done "$testroot" "$ret"
172 run_test test_ref_create
173 run_test test_ref_delete