Skip to content

add author and committer in params of the commit function #146

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

Merged
merged 5 commits into from
Nov 17, 2014
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions git/index/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ def move(self, items, skip_errors=False, **kwargs):

return out

def commit(self, message, parent_commits=None, head=True):
def commit(self, message, parent_commits=None, head=True, author=None, committer=None):
Copy link
Member

Choose a reason for hiding this comment

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

The added parameters are not yet documented in Commit.create_from_tree.

"""Commit the current default index file, creating a commit object.

For more information on the arguments, see tree.commit.
Expand All @@ -884,7 +884,7 @@ def commit(self, message, parent_commits=None, head=True):
:return:
Commit object representing the new commit"""
tree = self.write_tree()
return Commit.create_from_tree(self.repo, tree, message, parent_commits, head)
return Commit.create_from_tree(self.repo, tree, message, parent_commits, head, author=author, committer=committer)

@classmethod
def _flush_stdin_and_wait(cls, proc, ignore_stdout = False):
Expand Down
11 changes: 8 additions & 3 deletions git/objects/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def _iter_from_process_or_stream(cls, repo, proc_or_stream):


@classmethod
def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False):
def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False, author=None, committer=None):
"""Commit the given tree, creating a commit object.

:param repo: Repo object the commit should be part of
Expand Down Expand Up @@ -299,8 +299,13 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False):
cr = repo.config_reader()
env = os.environ

committer = Actor.committer(cr)
author = Actor.author(cr)
if author is None and committer is None:
Copy link
Member

Choose a reason for hiding this comment

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

This input check should be simplified.

committer = Actor.committer(cr)
author = Actor.author(cr)
elif author is None:
author = Actor.author(cr)
elif committer is None:
committer = Actor.committer(cr)

# PARSE THE DATES
unix_time = int(time())
Expand Down
2 changes: 1 addition & 1 deletion git/refs/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def append_entry(cls, config_reader, filepath, oldbinsha, newbinsha, message):
raise ValueError("Shas need to be given in binary format")
#END handle sha type
assure_directory_exists(filepath, is_file=True)
entry = RefLogEntry((bin_to_hex(oldbinsha), bin_to_hex(newbinsha), Actor.committer(config_reader), (int(time.time()), time.altzone), message))
entry = RefLogEntry((bin_to_hex(oldbinsha), bin_to_hex(newbinsha), config_reader, (int(time.time()), time.altzone), message))
Copy link
Member

Choose a reason for hiding this comment

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

config_reader is now actually just the Actor instance of the committer. It would be very confusing to leave that name.
Also it breaks the API due to the type change. Code must be added to check the type of the input and act accordingly.


lf = LockFile(filepath)
lf._obtain_lock_or_raise()
Expand Down
2 changes: 1 addition & 1 deletion git/refs/symbolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def log_append(self, oldbinsha, message, newbinsha=None):
:param newbinsha: The sha the ref points to now. If None, our current commit sha
will be used
:return: added RefLogEntry instance"""
return RefLog.append_entry(self.repo.config_reader(), RefLog.path(self), oldbinsha,
return RefLog.append_entry(self.commit.committer, RefLog.path(self), oldbinsha,
Copy link
Member

Choose a reason for hiding this comment

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

See above

(newbinsha is None and self.commit.binsha) or newbinsha,
message)

Expand Down