Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle exception when analyzing an empty repository #300

Merged
merged 5 commits into from
Oct 4, 2024

Conversation

IP1102
Copy link
Contributor

@IP1102 IP1102 commented Oct 4, 2024

It might seem obvious to run this tool on a non-empty repository, but for few use cases like integrating this tool as part of an automated pipeline to analyze several repositories there might be few empty repositories. When ran on an empty repository, it fails to iter_commits and throws the following error:

git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
cmdline: git rev-list --reverse HEAD --
stderr: 'fatal: bad revision 'HEAD'

To fix this, I followed the same approach adapted in get_commits_modified_file method to handle empty modifications by checking GitCommandError exception (ref). I have added the test case and added it's corresponding repository in the .zip file.

Copy link

codecov bot commented Oct 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.26%. Comparing base (aed5f5b) to head (f4385e0).
Report is 6 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #300      +/-   ##
==========================================
+ Coverage   97.25%   97.26%   +0.01%     
==========================================
  Files          17       17              
  Lines        1091     1096       +5     
==========================================
+ Hits         1061     1066       +5     
  Misses         30       30              
Files with missing lines Coverage Δ
pydriller/git.py 97.12% <100.00%> (+0.10%) ⬆️

@ishepard
Copy link
Owner

ishepard commented Oct 4, 2024

LGTM! Thanks for the PR!

@ishepard ishepard merged commit 7a71655 into ishepard:master Oct 4, 2024
4 of 19 checks passed
Repository owner deleted a comment from testpulseio bot Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants