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 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
25 d1c1ae5f 2019-08-12 stsp ret="$?"
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"
29 d1c1ae5f 2019-08-12 stsp return 1
30 d1c1ae5f 2019-08-12 stsp fi
31 d1c1ae5f 2019-08-12 stsp
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)
34 d1c1ae5f 2019-08-12 stsp ret="$?"
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"
38 d1c1ae5f 2019-08-12 stsp return 1
39 d1c1ae5f 2019-08-12 stsp fi
40 d1c1ae5f 2019-08-12 stsp
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
43 d1c1ae5f 2019-08-12 stsp ret="$?"
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"
47 d1c1ae5f 2019-08-12 stsp return 1
48 d1c1ae5f 2019-08-12 stsp fi
49 d1c1ae5f 2019-08-12 stsp
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)
52 d1c1ae5f 2019-08-12 stsp ret="$?"
53 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
54 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
55 d1c1ae5f 2019-08-12 stsp return 1
56 d1c1ae5f 2019-08-12 stsp fi
57 d1c1ae5f 2019-08-12 stsp
58 d1c1ae5f 2019-08-12 stsp (cd $testroot/repo && git checkout -q anotherref)
59 d1c1ae5f 2019-08-12 stsp ret="$?"
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"
63 d1c1ae5f 2019-08-12 stsp fi
64 d1c1ae5f 2019-08-12 stsp
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)
67 d1c1ae5f 2019-08-12 stsp ret="$?"
68 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
69 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
70 d1c1ae5f 2019-08-12 stsp return 1
71 d1c1ae5f 2019-08-12 stsp fi
72 d1c1ae5f 2019-08-12 stsp
73 d1c1ae5f 2019-08-12 stsp (cd $testroot/repo && git checkout -q symbolicref)
74 d1c1ae5f 2019-08-12 stsp ret="$?"
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"
78 2d463f36 2019-08-12 stsp return 1
79 d1c1ae5f 2019-08-12 stsp fi
80 d1c1ae5f 2019-08-12 stsp
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)
84 2d463f36 2019-08-12 stsp ret="$?"
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"
88 2d463f36 2019-08-12 stsp return 1
89 2d463f36 2019-08-12 stsp fi
90 2d463f36 2019-08-12 stsp
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
93 2d463f36 2019-08-12 stsp ret="$?"
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"
97 2d463f36 2019-08-12 stsp return 1
98 2d463f36 2019-08-12 stsp fi
99 2d463f36 2019-08-12 stsp
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
111 d1c1ae5f 2019-08-12 stsp ret="$?"
112 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
113 d1c1ae5f 2019-08-12 stsp diff -u $testroot/stdout.expected $testroot/stdout
114 d1c1ae5f 2019-08-12 stsp fi
115 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
116 d1c1ae5f 2019-08-12 stsp }
117 d1c1ae5f 2019-08-12 stsp
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`
121 d1c1ae5f 2019-08-12 stsp
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
124 d1c1ae5f 2019-08-12 stsp ret="$?"
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"
128 d1c1ae5f 2019-08-12 stsp return 1
129 d1c1ae5f 2019-08-12 stsp fi
130 d1c1ae5f 2019-08-12 stsp done
131 d1c1ae5f 2019-08-12 stsp
132 d1c1ae5f 2019-08-12 stsp got ref -d refs/heads/ref2 -r $testroot/repo > $testroot/stdout
133 d1c1ae5f 2019-08-12 stsp ret="$?"
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"
137 d1c1ae5f 2019-08-12 stsp return 1
138 d1c1ae5f 2019-08-12 stsp fi
139 d1c1ae5f 2019-08-12 stsp
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
146 d1c1ae5f 2019-08-12 stsp ret="$?"
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"
150 d1c1ae5f 2019-08-12 stsp return 1
151 d1c1ae5f 2019-08-12 stsp fi
152 d1c1ae5f 2019-08-12 stsp
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
155 d1c1ae5f 2019-08-12 stsp ret="$?"
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"
159 d1c1ae5f 2019-08-12 stsp return 1
160 d1c1ae5f 2019-08-12 stsp fi
161 d1c1ae5f 2019-08-12 stsp
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
165 d1c1ae5f 2019-08-12 stsp ret="$?"
166 d1c1ae5f 2019-08-12 stsp if [ "$ret" != "0" ]; then
167 d1c1ae5f 2019-08-12 stsp diff -u $testroot/stderr.expected $testroot/stderr
168 d1c1ae5f 2019-08-12 stsp fi
169 d1c1ae5f 2019-08-12 stsp test_done "$testroot" "$ret"
170 d1c1ae5f 2019-08-12 stsp }
171 d1c1ae5f 2019-08-12 stsp
172 d1c1ae5f 2019-08-12 stsp run_test test_ref_create
173 d1c1ae5f 2019-08-12 stsp run_test test_ref_delete