def get_changed_files(master_commit: Commit, patch_commit: Commit): # TODO # git change type support: # A: addition of a file # C: copy of a file into a new one # D: deletion of a file # done M: modification of the contents or mode of a file # R: renaming of a file # T: change in the type of the file # U: file is unmerged (you must complete the merge before it can be committed) # X: "unknown" change type (most probably a bug, please report it) changed_files = {} renamed_files = {} for x in master_commit.diff(patch_commit): # Change type of x is not 'new' if x.a_blob != None and x.a_blob.path not in changed_files.keys(): if x.change_type == "R": # file have been renamed, the dest file is include in the changed files # so we need to delete this file from dest repo # print(f'a remove(rename) :{x.a_blob.path}, type: {x.change_type}') renamed_files[x.a_blob.path] = {"type": x.change_type} else: # print(f'a change :{x.a_blob.path}, type: {x.change_type}') changed_files[x.a_blob.path] = {"type": x.change_type} # Change type of x is not 'delete' if x.b_blob is not None and x.b_blob.path not in changed_files.keys(): # print(f'b change :{x.b_blob.path}, type: {x.change_type}') changed_files[x.b_blob.path] = {"type": x.change_type} return changed_files, renamed_files
def createCommit(repo, shaBin, shaStr): comm = Commit(repo, shaBin) myCommit = MyCommit(shaStr) myCommit.author = MyAuthor(comm.author.name, comm.author.email) myCommit.committer = MyCommitter(comm.committer.name, comm.committer.email) myCommit.msg = comm.message myCommit.tree = comm.tree.hexsha if comm.parents: myCommit.parents = [pcommit.hexsha for pcommit in comm.parents] return myCommit
def __init__(self, old: Commit, new: Commit): """[summary] Args: old (Commit): the older/earlier commit that defines the diff new (Commit): the newer/later commit that defines the diff """ if old.repo != new.repo: raise ValueError( "you can only diff two commits from the same repo!") self._repo: Repo = old.repo self._old = old self._new = new self._diffs: DiffIndex = old.diff(new)
def commits(rev=None): if rev: return Commit.iter_items(local_repo(), rev) else: return _all_commits_generator()
from git import Repo from git.refs.tag import TagReference from git.objects.commit import Commit repo = Repo(path=r"c:\Work\RedCat\riverbeas") tree = repo.heads.master.commit.tree fifty_first_commits = list(repo.iter_commits('master', max_count=50)) print(fifty_first_commits) first_commit = fifty_first_commits[0] with repo.git.custom_environment(GIT_SSH='c:/Programs/babun/.babun/cygwin/bin/ssh.exe'): repo.remotes.origin.fetch() tag = repo.tags[0] commit = Commit(repo)