Python sh, set user.email to commit (Git)
Question: I'm working with [Waliki](https://github.com/mgaitan/waliki/), specifically
with waliki.git,

Waliki.git use sh to manage Git, so there, when execute a commit, user ever is
setted to `settings.WALIKI_COMMITTER_EMAIL`, looking for source (as next),
`user` at `.git/config` never is changed.

    
    
    class Git(object):
        __shared_state = {}     # it's a Borg
    
        def __init__(self):
            self.__dict__ = self.__shared_state
            from waliki.settings import WALIKI_DATA_DIR
            self.content_dir = WALIKI_DATA_DIR
            os.chdir(self.content_dir)
            if not os.path.isdir(os.path.join(self.content_dir, '.git')):
                git.init()
                git.config("user.email", settings.WALIKI_COMMITTER_EMAIL)
                git.config("user.name", settings.WALIKI_COMMITTER_NAME)    
            self.git = git
    
        def commit(self, page, message='', author=None, parent=None, extra_path=None):
            path = page.path
            paths_to_commit = [path]
            if extra_path:
                paths_to_commit.append(extra_path)
            kwargs = {}
            if isinstance(author, User) and author.is_authenticated():
                kwargs['author'] = u"%s <%s>" % (author.get_full_name() or author.username, author.email)
            elif isinstance(author, six.string_types):
                kwargs['author'] = author
    
            try:
                there_were_changes = parent and parent != self.last_version(page)
                status = git.status('--porcelain', path).stdout.decode('utf8')[:2]
                if parent and status != "UU":
                    git.stash()
                    git.checkout('--detach', parent)
                    try:
                        git.stash('pop')
                    except:
                        git.checkout('--theirs', path)
    
                if status == 'UU':
                    # See http://stackoverflow.com/a/8062976/811740
                    kwargs['i'] = True
    
                git.add(path)
                git_commit_cmd = git.commit.bake(allow_empty=True, allow_empty_message=True, m=message, **kwargs)
                git_commit_cmd('--', *paths_to_commit)
                last = self.last_version(page)
                if parent and status != "UU":
                    git.checkout('master')
                    git.merge(last)
            except ErrorReturnCode as e:
                # TODO: make this more robust!
                error = e.stdout.decode('utf8')
                if 'CONFLICT' in error:
                    # For '-i' attribute see http://stackoverflow.com/q/5827944/811740
                    git_commit_cmd = git.commit.bake(allow_empty=True, allow_empty_message=True, m=_('Merged with conflict'), i=True, **kwargs)
                    git_commit_cmd('--', *paths_to_commit)
                    raise Page.EditionConflict(_('Automatic merge failed. Please, fix the conflict and save the page.'))
                else:
                    raise
            return there_were_changes
    

I add some code, so:

class Git(object): __shared_state = {} # it's a Borg

    
    
        def __init__(self, author):
            self.__dict__ = self.__shared_state
            from waliki.settings import WALIKI_DATA_DIR
            self.content_dir = WALIKI_DATA_DIR
            os.chdir(self.content_dir)
            if not os.path.isdir(os.path.join(self.content_dir, '.git')):
                git.init()
                git.config("user.email", settings.WALIKI_COMMITTER_EMAIL)
                git.config("user.name", settings.WALIKI_COMMITTER_NAME)    
            else:
                git.config("user.email", author)
                git.config("user.name", author)
            self.git = git
    

but Got:

    
    
      RAN: '/usr/bin/git --no-pager commit -m Page created --allow-empty --allow-empty-message --author=rizotastack@gmail.com -- content.md'
    
      STDOUT:
    
    
      STDERR:
    fatal: No existing author found with 'rizotastack@gmail.com'
    

How I can do Git set rightly current user to commit?


Answer: This is the part of interest:

    
    
        if isinstance(author, User) and author.is_authenticated():
            kwargs['author'] = u"%s <%s>" % (author.get_full_name() or author.username, author.email)
        elif isinstance(author, six.string_types):
            kwargs['author'] = author
    

You need to specify the author with the format `Full Name
<email@example.com>`.

[From the docs](https://www.kernel.org/pub/software/scm/git/docs/git-
commit.html):

    
    
    --author=<author>
    
    Override the commit author. Specify an explicit author using the standard
    "A U Thor <author@example.com>" format. Otherwise <author> is assumed to be a
    pattern and is used to search for an existing commit by that author (i.e.
    rev-list --all -i --author=<author>); the commit author is then copied from the
    first such commit found.
    

