Blob


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