Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/gitrepository #52

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions gbp/git/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def __init__(self, path, toplevel=True):
def __build_env(extra_env):
"""Prepare environment for subprocess calls"""
env = None
if extra_env is not None:
if extra_env:
env = os.environ.copy()
env.update(extra_env)
return env
Expand Down Expand Up @@ -1450,11 +1450,14 @@ def rename_file(self, old, new):

#{ Comitting

def _commit(self, msg, args=[], author_info=None):
extra_env = author_info.get_author_env() if author_info else None
def _commit(self, msg, args=[], author_info=None, committer_info=None):
extra_env = author_info.get_author_env() if author_info else {}
if committer_info:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we change from None to {} here we need to fixup _build_env to return None for extra_env being {} or None

extra_env.update(committer_info.get_committer_env())
self._git_command("commit", ['-q', '-m', msg] + args, extra_env=extra_env)

def commit_staged(self, msg, author_info=None, edit=False):
def commit_staged(self, msg, author_info=None, edit=False,
committer_info=None):
"""
Commit currently staged files to the repository

Expand All @@ -1464,24 +1467,30 @@ def commit_staged(self, msg, author_info=None, edit=False):
@type author_info: L{GitModifier}
@param edit: whether to spawn an editor to edit the commit info
@type edit: C{bool}
@param committer_info: committer information
@type committer_info: L{GitModifier}
"""
args = GitArgs()
args.add_true(edit, '--edit')
self._commit(msg=msg, args=args.args, author_info=author_info)
self._commit(msg=msg, args=args.args, author_info=author_info,
committer_info=committer_info)

def commit_all(self, msg, author_info=None, edit=False):
def commit_all(self, msg, author_info=None, edit=False, committer_info=None):
"""
Commit all changes to the repository
@param msg: commit message
@type msg: C{str}
@param author_info: authorship information
@type author_info: L{GitModifier}
@param committer_info: committer information
@type committer_info: L{GitModifier}
"""
args = GitArgs('-a')
args.add_true(edit, '--edit')
self._commit(msg=msg, args=args.args, author_info=author_info)
self._commit(msg=msg, args=args.args, author_info=author_info,
committer_info=committer_info)

def commit_files(self, files, msg, author_info=None):
def commit_files(self, files, msg, author_info=None, committer_info=None):
"""
Commit the given files to the repository

Expand All @@ -1491,10 +1500,13 @@ def commit_files(self, files, msg, author_info=None):
@type msg: C{str}
@param author_info: authorship information
@type author_info: L{GitModifier}
@param committer_info: committer information
@type committer_info: L{GitModifier}
"""
if isinstance(files, str):
files = [files]
self._commit(msg=msg, args=files, author_info=author_info)
self._commit(msg=msg, args=files, author_info=author_info,
committer_info=committer_info)

def commit_dir(self, unpack_dir, msg, branch, other_parents=None,
author={}, committer={}, create_missing_branch=False):
Expand Down