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