-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ran nbdev_prepare to generate kyma_poc/scm.py
- Loading branch information
1 parent
140ef49
commit cbe5c9c
Showing
3 changed files
with
41 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/02_scm_git_diff.ipynb. | ||
|
||
# %% auto 0 | ||
__all__ = ['GitDiff'] | ||
|
||
# %% ../nbs/02_scm_git_diff.ipynb 12 | ||
from git import BadName, Repo | ||
|
||
class GitDiff: | ||
def __init__(self, repo_path): | ||
self.repo_path = repo_path | ||
self.repo = Repo(self.repo_path) | ||
|
||
def get_patch(self, start_commit_id, end_commit_id="HEAD"): | ||
# If either commit_id is not valid, this will raise a BadName exception | ||
start_commit = self.repo.commit(start_commit_id) | ||
end_commit = self.repo.commit(end_commit_id) | ||
return start_commit.diff(end_commit_id, create_patch=True) | ||
|
||
def get_patch_for_file(self, start_commit_id, end_commit_id, file_path): | ||
diff_indexes = self.get_patch(start_commit_id, end_commit_id) | ||
# We need to search through the indexes to find the diff for our file_path | ||
patch = None | ||
for diff in diff_indexes: | ||
print(f"'{file_path}' '{diff.a_path}' '{diff.b_path}' ") | ||
if diff.a_path == file_path or diff.b_path == file_path: | ||
print("Found match") | ||
patch = diff.diff | ||
break | ||
return patch | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters