diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2015-01-07 14:44:02 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2015-01-07 14:44:02 +0100 |
commit | 73790919dbe038285a3612a191c377bc27ae6170 (patch) | |
tree | ced3af491a2b4354c15fb161102e9704d180d8d4 | |
parent | 45eb728554953fafcee2aab0f76ca65e005326b0 (diff) | |
parent | b6ed8d46c72366e111b9a97a7c238ef4af3bf4dc (diff) | |
download | gitpython-73790919dbe038285a3612a191c377bc27ae6170.tar.gz |
Merge branch 'commit_by_actor' of https://github.com/firm1/GitPython into firm1-commit_by_actor
-rw-r--r-- | doc/source/tutorial.rst | 5 | ||||
-rw-r--r-- | git/objects/commit.py | 2 | ||||
-rw-r--r-- | git/refs/log.py | 11 | ||||
-rw-r--r-- | git/test/test_index.py | 17 |
4 files changed, 29 insertions, 6 deletions
diff --git a/doc/source/tutorial.rst b/doc/source/tutorial.rst index d9b35fda..3f45b70d 100644 --- a/doc/source/tutorial.rst +++ b/doc/source/tutorial.rst @@ -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", "author@example.com") + my_committer = Actor("A committer", "committer@example.com") + 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:: diff --git a/git/objects/commit.py b/git/objects/commit.py index 8f93d1b9..f2ce91ca 100644 --- a/git/objects/commit.py +++ b/git/objects/commit.py @@ -358,7 +358,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): # 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 diff --git a/git/refs/log.py b/git/refs/log.py index 8ce98d30..ec19c1e8 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -32,7 +32,6 @@ __all__ = ["RefLog", "RefLogEntry"] 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() @@ -40,8 +39,13 @@ class RefLogEntry(tuple): """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): @@ -267,7 +271,6 @@ class RefLog(list, Serializable): lf = LockFile(filepath) lf._obtain_lock_or_raise() - fd = open(filepath, 'ab') try: fd.write(repr(entry).encode(defenc)) diff --git a/git/test/test_index.py b/git/test/test_index.py index f7504b32..f7d1cc6a 100644 --- a/git/test/test_index.py +++ b/git/test/test_index.py @@ -10,6 +10,7 @@ from git.test.lib import ( fixture, with_rw_repo ) +from git.util import Actor from git import ( IndexFile, BlobFilter, @@ -445,6 +446,22 @@ class TestIndex(TestBase): 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", "author@example.com") + my_committer = Actor("An committer", "committer@example.com") + 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 == "author@example.com" + assert commit_actor.committer.name == "An committer" + assert commit_actor.committer.email == "committer@example.com" + 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) |