You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@yeraydavidrodriguez@da2ce7 the change is already implemented but I would like to refactor the GitRepo class:
fromgitimportRepoclassGitRepo:
"""A wrapper for GitPython Repo"""def__init__(self, git_repo_dir, git_user, gnupghome="~/.gnupg"):
self.repo=Repo(git_repo_dir)
self.git_user=git_userself.gnupghome=gnupghomedefcommit(self, filepaths, commit_message: str, env: dict[str, str] = {}):
""" It creates a commit. Filepath is an object with four optional file lists: { "added": [], "deleted": [], "modified": [], "renamed": [], } """if"added"infilepaths:
self.repo.index.add(filepaths["added"])
if"deleted"infilepaths:
self.repo.index.remove(filepaths["deleted"])
if"renamed"infilepaths:
self.repo.index.add(filepaths["renamed"]["new"])
self.repo.index.remove(filepaths["renamed"]["old"])
# Write index. Needed for commit with signature:# https://github.com/gitpython-developers/GitPython/issues/580#issuecomment-282474086self.repo.index.write()
# Unsigned commitifself.git_user.signingkeyisNone:
withself.repo.git.custom_environment(**env):
returnself.repo.git.commit("-m", f"{commit_message}")
# Signed commitwithself.repo.git.custom_environment(GNUPGHOME=self.gnupghome, **env):
returnself.repo.git.commit(
"-S",
f"--gpg-sign={self.git_user.signingkey}",
"-m",
f"{commit_message}",
)
@yeraydavidrodriguez and I agreed some weeks ago that we should not couple this mod to the specific data structure used by the dvc diff command.
TODO:
Add method add
Add method delete
Add method rename
The commit method should only write the index and commit.
TODO:
Remove gnupghome from constructor. It should be one env variable in env commit argument.
Remove git_user from constructor. You can overwrite the Git committer info (email and name) with an env var as it's done by Git. It only makes sense if we always want to use the same committer info, but in that case, we should change the class name. In fact we should even separate the committer, author and signing key info because they can be set independently. We also have another issue to make signed commits optional.
@yeraydavidrodriguez @da2ce7 the change is already implemented but I would like to refactor the
GitRepo
class:@yeraydavidrodriguez and I agreed some weeks ago that we should not couple this mod to the specific data structure used by the
dvc diff
command.TODO:
add
delete
rename
The
commit
method should only write the index and commit.TODO:
gnupghome
from constructor. It should be one env variable inenv
commit argument.git_user
from constructor. You can overwrite the Git committer info (email and name) with an env var as it's done by Git. It only makes sense if we always want to use the same committer info, but in that case, we should change the class name. In fact we should even separate the committer, author and signing key info because they can be set independently. We also have another issue to make signed commits optional.Originally posted by @josecelano in #108 (comment)
The text was updated successfully, but these errors were encountered: