From 2f0951b216489ecbd0a28935ca589fb0067a8381 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 10 Jul 2019 17:13:46 -0400 Subject: git_command: set GIT_HTTP_USER_AGENT on all requests We've been setting the User-Agent header when making connections from repo itself, but not when running git (as the latter will set up User-Agent itself). Our Gerrit/Git admins say it'll be helpful if we pass through the repo version settings even when running git. We currently set GIT_HTTP_USER_AGENT and not GIT_USER_AGENT as it's unclear if the extended form works over all protocols. We can wait for a user request. Bug: https://crbug.com/gerrit/11144 Change-Id: I21d293f49534058dbc23225152451df26c5b7bef Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/239233 Tested-by: Mike Frysinger Reviewed-by: David Pursehouse --- git_command.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'git_command.py') diff --git a/git_command.py b/git_command.py index a4081f45..dc542c36 100644 --- a/git_command.py +++ b/git_command.py @@ -134,6 +134,7 @@ class UserAgent(object): _os = None _repo_ua = None + _git_ua = None @property def os(self): @@ -165,6 +166,17 @@ class UserAgent(object): return self._repo_ua + @property + def git(self): + """The UA when running git.""" + if self._git_ua is None: + self._git_ua = 'git/%s (%s) git-repo/%s' % ( + git.version_tuple().full, + self.os, + RepoSourceVersion()) + + return self._git_ua + user_agent = UserAgent() def git_require(min_version, fail=False, msg=''): @@ -214,6 +226,7 @@ class GitCommand(object): if 'GIT_ALLOW_PROTOCOL' not in env: _setenv(env, 'GIT_ALLOW_PROTOCOL', 'file:git:http:https:ssh:persistent-http:persistent-https:sso:rpc') + _setenv(env, 'GIT_HTTP_USER_AGENT', user_agent.git) if project: if not cwd: -- cgit v1.2.3-54-g00ecf