diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2013-03-01 18:04:40 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2013-03-01 18:04:40 +0000 |
commit | c11cdb16e2d10e29c96873db5796e911979012d8 (patch) | |
tree | ef14e3fab90c6719b28a98d37f9329e93e606b2f | |
parent | 1b16bb71e792228302cd7bb9dabef9220c7ca5b1 (diff) | |
parent | d884a94133ae4b78138cb0a1d9f1ccfcc0061b1e (diff) | |
download | morph-c11cdb16e2d10e29c96873db5796e911979012d8.tar.gz |
Merge branch 'baserock/richardmaw/branch-and-merge-git-config-warnings-v2' of git://git.baserock.org/baserock/baserock/morphbaserock/genivi/baseline/releases/F-0.1
Reviewed-by: Sam Thursfield
Reviewed-by: Lars Wirzenius
-rw-r--r-- | morphlib/git.py | 17 | ||||
-rw-r--r-- | morphlib/plugins/branch_and_merge_plugin.py | 25 |
2 files changed, 40 insertions, 2 deletions
diff --git a/morphlib/git.py b/morphlib/git.py index c63c21b2..fffc05d0 100644 --- a/morphlib/git.py +++ b/morphlib/git.py @@ -183,6 +183,23 @@ def get_user_email(runcmd): ' git config --global user.email "me@example.com"\n') +def check_config_set(runcmd, keys=("user.name", "user.email"), cwd='.'): + ''' Check whether the given keys have values in git config. ''' + missing = [] + for key in keys: + try: + runcmd(['git', 'config', key], cwd=cwd) + except cliapp.AppException: + missing.append(key) + if missing: + if len(missing) == 1: + emesg = 'Git configuration for %s has not been set' % missing[0] + else: + emesg = ('Git configuration for keys %s and %s have not been set' + % (', '.join(missing[:-1]), missing[-1])) + raise cliapp.AppException(emesg) + + def set_remote(runcmd, gitdir, name, url): '''Set remote with name 'name' use a given url at gitdir''' return runcmd(['git', 'remote', 'set-url', name, url], cwd=gitdir) diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py index cbc41acf..cc221e85 100644 --- a/morphlib/plugins/branch_and_merge_plugin.py +++ b/morphlib/plugins/branch_and_merge_plugin.py @@ -16,6 +16,7 @@ import cliapp import copy +import functools import glob import logging import os @@ -28,6 +29,22 @@ import uuid import morphlib + +def requires_git_config(*keys): + def decorator(func): + @functools.wraps(func) + def check_config(self, *args, **kwargs): + try: + morphlib.git.check_config_set(self.app.runcmd, keys) + except cliapp.AppException, e: + self.app.status(msg="WARNING: %(message)s", + message=e.msg, error=True) + return func(self, *args, **kwargs) + return check_config + + return decorator + + class BranchAndMergePlugin(cliapp.Plugin): def __init__(self): @@ -571,6 +588,7 @@ class BranchAndMergePlugin(cliapp.Plugin): self.remove_branch_dir_safe(workspace, branch_name) raise + @requires_git_config('user.name', 'user.email') def branch(self, args): '''Create a new system branch.''' @@ -591,6 +609,7 @@ class BranchAndMergePlugin(cliapp.Plugin): workspace = self.deduce_workspace() self._create_branch(workspace, new_branch, repo, commit) + @requires_git_config('user.name', 'user.email') def checkout(self, args): '''Check out an existing system branch.''' @@ -662,6 +681,7 @@ class BranchAndMergePlugin(cliapp.Plugin): branch_dir, spec['repo'], branch, parent_ref=spec['ref']) return repo_dir + @requires_git_config('user.name', 'user.email') def edit(self, args): '''Edit a component in a system branch.''' @@ -982,6 +1002,7 @@ class BranchAndMergePlugin(cliapp.Plugin): self.print_changelog('The following changes were made but have not ' 'been committed') + @requires_git_config('user.name', 'user.email') def tag(self, args): if len(args) < 1: raise cliapp.AppException('morph tag expects a tag name') @@ -1481,6 +1502,7 @@ class BranchAndMergePlugin(cliapp.Plugin): self.reset_work_tree_safe(repo_dir) raise + @requires_git_config('user.name', 'user.email') def build(self, args): '''Build a system from the current system branch''' @@ -1629,8 +1651,7 @@ class BranchAndMergePlugin(cliapp.Plugin): # Define the committer. committer_name = 'Morph (on behalf of %s)' % \ (morphlib.git.get_user_name(self.app.runcmd)) - committer_email = '%s@%s' % \ - (os.environ.get('LOGNAME'), socket.gethostname()) + committer_email = morphlib.git.get_user_email(self.app.runcmd) for repo, info in build_repos.iteritems(): repo_dir = info['dirname'] |