Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
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.
8 #
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.
17 . ./common.sh
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
25 ret="$?"
26 if [ "$ret" != "0" ]; then
27 echo "got ref command failed unexpectedly"
28 test_done "$testroot" "$ret"
29 return 1
30 fi
32 # Ensure that Git recognizes the ref Got has created
33 (cd $testroot/repo && git checkout -q newref)
34 ret="$?"
35 if [ "$ret" != "0" ]; then
36 echo "git checkout command failed unexpectedly"
37 test_done "$testroot" "$ret"
38 return 1
39 fi
41 # Ensure Got recognizes the new ref
42 got checkout -b newref $testroot/repo $testroot/wt >/dev/null
43 ret="$?"
44 if [ "$ret" != "0" ]; then
45 echo "got checkout command failed unexpectedly"
46 test_done "$testroot" "$ret"
47 return 1
48 fi
50 # Create a head ref based on another specific ref
51 (cd $testroot/wt && got ref refs/heads/anotherref refs/heads/master)
52 ret="$?"
53 if [ "$ret" != "0" ]; then
54 test_done "$testroot" "$ret"
55 return 1
56 fi
58 (cd $testroot/repo && git checkout -q anotherref)
59 ret="$?"
60 if [ "$ret" != "0" ]; then
61 echo "git checkout command failed unexpectedly"
62 test_done "$testroot" "$ret"
63 fi
65 # Create a symbolic ref
66 (cd $testroot/wt && got ref -s refs/heads/symbolicref refs/heads/master)
67 ret="$?"
68 if [ "$ret" != "0" ]; then
69 test_done "$testroot" "$ret"
70 return 1
71 fi
73 (cd $testroot/repo && git checkout -q symbolicref)
74 ret="$?"
75 if [ "$ret" != "0" ]; then
76 echo "git checkout command failed unexpectedly"
77 test_done "$testroot" "$ret"
78 return 1
79 fi
81 # Attempt to create a symbolic ref pointing at a non-reference
82 (cd $testroot/wt && got ref -s refs/heads/symbolicref $commit_id \
83 2> $testroot/stderr)
84 ret="$?"
85 if [ "$ret" == "0" ]; then
86 echo "git ref command succeeded unexpectedly"
87 test_done "$testroot" "1"
88 return 1
89 fi
91 echo "got: reference $commit_id not found" > $testroot/stderr.expected
92 cmp -s $testroot/stderr $testroot/stderr.expected
93 ret="$?"
94 if [ "$ret" != "0" ]; then
95 diff -u $testroot/stderr.expected $testroot/stderr
96 test_done "$testroot" "$ret"
97 return 1
98 fi
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
111 ret="$?"
112 if [ "$ret" != "0" ]; then
113 diff -u $testroot/stdout.expected $testroot/stdout
114 fi
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
124 ret="$?"
125 if [ "$ret" != "0" ]; then
126 echo "got ref command failed unexpectedly"
127 test_done "$testroot" "$ret"
128 return 1
129 fi
130 done
132 got ref -d refs/heads/ref2 -r $testroot/repo > $testroot/stdout
133 ret="$?"
134 if [ "$ret" != "0" ]; then
135 echo "got ref command failed unexpectedly"
136 test_done "$testroot" "$ret"
137 return 1
138 fi
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
146 ret="$?"
147 if [ "$ret" != "0" ]; then
148 diff -u $testroot/stdout.expected $testroot/stdout
149 test_done "$testroot" "$ret"
150 return 1
151 fi
153 got ref -d refs/heads/bogus_ref_name -r $testroot/repo \
154 > $testroot/stdout 2> $testroot/stderr
155 ret="$?"
156 if [ "$ret" == "0" ]; then
157 echo "got ref succeeded unexpectedly"
158 test_done "$testroot" "$ret"
159 return 1
160 fi
162 echo "got: reference refs/heads/bogus_ref_name not found" \
163 > $testroot/stderr.expected
164 cmp -s $testroot/stderr $testroot/stderr.expected
165 ret="$?"
166 if [ "$ret" != "0" ]; then
167 diff -u $testroot/stderr.expected $testroot/stderr
168 fi
169 test_done "$testroot" "$ret"
172 run_test test_ref_create
173 run_test test_ref_delete