]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5519-push-alternates.sh
Sync with Git 2.45.1
[thirdparty/git.git] / t / t5519-push-alternates.sh
CommitLineData
02322e16
JH
1#!/bin/sh
2
3test_description='push to a repository that borrows from elsewhere'
4
bc925ce3 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
02322e16
JH
8. ./test-lib.sh
9
10test_expect_success setup '
11 mkdir alice-pub &&
12 (
13 cd alice-pub &&
14 GIT_DIR=. git init
15 ) &&
16 mkdir alice-work &&
17 (
18 cd alice-work &&
19 git init &&
20 >file &&
21 git add . &&
22 git commit -m initial &&
bc925ce3 23 git push ../alice-pub main
02322e16
JH
24 ) &&
25
26 # Project Bob is a fork of project Alice
27 mkdir bob-pub &&
28 (
29 cd bob-pub &&
30 GIT_DIR=. git init &&
31 mkdir -p objects/info &&
32 echo ../../alice-pub/objects >objects/info/alternates
33 ) &&
34 git clone alice-pub bob-work &&
35 (
36 cd bob-work &&
bc925ce3 37 git push ../bob-pub main
02322e16
JH
38 )
39'
40
41test_expect_success 'alice works and pushes' '
42 (
43 cd alice-work &&
44 echo more >file &&
45 git commit -a -m second &&
f3258d3d 46 git push ../alice-pub :
02322e16
JH
47 )
48'
49
50test_expect_success 'bob fetches from alice, works and pushes' '
51 (
52 # Bob acquires what Alice did in his work tree first.
53 # Even though these objects are not directly in
54 # the public repository of Bob, this push does not
55 # need to send the commit Bob received from Alice
56 # to his public repository, as all the object Alice
57 # has at her public repository are available to it
58 # via its alternates.
59 cd bob-work &&
bc925ce3 60 git pull ../alice-pub main &&
02322e16
JH
61 echo more bob >file &&
62 git commit -a -m third &&
f3258d3d 63 git push ../bob-pub :
02322e16
JH
64 ) &&
65
66 # Check that the second commit by Alice is not sent
67 # to ../bob-pub
68 (
69 cd bob-pub &&
70 second=$(git rev-parse HEAD^) &&
71 rm -f objects/info/alternates &&
72 test_must_fail git cat-file -t $second &&
73 echo ../../alice-pub/objects >objects/info/alternates
74 )
75'
76
77test_expect_success 'clean-up in case the previous failed' '
78 (
79 cd bob-pub &&
80 echo ../../alice-pub/objects >objects/info/alternates
81 )
82'
83
84test_expect_success 'alice works and pushes again' '
85 (
86 # Alice does not care what Bob does. She does not
87 # even have to be aware of his existence. She just
88 # keeps working and pushing
89 cd alice-work &&
90 echo more alice >file &&
91 git commit -a -m fourth &&
f3258d3d 92 git push ../alice-pub :
02322e16
JH
93 )
94'
95
96test_expect_success 'bob works and pushes' '
97 (
98 # This time Bob does not pull from Alice, and
bc925ce3 99 # the main branch at her public repository points
02322e16
JH
100 # at a commit Bob does not know about. This should
101 # not prevent the push by Bob from succeeding.
102 cd bob-work &&
103 echo yet more bob >file &&
104 git commit -a -m fifth &&
f3258d3d 105 git push ../bob-pub :
02322e16
JH
106 )
107'
108
aeeae1b7
JH
109test_expect_success 'alice works and pushes yet again' '
110 (
111 # Alice does not care what Bob does. She does not
112 # even have to be aware of his existence. She just
113 # keeps working and pushing
114 cd alice-work &&
115 echo more and more alice >file &&
116 git commit -a -m sixth.1 &&
117 echo more and more alice >>file &&
118 git commit -a -m sixth.2 &&
119 echo more and more alice >>file &&
120 git commit -a -m sixth.3 &&
f3258d3d 121 git push ../alice-pub :
aeeae1b7
JH
122 )
123'
124
125test_expect_success 'bob works and pushes again' '
126 (
127 cd alice-pub &&
bc925ce3 128 git cat-file commit main >../bob-work/commit
a48fcd83 129 ) &&
aeeae1b7
JH
130 (
131 # This time Bob does not pull from Alice, and
bc925ce3 132 # the main branch at her public repository points
aeeae1b7
JH
133 # at a commit Bob does not fully know about, but
134 # he happens to have the commit object (but not the
135 # necessary tree) in his repository from Alice.
136 # This should not prevent the push by Bob from
137 # succeeding.
138 cd bob-work &&
139 git hash-object -t commit -w commit &&
140 echo even more bob >file &&
141 git commit -a -m seventh &&
f3258d3d 142 git push ../bob-pub :
aeeae1b7
JH
143 )
144'
145
02322e16 146test_done