Skip to content

Commit 7379091

Browse files
committed
Merge branch 'commit_by_actor' of https://github.com/firm1/GitPython into firm1-commit_by_actor
2 parents 45eb728 + b6ed8d4 commit 7379091

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

‎doc/source/tutorial.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,10 @@ Access objects and add/remove entries. Commit the changes::
297297
# Access the entries directly
298298
index.add(['my_new_file']) # add a new file to the index
299299
index.remove(['dir/existing_file'])
300-
new_commit = index.commit("my commit message")
300+
new_commit = index.commit("my commit message") # commit by commit message first
301+
my_author = Actor("An author", "author@example.com")
302+
my_committer = Actor("A committer", "committer@example.com")
303+
next_commit = index.commit("my commit message", author=my_author, commiter=my_committer) # commit by commit message and author and committer
301304
302305
Create new indices from other trees or as result of a merge. Write that result to a new index file::
303306

‎git/objects/commit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False,
358358
# as well ...
359359
import git.refs
360360
try:
361-
repo.head.set_commit(new_commit, logmsg="commit: %s" % message)
361+
repo.head.set_commit(new_commit, logmsg=message)
362362
except ValueError:
363363
# head is not yet set to the ref our HEAD points to
364364
# Happens on first commit

‎git/refs/log.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,20 @@
3232
class RefLogEntry(tuple):
3333

3434
"""Named tuple allowing easy access to the revlog data fields"""
35-
_fmt = "%s %s %s <%s> %i %s\t%s\n"
3635
_re_hexsha_only = re.compile('^[0-9A-Fa-f]{40}$')
3736
__slots__ = tuple()
3837

3938
def __repr__(self):
4039
"""Representation of ourselves in git reflog format"""
4140
act = self.actor
4241
time = self.time
43-
return self._fmt % (self.oldhexsha, self.newhexsha, act.name, act.email,
44-
time[0], altz_to_utctz_str(time[1]), self.message)
42+
return u"{0} {1} {2} <{3}> {4!s} {5}\t{6}\n".format(self.oldhexsha,
43+
self.newhexsha,
44+
act.name,
45+
act.email,
46+
time[0],
47+
altz_to_utctz_str(time[1]),
48+
self.message).encode("utf-8")
4549

4650
@property
4751
def oldhexsha(self):
@@ -267,7 +271,6 @@ def append_entry(cls, config_reader, filepath, oldbinsha, newbinsha, message):
267271

268272
lf = LockFile(filepath)
269273
lf._obtain_lock_or_raise()
270-
271274
fd = open(filepath, 'ab')
272275
try:
273276
fd.write(repr(entry).encode(defenc))

‎git/test/test_index.py

+17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
fixture,
1111
with_rw_repo
1212
)
13+
from git.util import Actor
1314
from git import (
1415
IndexFile,
1516
BlobFilter,
@@ -445,6 +446,22 @@ def mixed_iterator():
445446
assert len(new_commit.parents) == 1
446447
assert cur_head.commit == cur_commit
447448

449+
# commit with other actor
450+
cur_commit = cur_head.commit
451+
452+
my_author = Actor("An author", "author@example.com")
453+
my_committer = Actor("An committer", "committer@example.com")
454+
commit_actor = index.commit(commit_message, author=my_author, committer=my_committer)
455+
assert cur_commit != commit_actor
456+
assert commit_actor.author.name == "An author"
457+
assert commit_actor.author.email == "author@example.com"
458+
assert commit_actor.committer.name == "An committer"
459+
assert commit_actor.committer.email == "committer@example.com"
460+
assert commit_actor.message == commit_message
461+
assert commit_actor.parents[0] == cur_commit
462+
assert len(new_commit.parents) == 1
463+
assert cur_head.commit == cur_commit
464+
448465
# same index, no parents
449466
commit_message = "index without parents"
450467
commit_no_parents = index.commit(commit_message, parent_commits=list(), head=True)

0 commit comments

Comments
 (0)