Skip to content

Commit 89d0024

Browse files
committed
submodule: pass on http.extraheader config settings
To support this developer's use case of allowing build agents token-based access to private repositories, we introduced the http.extraheader feature, allowing extra HTTP headers to be sent along with every HTTP request. This patch allows us to configure these extra HTTP headers for use with `git submodule update`, too. It requires somewhat special handling: submodules do not share the parent project's config. It would be incorrect to simply reuse that specific part of the parent's config. Instead, the config option needs to be specified on the command-line or in ~/.gitconfig or friends. Example: git -c http.extraheader="Secret: Sauce" submodule update --init Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 3b71def commit 89d0024

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

builtin/submodule--helper.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ static int module_name(int argc, const char **argv, const char *prefix)
127127
*/
128128
static int submodule_config_ok(const char *var)
129129
{
130-
if (starts_with(var, "credential."))
130+
if (starts_with(var, "credential.") ||
131+
(starts_with(var, "http.") &&
132+
ends_with(var, ".extraheader")))
131133
return 1;
132134
return 0;
133135
}

t/t5551-http-fetch-smart.sh

+10-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,16 @@ test_expect_success 'custom http headers' '
286286
test_must_fail git fetch "$HTTPD_URL/smart_headers/repo.git" &&
287287
git -c http.extraheader="x-magic-one: abra" \
288288
-c http.extraheader="x-magic-two: cadabra" \
289-
fetch "$HTTPD_URL/smart_headers/repo.git"
289+
fetch "$HTTPD_URL/smart_headers/repo.git" &&
290+
git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&
291+
git config -f .gitmodules submodule.sub.path sub &&
292+
git config -f .gitmodules submodule.sub.url \
293+
"$HTTPD_URL/smart_headers/repo.git" &&
294+
git submodule init sub &&
295+
test_must_fail git submodule update sub &&
296+
git -c http.extraheader="x-magic-one: abra" \
297+
-c http.extraheader="x-magic-two: cadabra" \
298+
submodule update sub
290299
'
291300

292301
stop_httpd

0 commit comments

Comments
 (0)