Sync with 2.44.1
[git/gitster.git] / t / t5519-push-alternates.sh
blob20ba604dfde1629b5ab75226f41ef2e4b3814d07
1 #!/bin/sh
3 test_description='push to a repository that borrows from elsewhere'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 . ./test-lib.sh
10 test_expect_success setup '
11 mkdir alice-pub &&
13 cd alice-pub &&
14 GIT_DIR=. git init
15 ) &&
16 mkdir alice-work &&
18 cd alice-work &&
19 git init &&
20 >file &&
21 git add . &&
22 git commit -m initial &&
23 git push ../alice-pub main
24 ) &&
26 # Project Bob is a fork of project Alice
27 mkdir bob-pub &&
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 &&
36 cd bob-work &&
37 git push ../bob-pub main
41 test_expect_success 'alice works and pushes' '
43 cd alice-work &&
44 echo more >file &&
45 git commit -a -m second &&
46 git push ../alice-pub :
50 test_expect_success 'bob fetches from alice, works and pushes' '
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 &&
60 git pull ../alice-pub main &&
61 echo more bob >file &&
62 git commit -a -m third &&
63 git push ../bob-pub :
64 ) &&
66 # Check that the second commit by Alice is not sent
67 # to ../bob-pub
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
77 test_expect_success 'clean-up in case the previous failed' '
79 cd bob-pub &&
80 echo ../../alice-pub/objects >objects/info/alternates
84 test_expect_success 'alice works and pushes again' '
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 &&
92 git push ../alice-pub :
96 test_expect_success 'bob works and pushes' '
98 # This time Bob does not pull from Alice, and
99 # the main branch at her public repository points
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 &&
105 git push ../bob-pub :
109 test_expect_success 'alice works and pushes yet again' '
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 &&
121 git push ../alice-pub :
125 test_expect_success 'bob works and pushes again' '
127 cd alice-pub &&
128 git cat-file commit main >../bob-work/commit
129 ) &&
131 # This time Bob does not pull from Alice, and
132 # the main branch at her public repository points
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 &&
142 git push ../bob-pub :
146 test_done