config: unify code paths to get global config paths
[git] / t / t5521-pull-options.sh
1 #!/bin/sh
2
3 test_description='pull options'
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 parent &&
12         (cd parent && git init &&
13          echo one >file && git add file &&
14          git commit -m one)
15 '
16
17 test_expect_success 'git pull -q --no-rebase' '
18         mkdir clonedq &&
19         (cd clonedq && git init &&
20         git pull -q --no-rebase "../parent" >out 2>err &&
21         test_must_be_empty err &&
22         test_must_be_empty out)
23 '
24
25 test_expect_success 'git pull -q --rebase' '
26         mkdir clonedqrb &&
27         (cd clonedqrb && git init &&
28         git pull -q --rebase "../parent" >out 2>err &&
29         test_must_be_empty err &&
30         test_must_be_empty out &&
31         git pull -q --rebase "../parent" >out 2>err &&
32         test_must_be_empty err &&
33         test_must_be_empty out)
34 '
35
36 test_expect_success 'git pull --no-rebase' '
37         mkdir cloned &&
38         (cd cloned && git init &&
39         git pull --no-rebase "../parent" >out 2>err &&
40         test -s err &&
41         test_must_be_empty out)
42 '
43
44 test_expect_success 'git pull --rebase' '
45         mkdir clonedrb &&
46         (cd clonedrb && git init &&
47         git pull --rebase "../parent" >out 2>err &&
48         test -s err &&
49         test_must_be_empty out)
50 '
51
52 test_expect_success 'git pull -v --no-rebase' '
53         mkdir clonedv &&
54         (cd clonedv && git init &&
55         git pull -v --no-rebase "../parent" >out 2>err &&
56         test -s err &&
57         test_must_be_empty out)
58 '
59
60 test_expect_success 'git pull -v --rebase' '
61         mkdir clonedvrb &&
62         (cd clonedvrb && git init &&
63         git pull -v --rebase "../parent" >out 2>err &&
64         test -s err &&
65         test_must_be_empty out)
66 '
67
68 test_expect_success 'git pull -v -q --no-rebase' '
69         mkdir clonedvq &&
70         (cd clonedvq && git init &&
71         git pull -v -q --no-rebase "../parent" >out 2>err &&
72         test_must_be_empty out &&
73         test_must_be_empty err)
74 '
75
76 test_expect_success 'git pull -q -v --no-rebase' '
77         mkdir clonedqv &&
78         (cd clonedqv && git init &&
79         git pull -q -v --no-rebase "../parent" >out 2>err &&
80         test_must_be_empty out &&
81         test -s err)
82 '
83 test_expect_success 'git pull --cleanup errors early on invalid argument' '
84         mkdir clonedcleanup &&
85         (cd clonedcleanup && git init &&
86         test_must_fail git pull --no-rebase --cleanup invalid "../parent" >out 2>err &&
87         test_must_be_empty out &&
88         test -s err)
89 '
90
91 test_expect_success 'git pull --no-write-fetch-head fails' '
92         mkdir clonedwfh &&
93         (cd clonedwfh && git init &&
94         test_expect_code 129 git pull --no-write-fetch-head "../parent" >out 2>err &&
95         test_must_be_empty out &&
96         test_i18ngrep "no-write-fetch-head" err)
97 '
98
99 test_expect_success 'git pull --force' '
100         mkdir clonedoldstyle &&
101         (cd clonedoldstyle && git init &&
102         cat >>.git/config <<-\EOF &&
103         [remote "one"]
104                 url = ../parent
105                 fetch = refs/heads/main:refs/heads/mirror
106         [remote "two"]
107                 url = ../parent
108                 fetch = refs/heads/main:refs/heads/origin
109         [branch "main"]
110                 remote = two
111                 merge = refs/heads/main
112         EOF
113         git pull two &&
114         test_commit A &&
115         git branch -f origin &&
116         git pull --all --force
117         )
118 '
119
120 test_expect_success 'git pull --all' '
121         mkdir clonedmulti &&
122         (cd clonedmulti && git init &&
123         cat >>.git/config <<-\EOF &&
124         [remote "one"]
125                 url = ../parent
126                 fetch = refs/heads/*:refs/remotes/one/*
127         [remote "two"]
128                 url = ../parent
129                 fetch = refs/heads/*:refs/remotes/two/*
130         [branch "main"]
131                 remote = one
132                 merge = refs/heads/main
133         EOF
134         git pull --all
135         )
136 '
137
138 test_expect_success 'git pull --dry-run' '
139         test_when_finished "rm -rf clonedry" &&
140         git init clonedry &&
141         (
142                 cd clonedry &&
143                 git pull --dry-run ../parent &&
144                 test_path_is_missing .git/FETCH_HEAD &&
145                 test_path_is_missing .git/refs/heads/main &&
146                 test_path_is_missing .git/index &&
147                 test_path_is_missing file
148         )
149 '
150
151 test_expect_success 'git pull --all --dry-run' '
152         test_when_finished "rm -rf cloneddry" &&
153         git init clonedry &&
154         (
155                 cd clonedry &&
156                 git remote add origin ../parent &&
157                 git pull --all --dry-run &&
158                 test_path_is_missing .git/FETCH_HEAD &&
159                 test_path_is_missing .git/refs/remotes/origin/main &&
160                 test_path_is_missing .git/index &&
161                 test_path_is_missing file
162         )
163 '
164
165 test_expect_success 'git pull --allow-unrelated-histories' '
166         test_when_finished "rm -fr src dst" &&
167         git init src &&
168         (
169                 cd src &&
170                 test_commit one &&
171                 test_commit two
172         ) &&
173         git clone src dst &&
174         (
175                 cd src &&
176                 git checkout --orphan side HEAD^ &&
177                 test_commit three
178         ) &&
179         (
180                 cd dst &&
181                 test_must_fail git pull ../src side &&
182                 git pull --allow-unrelated-histories ../src side
183         )
184 '
185
186 test_expect_success 'git pull does not add a sign-off line' '
187         test_when_finished "rm -fr src dst actual" &&
188         git init src &&
189         test_commit -C src one &&
190         git clone src dst &&
191         test_commit -C src two &&
192         git -C dst pull --no-ff &&
193         git -C dst show -s --pretty="format:%(trailers)" HEAD >actual &&
194         test_must_be_empty actual
195 '
196
197 test_expect_success 'git pull --no-signoff does not add sign-off line' '
198         test_when_finished "rm -fr src dst actual" &&
199         git init src &&
200         test_commit -C src one &&
201         git clone src dst &&
202         test_commit -C src two &&
203         git -C dst pull --no-signoff --no-ff &&
204         git -C dst show -s --pretty="format:%(trailers)" HEAD >actual &&
205         test_must_be_empty actual
206 '
207
208 test_expect_success 'git pull --signoff add a sign-off line' '
209         test_when_finished "rm -fr src dst expected actual" &&
210         echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected &&
211         git init src &&
212         test_commit -C src one &&
213         git clone src dst &&
214         test_commit -C src two &&
215         git -C dst pull --signoff --no-ff &&
216         git -C dst show -s --pretty="format:%(trailers)" HEAD >actual &&
217         test_cmp expected actual
218 '
219
220 test_expect_success 'git pull --no-signoff flag cancels --signoff flag' '
221         test_when_finished "rm -fr src dst actual" &&
222         git init src &&
223         test_commit -C src one &&
224         git clone src dst &&
225         test_commit -C src two &&
226         git -C dst pull --signoff --no-signoff --no-ff &&
227         git -C dst show -s --pretty="format:%(trailers)" HEAD >actual &&
228         test_must_be_empty actual
229 '
230
231 test_done