diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2013-02-28 15:20:51 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2013-03-01 11:34:31 +0000 |
commit | d884a94133ae4b78138cb0a1d9f1ccfcc0061b1e (patch) | |
tree | f387ab06eb60c8f4a0eb5cf63c0ce2939fe33264 /morphlib/git.py | |
parent | c417076fb338ff544129a8211d588aa06fe20e46 (diff) | |
download | morph-d884a94133ae4b78138cb0a1d9f1ccfcc0061b1e.tar.gz |
B&M: Check git config before some subcommands
Some subcommands use git to create commits, in which case user config
needs to be set.
Others imply commits may be created, e.g. by cloning a repository, at
which point it is useful to have a reminder that the configuration needs
to be set.
Diffstat (limited to 'morphlib/git.py')
-rw-r--r-- | morphlib/git.py | 17 |
1 files changed, 17 insertions, 0 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) |