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