Skip to content

Make a commit with another author #228

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
Jan 7, 2015
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
5 changes: 4 additions & 1 deletion doc/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ Access objects and add/remove entries. Commit the changes::
# Access the entries directly
index.add(['my_new_file']) # add a new file to the index
index.remove(['dir/existing_file'])
new_commit = index.commit("my commit message")
new_commit = index.commit("my commit message") # commit by commit message first
my_author = Actor("An author", "[email protected]")
my_committer = Actor("A committer", "[email protected]")
next_commit = index.commit("my commit message", author=my_author, commiter=my_committer) # commit by commit message and author and committer

Create new indices from other trees or as result of a merge. Write that result to a new index file::

Expand Down
2 changes: 1 addition & 1 deletion git/objects/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False,
# as well ...
import git.refs
try:
repo.head.set_commit(new_commit, logmsg="commit: %s" % message)
repo.head.set_commit(new_commit, logmsg=message)
except ValueError:
# head is not yet set to the ref our HEAD points to
# Happens on first commit
Expand Down
11 changes: 7 additions & 4 deletions git/refs/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,20 @@
class RefLogEntry(tuple):

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

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

@property
def oldhexsha(self):
Expand Down Expand Up @@ -267,7 +271,6 @@ def append_entry(cls, config_reader, filepath, oldbinsha, newbinsha, message):

lf = LockFile(filepath)
lf._obtain_lock_or_raise()

fd = open(filepath, 'ab')
try:
fd.write(repr(entry).encode(defenc))
Expand Down
17 changes: 17 additions & 0 deletions git/test/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
fixture,
with_rw_repo
)
from git.util import Actor
from git import (
IndexFile,
BlobFilter,
Expand Down Expand Up @@ -445,6 +446,22 @@ def mixed_iterator():
assert len(new_commit.parents) == 1
assert cur_head.commit == cur_commit

# commit with other actor
cur_commit = cur_head.commit

my_author = Actor("An author", "[email protected]")
my_committer = Actor("An committer", "[email protected]")
commit_actor = index.commit(commit_message, author=my_author, committer=my_committer)
assert cur_commit != commit_actor
assert commit_actor.author.name == "An author"
assert commit_actor.author.email == "[email protected]"
assert commit_actor.committer.name == "An committer"
assert commit_actor.committer.email == "[email protected]"
assert commit_actor.message == commit_message
assert commit_actor.parents[0] == cur_commit
assert len(new_commit.parents) == 1
assert cur_head.commit == cur_commit

# same index, no parents
commit_message = "index without parents"
commit_no_parents = index.commit(commit_message, parent_commits=list(), head=True)
Expand Down