aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMichael Stapelberg <stapelberg@debian.org>2016-11-24 12:17:50 +0100
committerGuido Günther <agx@sigxcpu.org>2016-12-19 08:32:38 +0100
commit67cf3ed1bb667816baff586b75d991142d1840ef (patch)
tree96e3e5187658afb22288d9b410fc5e1abe4efad3
parent9cbb9df7d8e05ce9c356216e3c4ac190141c0d02 (diff)
gbp clone: configure user.email, user.name from DEBEMAIL/DEBFULLNAME
Signed-off-by: Guido Günther <agx@sigxcpu.org> Close: #845536
-rw-r--r--gbp/config.py12
-rw-r--r--gbp/git/repository.py18
-rwxr-xr-xgbp/scripts/clone.py7
-rw-r--r--gbp/scripts/common/repo_setup.py30
-rw-r--r--gbp/scripts/import_dsc.py8
-rwxr-xr-xgbp/scripts/import_srpm.py8
-rw-r--r--tests/component/deb/test_clone.py24
-rw-r--r--tests/doctests/test_GitRepository.py13
8 files changed, 119 insertions, 1 deletions
diff --git a/gbp/config.py b/gbp/config.py
index 149a1bb4..18a3afc5 100644
--- a/gbp/config.py
+++ b/gbp/config.py
@@ -181,6 +181,8 @@ class GbpOptionParser(OptionParser):
'component': [],
'bare': 'True',
'urgency': 'medium',
+ 'repo-user': 'DEBIAN',
+ 'repo-email': 'DEBIAN',
}
help = {
'debian-branch':
@@ -350,7 +352,15 @@ class GbpOptionParser(OptionParser):
"wether to create a bare repository on the remote side. "
"'Default is '%(bare)s'.",
'urgency':
- "Set urgency level, default is '%(urgency)s'"
+ "Set urgency level, default is '%(urgency)s'",
+ 'repo-user':
+ "Set repo username from the DEBFULLNAME and DEBEMAIL "
+ "environment variables ('DEBIAN') or fallback to the "
+ "git configuration ('GIT'), default is '%(repo-user)s'",
+ 'repo-email':
+ "Set repo email from the DEBFULLNAME and DEBEMAIL "
+ "environment variables ('DEBIAN') or fallback to the "
+ "git configuration ('GIT'), default is '%(repo-email)s'"
}
short_opts = {
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index 2f1b71bf..644fc7b4 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -1063,6 +1063,24 @@ class GitRepository(object):
raise KeyError
return value[0][:-1] # first line with \n ending removed
+ def set_user_name(self, name):
+ """
+ Sets the full name to use for git commits.
+
+ @param name: full name to use
+ """
+ args = GitArgs('user.name', name)
+ self._git_command("config", args.args)
+
+ def set_user_email(self, email):
+ """
+ Sets the email address to use for git commits.
+
+ @param email: email address to use
+ """
+ args = GitArgs('user.email', email)
+ self._git_command("config", args.args)
+
def get_author_info(self):
"""
Determine a sane values for author name and author email from git's
diff --git a/gbp/scripts/clone.py b/gbp/scripts/clone.py
index 63b1468a..0afa54c4 100755
--- a/gbp/scripts/clone.py
+++ b/gbp/scripts/clone.py
@@ -26,6 +26,7 @@ from gbp.deb.git import DebianGitRepository
from gbp.git import (GitRepository, GitRepositoryError)
from gbp.errors import GbpError
from gbp.scripts.common import ExitCodes
+from gbp.scripts.common import repo_setup
from gbp.scripts.common.hook import Hook
import gbp.log
@@ -62,6 +63,10 @@ def build_parser(name):
parser.add_config_file_option(option_name="color", dest="color", type='tristate')
parser.add_config_file_option(option_name="color-scheme",
dest="color_scheme")
+ parser.add_config_file_option(option_name="repo-user", dest="repo_user",
+ choices=['DEBIAN', 'GIT'])
+ parser.add_config_file_option(option_name="repo-email", dest="repo_email",
+ choices=['DEBIAN', 'GIT'])
return parser
@@ -128,6 +133,8 @@ def main(argv):
repo.set_branch(options.debian_branch)
+ repo_setup.set_user_name_and_email(options.repo_user, options.repo_email, repo)
+
if postclone:
Hook('Postclone', options.postclone,
extra_env={'GBP_GIT_DIR': repo.git_dir},
diff --git a/gbp/scripts/common/repo_setup.py b/gbp/scripts/common/repo_setup.py
new file mode 100644
index 00000000..4e52c45c
--- /dev/null
+++ b/gbp/scripts/common/repo_setup.py
@@ -0,0 +1,30 @@
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2006-2011, 2016 Guido Guenther <agx@sigxcpu.org>
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, please see
+# <http://www.gnu.org/licenses/>
+#
+"""Common repository setup functionality."""
+
+import os
+
+
+def set_user_name_and_email(repo_user, repo_email, repo):
+ if repo_user == 'DEBIAN':
+ if os.getenv('DEBFULLNAME'):
+ repo.set_user_name(os.getenv('DEBFULLNAME'))
+
+ if repo_email == 'DEBIAN':
+ if os.getenv('DEBEMAIL'):
+ repo.set_user_email(os.getenv('DEBEMAIL'))
diff --git a/gbp/scripts/import_dsc.py b/gbp/scripts/import_dsc.py
index 61130322..300c2366 100644
--- a/gbp/scripts/import_dsc.py
+++ b/gbp/scripts/import_dsc.py
@@ -35,6 +35,7 @@ from gbp.config import (GbpOptionParserDebian, GbpOptionGroup,
no_upstream_branch_msg)
from gbp.errors import GbpError
from gbp.scripts.common import ExitCodes
+from gbp.scripts.common import repo_setup
import gbp.log
@@ -269,6 +270,11 @@ def build_parser(name):
dest="author_committer_date")
import_group.add_boolean_config_file_option(option_name="allow-unauthenticated",
dest="allow_unauthenticated")
+
+ parser.add_config_file_option(option_name="repo-user", dest="repo_user",
+ choices=['DEBIAN', 'GIT'])
+ parser.add_config_file_option(option_name="repo-email", dest="repo_email",
+ choices=['DEBIAN', 'GIT'])
return parser
@@ -341,6 +347,8 @@ def main(argv):
if repo.bare:
disable_pristine_tar(options, "Bare repository")
+ repo_setup.set_user_name_and_email(options.repo_user, options.repo_email, repo)
+
dirs['tmp'] = os.path.abspath(tempfile.mkdtemp(dir='..'))
upstream = DebianUpstreamSource(src.tgz)
upstream.unpack(dirs['tmp'], options.filters)
diff --git a/gbp/scripts/import_srpm.py b/gbp/scripts/import_srpm.py
index f98a6598..e483191e 100755
--- a/gbp/scripts/import_srpm.py
+++ b/gbp/scripts/import_srpm.py
@@ -37,6 +37,7 @@ from gbp.config import (GbpOptionParserRpm, GbpOptionGroup,
no_upstream_branch_msg)
from gbp.errors import GbpError
from gbp.scripts.common import ExitCodes
+from gbp.scripts.common import repo_setup
import gbp.log
from gbp.pkg import parse_archive_filename
@@ -186,6 +187,11 @@ def build_parser(name):
dest="author_is_committer")
import_group.add_config_file_option(option_name="packaging-dir",
dest="packaging_dir")
+
+ parser.add_config_file_option(option_name="repo-user", dest="repo_user",
+ choices=['DEBIAN', 'GIT'])
+ parser.add_config_file_option(option_name="repo-email", dest="repo_email",
+ choices=['DEBIAN', 'GIT'])
return parser
@@ -273,6 +279,8 @@ def main(argv):
repo = RpmGitRepository.create(target)
os.chdir(repo.path)
+ repo_setup.set_user_name_and_email(options.repo_user, options.repo_email, repo)
+
if repo.bare:
set_bare_repo_options(options)
diff --git a/tests/component/deb/test_clone.py b/tests/component/deb/test_clone.py
index 0c3ba2cc..61bf46e2 100644
--- a/tests/component/deb/test_clone.py
+++ b/tests/component/deb/test_clone.py
@@ -72,3 +72,27 @@ class TestClone(ComponentTestBase):
self._check_repo_state(cloned, 'master', ['master'])
assert len(cloned.get_commits()) == 1
self.check_hook_vars('postclone', ["GBP_GIT_DIR"])
+
+ def test_clone_environ(self):
+ """Test that environment variables influence git configuration"""
+ def _dsc(version):
+ return os.path.join(DEB_TEST_DATA_DIR,
+ 'dsc-native',
+ 'git-buildpackage_%s.dsc' % version)
+
+ # Build up somethng we can clone from
+ dsc = _dsc('0.4.14')
+ os.environ['DEBFULLNAME'] = 'testing tester'
+ os.environ['DEBEMAIL'] = 'gbp-tester@debian.invalid'
+ assert import_dsc(['arg0', dsc]) == 0
+ repo = ComponentTestGitRepository('git-buildpackage')
+ self._check_repo_state(repo, 'master', ['master'])
+ assert len(repo.get_commits()) == 1
+
+ got = repo.get_config("user.email")
+ want = os.environ['DEBEMAIL']
+ ok_(got == want, "unexpected git config user.email: got %s, want %s" % (got, want))
+
+ got = repo.get_config("user.name")
+ want = os.environ['DEBFULLNAME']
+ ok_(got == want, "unexpected git config user.name: got %s, want %s" % (got, want))
diff --git a/tests/doctests/test_GitRepository.py b/tests/doctests/test_GitRepository.py
index bd7c005a..a5d6c534 100644
--- a/tests/doctests/test_GitRepository.py
+++ b/tests/doctests/test_GitRepository.py
@@ -996,4 +996,17 @@ def test_cmd_has_feature():
True
"""
+
+def test_set_user_name_and_email():
+ r"""
+ Methods tested:
+ - L{gbp.git.GitRepository.set_user_name}
+ - L{gbp.git.GitRepository.set_user_email}
+
+ >>> import gbp.git
+ >>> repo = gbp.git.GitRepository(dirs['repo'])
+ >>> repo.set_user_name("Michael Stapelberg")
+ >>> repo.set_user_email("stapelberg@test.invalid")
+ """
+
# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: