Skip to content

Commit

Permalink
submodule: pass on http.extraheader config settings
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
dscho committed Apr 28, 2016
1 parent 3b71def commit 89d0024
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion builtin/submodule--helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ static int module_name(int argc, const char **argv, const char *prefix)
*/
static int submodule_config_ok(const char *var)
{
if (starts_with(var, "credential."))
if (starts_with(var, "credential.") ||
(starts_with(var, "http.") &&
ends_with(var, ".extraheader")))
return 1;
return 0;
}
Expand Down
11 changes: 10 additions & 1 deletion t/t5551-http-fetch-smart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,16 @@ test_expect_success 'custom http headers' '
test_must_fail git fetch "$HTTPD_URL/smart_headers/repo.git" &&
git -c http.extraheader="x-magic-one: abra" \
-c http.extraheader="x-magic-two: cadabra" \
fetch "$HTTPD_URL/smart_headers/repo.git"
fetch "$HTTPD_URL/smart_headers/repo.git" &&
git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&
git config -f .gitmodules submodule.sub.path sub &&
git config -f .gitmodules submodule.sub.url \
"$HTTPD_URL/smart_headers/repo.git" &&
git submodule init sub &&
test_must_fail git submodule update sub &&
git -c http.extraheader="x-magic-one: abra" \
-c http.extraheader="x-magic-two: cadabra" \
submodule update sub
'

stop_httpd
Expand Down

0 comments on commit 89d0024

Please sign in to comment.