]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5553-set-upstream.sh
tests: mark tests relying on the current default for `init.defaultBranch`
[thirdparty/git.git] / t / t5553-set-upstream.sh
CommitLineData
24bc1a12
CB
1#!/bin/sh
2
3test_description='"git fetch/pull --set-upstream" basic tests.'
334afbc7
JS
4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
24bc1a12
CB
7. ./test-lib.sh
8
9check_config () {
10 printf "%s\n" "$2" "$3" >"expect.$1" &&
11 {
12 git config "branch.$1.remote" && git config "branch.$1.merge"
13 } >"actual.$1" &&
14 test_cmp "expect.$1" "actual.$1"
15}
16
17check_config_missing () {
18 test_expect_code 1 git config "branch.$1.remote" &&
19 test_expect_code 1 git config "branch.$1.merge"
20}
21
22clear_config () {
23 for branch in "$@"; do
24 test_might_fail git config --unset-all "branch.$branch.remote"
25 test_might_fail git config --unset-all "branch.$branch.merge"
26 done
27}
28
29ensure_fresh_upstream () {
30 rm -rf parent && git init --bare parent
31}
32
33test_expect_success 'setup bare parent fetch' '
34 ensure_fresh_upstream &&
35 git remote add upstream parent
36'
37
38test_expect_success 'setup commit on master and other fetch' '
39 test_commit one &&
40 git push upstream master &&
41 git checkout -b other &&
42 test_commit two &&
43 git push upstream other
44'
45
46# tests for fetch --set-upstream
47
48test_expect_success 'fetch --set-upstream does not set upstream w/o branch' '
49 clear_config master other &&
50 git checkout master &&
51 git fetch --set-upstream upstream &&
52 check_config_missing master &&
53 check_config_missing other
54'
55
56test_expect_success 'fetch --set-upstream upstream master sets branch master but not other' '
57 clear_config master other &&
58 git fetch --set-upstream upstream master &&
59 check_config master upstream refs/heads/master &&
60 check_config_missing other
61'
62
63test_expect_success 'fetch --set-upstream upstream other sets branch other' '
64 clear_config master other &&
65 git fetch --set-upstream upstream other &&
66 check_config master upstream refs/heads/other &&
67 check_config_missing other
68'
69
70test_expect_success 'fetch --set-upstream master:other does not set the branch other2' '
71 clear_config other2 &&
72 git fetch --set-upstream upstream master:other2 &&
73 check_config_missing other2
74'
75
76test_expect_success 'fetch --set-upstream http://nosuchdomain.example.com fails with invalid url' '
77 # master explicitly not cleared, we check that it is not touched from previous value
78 clear_config other other2 &&
79 test_must_fail git fetch --set-upstream http://nosuchdomain.example.com &&
80 check_config master upstream refs/heads/other &&
81 check_config_missing other &&
82 check_config_missing other2
83'
84
85test_expect_success 'fetch --set-upstream with valid URL sets upstream to URL' '
86 clear_config other other2 &&
c76b84a1 87 url="file://$PWD" &&
24bc1a12
CB
88 git fetch --set-upstream "$url" &&
89 check_config master "$url" HEAD &&
90 check_config_missing other &&
91 check_config_missing other2
92'
93
94# tests for pull --set-upstream
95
96test_expect_success 'setup bare parent pull' '
97 git remote rm upstream &&
98 ensure_fresh_upstream &&
99 git remote add upstream parent
100'
101
102test_expect_success 'setup commit on master and other pull' '
103 test_commit three &&
104 git push --tags upstream master &&
105 test_commit four &&
106 git push upstream other
107'
108
109test_expect_success 'pull --set-upstream upstream master sets branch master but not other' '
110 clear_config master other &&
111 git pull --set-upstream upstream master &&
112 check_config master upstream refs/heads/master &&
113 check_config_missing other
114'
115
116test_expect_success 'pull --set-upstream master:other2 does not set the branch other2' '
117 clear_config other2 &&
118 git pull --set-upstream upstream master:other2 &&
119 check_config_missing other2
120'
121
122test_expect_success 'pull --set-upstream upstream other sets branch master' '
123 clear_config master other &&
124 git pull --set-upstream upstream other &&
125 check_config master upstream refs/heads/other &&
126 check_config_missing other
127'
128
129test_expect_success 'pull --set-upstream upstream tag does not set the tag' '
130 clear_config three &&
131 git pull --tags --set-upstream upstream three &&
132 check_config_missing three
133'
134
135test_expect_success 'pull --set-upstream http://nosuchdomain.example.com fails with invalid url' '
136 # master explicitly not cleared, we check that it is not touched from previous value
137 clear_config other other2 three &&
138 test_must_fail git pull --set-upstream http://nosuchdomain.example.com &&
139 check_config master upstream refs/heads/other &&
140 check_config_missing other &&
141 check_config_missing other2 &&
142 check_config_missing three
143'
144
145test_expect_success 'pull --set-upstream upstream HEAD sets branch HEAD' '
146 clear_config master other &&
147 git pull --set-upstream upstream HEAD &&
148 check_config master upstream HEAD &&
149 git checkout other &&
150 git pull --set-upstream upstream HEAD &&
151 check_config other upstream HEAD
152'
153
154test_expect_success 'pull --set-upstream upstream with more than one branch does nothing' '
155 clear_config master three &&
156 git pull --set-upstream upstream master three &&
157 check_config_missing master &&
158 check_config_missing three
159'
160
161test_expect_success 'pull --set-upstream with valid URL sets upstream to URL' '
162 clear_config master other other2 &&
163 git checkout master &&
c76b84a1 164 url="file://$PWD" &&
24bc1a12
CB
165 git pull --set-upstream "$url" &&
166 check_config master "$url" HEAD &&
167 check_config_missing other &&
168 check_config_missing other2
169'
170
171test_expect_success 'pull --set-upstream with valid URL and branch sets branch' '
172 clear_config master other other2 &&
173 git checkout master &&
c76b84a1 174 url="file://$PWD" &&
24bc1a12
CB
175 git pull --set-upstream "$url" master &&
176 check_config master "$url" refs/heads/master &&
177 check_config_missing other &&
178 check_config_missing other2
179'
180
181test_done