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