t8*: adjust the references to the default branch name "main"
[git] / t / t5519-push-alternates.sh
1 #!/bin/sh
2
3 test_description='push to a repository that borrows from elsewhere'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 test_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 &&
23                 git push ../alice-pub main
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 &&
37                 git push ../bob-pub main
38         )
39 '
40
41 test_expect_success 'alice works and pushes' '
42         (
43                 cd alice-work &&
44                 echo more >file &&
45                 git commit -a -m second &&
46                 git push ../alice-pub :
47         )
48 '
49
50 test_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 &&
60                 git pull ../alice-pub main &&
61                 echo more bob >file &&
62                 git commit -a -m third &&
63                 git push ../bob-pub :
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
77 test_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
84 test_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 &&
92                 git push ../alice-pub :
93         )
94 '
95
96 test_expect_success 'bob works and pushes' '
97         (
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 :
106         )
107 '
108
109 test_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 &&
121                 git push ../alice-pub :
122         )
123 '
124
125 test_expect_success 'bob works and pushes again' '
126         (
127                 cd alice-pub &&
128                 git cat-file commit main >../bob-work/commit
129         ) &&
130         (
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 :
143         )
144 '
145
146 test_done