Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2024 Stefan Sperling <stsp@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 . ../cmdline/common.sh
18 . ./common.sh
20 test_fetch_with_git_history_walk() {
21 local testroot=`test_init fetch_with_git_history_walk 1`
23 git clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone \
24 2> $testroot/stderr
25 ret=$?
26 if [ $ret -ne 0 ]; then
27 echo "git clone failed unexpectedly" >&2
28 test_done "$testroot" "1"
29 return 1
30 fi
32 # Create new commits on a branch which doesn't exist in gotd repo.
33 # We want Git to send a flush-pkt followed by more have-lines. This
34 # requires at least 16 commits (fetch-pack.c:INITIAL_FLUSH 16).
35 git -C $testroot/repo-clone branch newbranch
36 for i in `seq 24`; do
37 echo $i >> $testroot/repo-clone/file$i
38 git -C $testroot/repo-clone add file$i
39 git_commit $testroot/repo-clone -m "add file$i"
40 ret=$?
41 if [ $ret -ne 0 ]; then
42 echo "git commit failed unexpectedly" >&2
43 test_done "$testroot" "1"
44 return 1
45 fi
46 done
48 git clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone2 \
49 2> $testroot/stderr
50 ret=$?
51 if [ $ret -ne 0 ]; then
52 echo "git clone failed unexpectedly" >&2
53 test_done "$testroot" "1"
54 return 1
55 fi
57 # create new commits on main branch, and push to gotd
58 for i in `seq 2`; do
59 echo $i >> $testroot/repo-clone2/file$i
60 git -C $testroot/repo-clone2 add file$i
61 git_commit $testroot/repo-clone2 -m "add file$i"
62 ret=$?
63 if [ $ret -ne 0 ]; then
64 echo "git commit failed unexpectedly" >&2
65 test_done "$testroot" "1"
66 return 1
67 fi
68 done
70 git -C $testroot/repo-clone2 push -q origin main
71 ret=$?
72 if [ $ret -ne 0 ]; then
73 echo "git push failed unexpectedly" >&2
74 test_done "$testroot" "1"
75 return 1
76 fi
78 # Fetching changes into the first repository clone should work.
79 # This used to fail because gotd rejected additional have-lines
80 # once Git had sent a flush-pkt.
81 git -C $testroot/repo-clone fetch -q 2> $testroot/stderr
82 ret=$?
83 if [ $ret -ne 0 ]; then
84 echo "git fetch failed unexpectedly" >&2
85 test_done "$testroot" "1"
86 return 1
87 fi
89 test_done "$testroot" "0"
90 }
92 run_test test_fetch_with_git_history_walk