Blame


1 2df845d5 2023-07-07 op #!/bin/sh
2 2df845d5 2023-07-07 op #
3 2df845d5 2023-07-07 op # Copyright (c) 2023 Omar Polo <op@openbsd.org>
4 2df845d5 2023-07-07 op #
5 2df845d5 2023-07-07 op # Permission to use, copy, modify, and distribute this software for any
6 2df845d5 2023-07-07 op # purpose with or without fee is hereby granted, provided that the above
7 2df845d5 2023-07-07 op # copyright notice and this permission notice appear in all copies.
8 2df845d5 2023-07-07 op #
9 2df845d5 2023-07-07 op # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 2df845d5 2023-07-07 op # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 2df845d5 2023-07-07 op # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 2df845d5 2023-07-07 op # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 2df845d5 2023-07-07 op # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 2df845d5 2023-07-07 op # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 2df845d5 2023-07-07 op # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 2df845d5 2023-07-07 op
17 2df845d5 2023-07-07 op . ./common.sh
18 2df845d5 2023-07-07 op
19 2df845d5 2023-07-07 op test_dump_bundle() {
20 2df845d5 2023-07-07 op local testroot=`test_init test_dump_bundle`
21 2df845d5 2023-07-07 op
22 2df845d5 2023-07-07 op # add a fake reference so that `got log' appears the same in
23 2df845d5 2023-07-07 op # the cloned repository
24 2df845d5 2023-07-07 op (cd "$testroot/repo" && got branch -n origin/master)
25 2df845d5 2023-07-07 op
26 2df845d5 2023-07-07 op (cd "$testroot/repo" && got log -p >$testroot/repo.log)
27 2df845d5 2023-07-07 op
28 2df845d5 2023-07-07 op (cd "$testroot/repo" && gotadmin dump -q master >$testroot/r.bundle)
29 2df845d5 2023-07-07 op if [ $? -ne 0 ]; then
30 2df845d5 2023-07-07 op echo "gotadmin dump failed unexpectedly" >&2
31 2df845d5 2023-07-07 op test_done "$testroot" 1
32 2df845d5 2023-07-07 op return 1
33 2df845d5 2023-07-07 op fi
34 2df845d5 2023-07-07 op
35 f73bf5bd 2023-10-01 naddy if ! git -C "$testroot" clone -b master -q r.bundle; then
36 2df845d5 2023-07-07 op echo "failed to git clone from the generated bundle" >&2
37 2df845d5 2023-07-07 op test_done "$testroot" 1
38 2df845d5 2023-07-07 op return 1
39 2df845d5 2023-07-07 op fi
40 2df845d5 2023-07-07 op
41 2df845d5 2023-07-07 op if ! (cd "$testroot/r" && got log -p >$testroot/r.log); then
42 2df845d5 2023-07-07 op echo "got log failed unexpectedly" >&2
43 2df845d5 2023-07-07 op test_done "$testroot" 1
44 2df845d5 2023-07-07 op return 1
45 2df845d5 2023-07-07 op fi
46 2df845d5 2023-07-07 op
47 2df845d5 2023-07-07 op if ! cmp -s "$testroot/repo.log" "$testroot/r.log"; then
48 2df845d5 2023-07-07 op echo "history differs after clone" >&2
49 2df845d5 2023-07-07 op diff -u "$testroot/repo.log" "$testroot/r.log"
50 2df845d5 2023-07-07 op test_done "$testroot" 1
51 2df845d5 2023-07-07 op return 1
52 2df845d5 2023-07-07 op fi
53 2df845d5 2023-07-07 op
54 f73bf5bd 2023-10-01 naddy git -C "$testroot/repo" checkout -q -b newbranch
55 2df845d5 2023-07-07 op
56 2df845d5 2023-07-07 op # commit some changes in the repo
57 2df845d5 2023-07-07 op for i in `seq 5`; do
58 2df845d5 2023-07-07 op echo "alpha edit #$i" > $testroot/repo/alpha
59 2df845d5 2023-07-07 op git_commit "$testroot/repo" -m "edit alpha"
60 2df845d5 2023-07-07 op done
61 2df845d5 2023-07-07 op
62 2df845d5 2023-07-07 op (cd "$testroot/repo" && \
63 2df845d5 2023-07-07 op gotadmin dump -q -x master newbranch >$testroot/r.bundle)
64 2df845d5 2023-07-07 op if [ $? -ne 0 ]; then
65 2df845d5 2023-07-07 op echo "gotadmin dump failed unexpectedly" >&2
66 2df845d5 2023-07-07 op test_done "$testroot" 1
67 2df845d5 2023-07-07 op return 1
68 2df845d5 2023-07-07 op fi
69 2df845d5 2023-07-07 op
70 f73bf5bd 2023-10-01 naddy git -C "$testroot/r" checkout -q -b newbranch && \
71 f73bf5bd 2023-10-01 naddy git -C "$testroot/r" pull -q "$testroot/r.bundle" newbranch
72 2df845d5 2023-07-07 op if [ $? -ne 0 ]; then
73 2df845d5 2023-07-07 op echo "git pull failed unexpectedly" >&2
74 2df845d5 2023-07-07 op test_done "$testroot" 1
75 2df845d5 2023-07-07 op return 1
76 2df845d5 2023-07-07 op fi
77 2df845d5 2023-07-07 op
78 2df845d5 2023-07-07 op (cd "$testroot/repo" && got log -p >$testroot/repo.log)
79 2df845d5 2023-07-07 op
80 2df845d5 2023-07-07 op if ! (cd "$testroot/r" && got log -p >$testroot/r.log); then
81 2df845d5 2023-07-07 op echo "got log failed unexpectedly" >&2
82 2df845d5 2023-07-07 op test_done "$testroot" 1
83 2df845d5 2023-07-07 op return 1
84 2df845d5 2023-07-07 op fi
85 2df845d5 2023-07-07 op
86 2df845d5 2023-07-07 op if ! cmp -s "$testroot/repo.log" "$testroot/r.log"; then
87 2df845d5 2023-07-07 op echo "history differs after pull" >&2
88 2df845d5 2023-07-07 op diff -u "$testroot/repo.log" "$testroot/r.log"
89 2df845d5 2023-07-07 op test_done "$testroot" 1
90 2df845d5 2023-07-07 op return 1
91 2df845d5 2023-07-07 op fi
92 2df845d5 2023-07-07 op
93 2df845d5 2023-07-07 op test_done "$testroot" 0
94 2df845d5 2023-07-07 op }
95 2df845d5 2023-07-07 op
96 2df845d5 2023-07-07 op test_parseargs "$@"
97 2df845d5 2023-07-07 op run_test test_dump_bundle