Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_modification_status():
gr = GitRepository('test-repos/git-1/')
commit = gr.get_commit('866e997a9e44cb4ddd9e00efe49361420aff2559')
assert commit.modifications[0].change_type == ModificationType.ADD
assert commit.modifications[0].old_path is None
commit = gr.get_commit('57dbd017d1a744b949e7ca0b1c1a3b3dd4c1cbc1')
assert commit.modifications[0].change_type == ModificationType.MODIFY
assert commit.modifications[0].new_path == commit.modifications[0].old_path
commit = gr.get_commit('ffccf1e7497eb8136fd66ed5e42bef29677c4b71')
assert commit.modifications[0].change_type == ModificationType.DELETE
assert commit.modifications[0].new_path is None
def _calculate_last_commits(self, commit: Commit,
modifications: List[Modification],
hashes_to_ignore_path: str = None) \
-> Dict[str, Set[str]]:
commits = {}
for mod in modifications:
path = mod.new_path
if mod.change_type == ModificationType.RENAME or \
mod.change_type == ModificationType.DELETE:
path = mod.old_path
deleted_lines = self.parse_diff(mod.diff)['deleted']
try:
blame = self._get_blame(commit.hash, path,
hashes_to_ignore_path)
for num_line, line in deleted_lines:
if not self._useless_line(line.strip()):
buggy_commit = blame[num_line - 1].split(' ')[
0].replace('^', '')
# Skip unblamable lines.
if buggy_commit.startswith("*"):
continue
if mod.change_type == ModificationType.RENAME:
path = mod.new_path
def _from_change_to_modification_type(diff: Diff):
if diff.new_file:
return ModificationType.ADD
if diff.deleted_file:
return ModificationType.DELETE
if diff.renamed_file:
return ModificationType.RENAME
if diff.a_blob and diff.b_blob and diff.a_blob != diff.b_blob:
return ModificationType.MODIFY
return ModificationType.UNKNOWN