Blame


1 d1c1ae5f 2019-08-12 stsp #!/bin/sh
2 d1c1ae5f 2019-08-12 stsp #
3 d1c1ae5f 2019-08-12 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 d1c1ae5f 2019-08-12 stsp #
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.
8 d1c1ae5f 2019-08-12 stsp #
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.
16 d1c1ae5f 2019-08-12 stsp
17 d1c1ae5f 2019-08-12 stsp . ./common.sh
18 d1c1ae5f 2019-08-12 stsp
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`
22 d1c1ae5f 2019-08-12 stsp
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
25 d4fc9a62 2019-10-09 stsp ret="$?"
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"
29 d4fc9a62 2019-10-09 stsp return 1
30 d4fc9a62 2019-10-09 stsp fi
31 d4fc9a62 2019-10-09 stsp
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
34 d1c1ae5f 2019-08-12 stsp ret="$?"
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"
38 d1c1ae5f 2019-08-12 stsp return 1
39 d1c1ae5f 2019-08-12 stsp fi
40 d1c1ae5f 2019-08-12 stsp
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)
43 d1c1ae5f 2019-08-12 stsp ret="$?"
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"
47 d1c1ae5f 2019-08-12 stsp return 1
48 d1c1ae5f 2019-08-12 stsp fi
49 d1c1ae5f 2019-08-12 stsp
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
52 d1c1ae5f 2019-08-12 stsp ret="$?"
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"
56 d1c1ae5f 2019-08-12 stsp return 1
57 d1c1ae5f 2019-08-12 stsp fi
58 d1c1ae5f 2019-08-12 stsp
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)
61 d1c1ae5f 2019-08-12 stsp ret="$?"
62 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
63 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
64 d1c1ae5f 2019-08-12 stsp return 1
65 d1c1ae5f 2019-08-12 stsp fi
66 d1c1ae5f 2019-08-12 stsp
67 d1c1ae5f 2019-08-12 stsp (cd $testroot/repo && git checkout -q anotherref)
68 d1c1ae5f 2019-08-12 stsp ret="$?"
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"
72 d1c1ae5f 2019-08-12 stsp fi
73 d1c1ae5f 2019-08-12 stsp
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)
76 d1c1ae5f 2019-08-12 stsp ret="$?"
77 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
78 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
79 d1c1ae5f 2019-08-12 stsp return 1
80 d1c1ae5f 2019-08-12 stsp fi
81 d1c1ae5f 2019-08-12 stsp
82 d1c1ae5f 2019-08-12 stsp (cd $testroot/repo && git checkout -q symbolicref)
83 d1c1ae5f 2019-08-12 stsp ret="$?"
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"
87 2d463f36 2019-08-12 stsp return 1
88 d1c1ae5f 2019-08-12 stsp fi
89 d1c1ae5f 2019-08-12 stsp
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)
93 2d463f36 2019-08-12 stsp ret="$?"
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"
97 2d463f36 2019-08-12 stsp return 1
98 2d463f36 2019-08-12 stsp fi
99 2d463f36 2019-08-12 stsp
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
102 2d463f36 2019-08-12 stsp ret="$?"
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"
106 2d463f36 2019-08-12 stsp return 1
107 2d463f36 2019-08-12 stsp fi
108 2d463f36 2019-08-12 stsp
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
121 d1c1ae5f 2019-08-12 stsp ret="$?"
122 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
123 d1c1ae5f 2019-08-12 stsp diff -u $testroot/stdout.expected $testroot/stdout
124 d1c1ae5f 2019-08-12 stsp fi
125 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
126 d1c1ae5f 2019-08-12 stsp }
127 d1c1ae5f 2019-08-12 stsp
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`
131 d1c1ae5f 2019-08-12 stsp
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
134 d1c1ae5f 2019-08-12 stsp ret="$?"
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"
138 d1c1ae5f 2019-08-12 stsp return 1
139 d1c1ae5f 2019-08-12 stsp fi
140 d1c1ae5f 2019-08-12 stsp done
141 d1c1ae5f 2019-08-12 stsp
142 d1c1ae5f 2019-08-12 stsp got ref -d refs/heads/ref2 -r $testroot/repo > $testroot/stdout
143 d1c1ae5f 2019-08-12 stsp ret="$?"
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"
147 d1c1ae5f 2019-08-12 stsp return 1
148 d1c1ae5f 2019-08-12 stsp fi
149 d1c1ae5f 2019-08-12 stsp
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
156 d1c1ae5f 2019-08-12 stsp ret="$?"
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"
160 d1c1ae5f 2019-08-12 stsp return 1
161 d1c1ae5f 2019-08-12 stsp fi
162 d1c1ae5f 2019-08-12 stsp
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
165 d1c1ae5f 2019-08-12 stsp ret="$?"
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"
169 d1c1ae5f 2019-08-12 stsp return 1
170 d1c1ae5f 2019-08-12 stsp fi
171 d1c1ae5f 2019-08-12 stsp
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
175 d1c1ae5f 2019-08-12 stsp ret="$?"
176 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
177 d1c1ae5f 2019-08-12 stsp diff -u $testroot/stderr.expected $testroot/stderr
178 d1c1ae5f 2019-08-12 stsp fi
179 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
180 d1c1ae5f 2019-08-12 stsp }
181 d1c1ae5f 2019-08-12 stsp
182 d1c1ae5f 2019-08-12 stsp run_test test_ref_create
183 d1c1ae5f 2019-08-12 stsp run_test test_ref_delete