Sorry, forgot to add that file :). Here we go.

On Mon, Dec 19, 2016 at 8:07 AM, Guido Günther <a...@sigxcpu.org> wrote:

> Hi Michael,
> On Sun, Dec 18, 2016 at 10:30:46PM +0100, Michael Stapelberg wrote:
> > Thanks for the review! All done:
>
> Thanks for working on this! We're almost there:
>
>
> $ nosetests -x
> ..................................................E
> ======================================================================
> ERROR: Failure: ImportError (cannot import name repo_setup)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>   File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 418, in
> loadTestsFromName
>     addr.filename, addr.module)
>   File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 47, in
> importFromPath
>     return self.importFromDir(dir_path, fqname)
>   File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 94, in
> importFromDir
>     mod = load_module(part_fqname, fh, filename, desc)
>   File 
> "/var/scratch/src/git-buildpackage/git-buildpackage/gbp/scripts/clone.py",
> line 29, in <module>
>     from gbp.scripts.common import repo_setup
> ImportError: cannot import name repo_setup
>
> It seems the definition of repo_setup itself is missing. Looks good
> otherwise.
> Cheers,
>  -- Guido
>



-- 
Best regards,
Michael
From aa65f2199930c1c0b5d21fb7370b09efde7934a8 Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <stapelb...@debian.org>
Date: Thu, 24 Nov 2016 12:17:50 +0100
Subject: [PATCH] gbp clone: configure user.email, user.name from
 DEBEMAIL/DEBFULLNAME

---
 gbp/config.py                        | 12 +++++++++++-
 gbp/git/repository.py                | 18 ++++++++++++++++++
 gbp/scripts/clone.py                 |  7 +++++++
 gbp/scripts/common/repo_setup.py     | 30 ++++++++++++++++++++++++++++++
 gbp/scripts/import_dsc.py            |  8 ++++++++
 gbp/scripts/import_srpm.py           |  8 ++++++++
 tests/component/deb/test_clone.py    | 24 ++++++++++++++++++++++++
 tests/doctests/test_GitRepository.py | 13 +++++++++++++
 8 files changed, 119 insertions(+), 1 deletion(-)
 create mode 100644 gbp/scripts/common/repo_setup.py

diff --git a/gbp/config.py b/gbp/config.py
index 149a1bb..18a3afc 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 2f1b71b..644fc7b 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 63b1468..0afa54c 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 0000000..4e52c45
--- /dev/null
+++ b/gbp/scripts/common/repo_setup.py
@@ -0,0 +1,30 @@
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2006-2011, 2016 Guido Guenther <a...@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 6113032..300c236 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 f98a659..e483191 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 0c3ba2c..61bf46e 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 bd7c005..a5d6c53 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\:·:
-- 
2.10.2

Reply via email to