summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2014-11-17 11:00:02 +0100
committerSebastian Thiel <byronimo@gmail.com>2014-11-17 11:00:02 +0100
commit9eb902eee03806db5868fc84afb23aa28802e841 (patch)
tree9e557ba5b510b2d68046481e8d185321dd88860b
parent322db077a693a513e79577a0adf94c97fc2be347 (diff)
parentba67e4ff74e97c4de5d980715729a773a48cd6bc (diff)
downloadgitpython-9eb902eee03806db5868fc84afb23aa28802e841.tar.gz
Merge branch 'firm1-0.3' into 0.3
This includes a few fixes to not break backwards compatiblity
-rw-r--r--git/index/base.py4
-rw-r--r--git/objects/commit.py12
-rw-r--r--git/refs/log.py8
-rw-r--r--git/refs/symbolic.py12
4 files changed, 24 insertions, 12 deletions
diff --git a/git/index/base.py b/git/index/base.py
index f11f4492..47c32dc6 100644
--- a/git/index/base.py
+++ b/git/index/base.py
@@ -867,7 +867,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
return out
- def commit(self, message, parent_commits=None, head=True):
+ def commit(self, message, parent_commits=None, head=True, author=None, committer=None):
"""Commit the current default index file, creating a commit object.
For more information on the arguments, see tree.commit.
@@ -878,7 +878,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
: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):
diff --git a/git/objects/commit.py b/git/objects/commit.py
index d778f2d7..453afe66 100644
--- a/git/objects/commit.py
+++ b/git/objects/commit.py
@@ -258,7 +258,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
finalize_process(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
@@ -276,6 +276,10 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
If True, the HEAD will be advanced to the new commit automatically.
Else the HEAD will remain pointing on the previous commit. This could
lead to undesired results when diffing files.
+ :param author: The name of the author, optional. If unset, the repository
+ configuration is used to obtain this value.
+ :param committer: The name of the committer, optional. If unset, the
+ repository configuration is used to obtain this value.
:return: Commit object representing the new commit
@@ -283,7 +287,6 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
Additional information about the committer and Author are taken from the
environment or from the git configuration, see git-commit-tree for
more information"""
- parents = parent_commits
if parent_commits is None:
try:
parent_commits = [repo.head.commit]
@@ -303,8 +306,8 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
cr = repo.config_reader()
env = os.environ
- committer = Actor.committer(cr)
- author = Actor.author(cr)
+ committer = committer or Actor.committer(cr)
+ author = author or Actor.author(cr)
# PARSE THE DATES
unix_time = int(time())
@@ -357,7 +360,6 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
except ValueError:
# head is not yet set to the ref our HEAD points to
# Happens on first commit
- import git.refs
master = git.refs.Head.create(repo, repo.head.ref, new_commit, logmsg="commit (initial): %s" % message)
repo.head.set_reference(master, logmsg='commit: Switching to %s' % master)
# END handle empty repositories
diff --git a/git/refs/log.py b/git/refs/log.py
index 7249aec5..3bc42801 100644
--- a/git/refs/log.py
+++ b/git/refs/log.py
@@ -235,7 +235,8 @@ class RefLog(list, Serializable):
"""Append a new log entry to the revlog at filepath.
:param config_reader: configuration reader of the repository - used to obtain
- user information. May be None
+ user information. May also be an Actor instance identifying the committer directly.
+ May also be None
:param filepath: full path to the log file
:param oldbinsha: binary sha of the previous commit
:param newbinsha: binary sha of the current commit
@@ -249,8 +250,9 @@ class RefLog(list, Serializable):
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))
-
+ committer = isinstance(config_reader, Actor) and config_reader or Actor.committer(config_reader)
+ entry = RefLogEntry((bin_to_hex(oldbinsha), bin_to_hex(newbinsha), committer, (int(time.time()), time.altzone), message))
+
lf = LockFile(filepath)
lf._obtain_lock_or_raise()
diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py
index 9f9eb9f5..9a95b7f0 100644
--- a/git/refs/symbolic.py
+++ b/git/refs/symbolic.py
@@ -355,8 +355,16 @@ class SymbolicReference(object):
: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,
- (newbinsha is None and self.commit.binsha) or newbinsha,
+ # NOTE: we use the committer of the currently active commit - this should be
+ # correct to allow overriding the committer on a per-commit level.
+ # See https://github.com/gitpython-developers/GitPython/pull/146
+ try:
+ committer_or_reader = self.commit.committer
+ except ValueError:
+ committer_or_reader = self.repo.config_reader()
+ # end handle newly cloned repositories
+ return RefLog.append_entry(committer_or_reader, RefLog.path(self), oldbinsha,
+ (newbinsha is None and self.commit.binsha) or newbinsha,
message)
def log_entry(self, index):