The 19th batch
[alt-git.git] / t / t5519-push-alternates.sh
blob72e97b15fabbb821eaf5d88a24fee0ae4c8de6f8
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_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 test_expect_success setup '
12 mkdir alice-pub &&
14 cd alice-pub &&
15 GIT_DIR=. git init
16 ) &&
17 mkdir alice-work &&
19 cd alice-work &&
20 git init &&
21 >file &&
22 git add . &&
23 git commit -m initial &&
24 git push ../alice-pub main
25 ) &&
27 # Project Bob is a fork of project Alice
28 mkdir bob-pub &&
30 cd bob-pub &&
31 GIT_DIR=. git init &&
32 mkdir -p objects/info &&
33 echo ../../alice-pub/objects >objects/info/alternates
34 ) &&
35 git clone alice-pub bob-work &&
37 cd bob-work &&
38 git push ../bob-pub main
42 test_expect_success 'alice works and pushes' '
44 cd alice-work &&
45 echo more >file &&
46 git commit -a -m second &&
47 git push ../alice-pub :
51 test_expect_success 'bob fetches from alice, works and pushes' '
53 # Bob acquires what Alice did in his work tree first.
54 # Even though these objects are not directly in
55 # the public repository of Bob, this push does not
56 # need to send the commit Bob received from Alice
57 # to his public repository, as all the object Alice
58 # has at her public repository are available to it
59 # via its alternates.
60 cd bob-work &&
61 git pull ../alice-pub main &&
62 echo more bob >file &&
63 git commit -a -m third &&
64 git push ../bob-pub :
65 ) &&
67 # Check that the second commit by Alice is not sent
68 # to ../bob-pub
70 cd bob-pub &&
71 second=$(git rev-parse HEAD^) &&
72 rm -f objects/info/alternates &&
73 test_must_fail git cat-file -t $second &&
74 echo ../../alice-pub/objects >objects/info/alternates
78 test_expect_success 'clean-up in case the previous failed' '
80 cd bob-pub &&
81 echo ../../alice-pub/objects >objects/info/alternates
85 test_expect_success 'alice works and pushes again' '
87 # Alice does not care what Bob does. She does not
88 # even have to be aware of his existence. She just
89 # keeps working and pushing
90 cd alice-work &&
91 echo more alice >file &&
92 git commit -a -m fourth &&
93 git push ../alice-pub :
97 test_expect_success 'bob works and pushes' '
99 # This time Bob does not pull from Alice, and
100 # the main branch at her public repository points
101 # at a commit Bob does not know about. This should
102 # not prevent the push by Bob from succeeding.
103 cd bob-work &&
104 echo yet more bob >file &&
105 git commit -a -m fifth &&
106 git push ../bob-pub :
110 test_expect_success 'alice works and pushes yet again' '
112 # Alice does not care what Bob does. She does not
113 # even have to be aware of his existence. She just
114 # keeps working and pushing
115 cd alice-work &&
116 echo more and more alice >file &&
117 git commit -a -m sixth.1 &&
118 echo more and more alice >>file &&
119 git commit -a -m sixth.2 &&
120 echo more and more alice >>file &&
121 git commit -a -m sixth.3 &&
122 git push ../alice-pub :
126 test_expect_success 'bob works and pushes again' '
128 cd alice-pub &&
129 git cat-file commit main >../bob-work/commit
130 ) &&
132 # This time Bob does not pull from Alice, and
133 # the main branch at her public repository points
134 # at a commit Bob does not fully know about, but
135 # he happens to have the commit object (but not the
136 # necessary tree) in his repository from Alice.
137 # This should not prevent the push by Bob from
138 # succeeding.
139 cd bob-work &&
140 git hash-object -t commit -w commit &&
141 echo even more bob >file &&
142 git commit -a -m seventh &&
143 git push ../bob-pub :
147 test_done