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