forked from importers/git-importer
Use proper user info in commits
This commit is contained in:
17
lib/git.py
17
lib/git.py
@@ -73,10 +73,8 @@ class Git:
|
||||
committer=None,
|
||||
committer_email=None,
|
||||
committer_time=None,
|
||||
allow_empty=False,
|
||||
):
|
||||
"""Add all the files and create a new commit in the current HEAD"""
|
||||
assert allow_empty or self.is_dirty()
|
||||
|
||||
if not committer:
|
||||
committer = self.committer if self.committer else self.user
|
||||
@@ -85,33 +83,20 @@ class Git:
|
||||
)
|
||||
committer_time = committer_time if committer_time else user_time
|
||||
|
||||
try:
|
||||
if self.is_dirty():
|
||||
self.repo.index.add_all()
|
||||
except pygit2.GitError as e:
|
||||
if not allow_empty:
|
||||
raise e
|
||||
|
||||
self.repo.index.write()
|
||||
author = pygit2.Signature(user, user_email, int(user_time.timestamp()))
|
||||
committer = pygit2.Signature(
|
||||
committer, committer_email, int(committer_time.timestamp())
|
||||
)
|
||||
if not parents:
|
||||
try:
|
||||
parents = [self.repo.head.target]
|
||||
except pygit2.GitError as e:
|
||||
parents = []
|
||||
if not allow_empty:
|
||||
raise e
|
||||
|
||||
tree = self.repo.index.write_tree()
|
||||
return self.repo.create_commit(
|
||||
"HEAD", author, committer, message, tree, parents
|
||||
)
|
||||
|
||||
def merge_abort(self):
|
||||
self.repo.state_cleanup()
|
||||
|
||||
def last_commit(self):
|
||||
try:
|
||||
return self.repo.head.target
|
||||
|
Reference in New Issue
Block a user