Skip to content

Commit

Permalink
changing path from absolute to relative, and removing useless code fr…
Browse files Browse the repository at this point in the history
…om get_commits_modified_file
  • Loading branch information
ishepard committed Jan 18, 2019
1 parent 2057c9a commit 1318c2e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
7 changes: 1 addition & 6 deletions pydriller/git_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,8 @@ def _useless_line(self, line: str):
line.startswith("'''") or line.startswith('"""') or line.startswith("*")

def get_commits_modified_file(self, filepath: str) -> List[str]:
all_commits = self.get_list_commits()
path = str(Path(filepath))

dict_commits = {}
for commit in all_commits:
dict_commits[commit.hash] = commit

path = str(Path(filepath).absolute())
commits = []
try:
commits = self.git.log("--follow", "--format=%H", path).split('\n')
Expand Down
4 changes: 2 additions & 2 deletions tests/test_git_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def test_get_commits_last_modified_lines_with_more_modification():
def test_get_commits_modified_file():
gr = GitRepository('test-repos/test1/')

commits = gr.get_commits_modified_file('test-repos/test1/file2.java')
commits = gr.get_commits_modified_file('file2.java')

assert len(commits) == 3
assert '09f6182cef737db02a085e1d018963c7a29bde5a' in commits
Expand All @@ -409,6 +409,6 @@ def test_get_commits_modified_file():
def test_get_commits_modified_file_missing_file():
gr = GitRepository('test-repos/test1/')

commits = gr.get_commits_modified_file('test-repos/test1/non-existing-file.java')
commits = gr.get_commits_modified_file('non-existing-file.java')

assert len(commits) == 0
4 changes: 2 additions & 2 deletions tests/test_repository_mining.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ def test_filepath():
dt = datetime(2018, 6, 6)
assert 4 == len(list(RepositoryMining(
path_to_repo='test-repos/test5',
filepath='test-repos/test5/A.java',
filepath='A.java',
to=dt).traverse_commits()))

def test_filepath_with_rename():
dt = datetime(2018, 6, 6)
commits = list(RepositoryMining(
path_to_repo='test-repos/test1',
filepath='test-repos/test1/file4.java',
filepath='file4.java',
to=dt).traverse_commits())
assert 2 == len(commits)

Expand Down

0 comments on commit 1318c2e

Please sign in to comment.