ishepard / pydriller

Python Framework to analyse Git repositories

Home Page:http://pydriller.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

a freshly initialized repository without commits fails here

lenntt opened this issue · comments

doing only a 'git init' and then try to traverse commits on that repo, will fail here:

for job in executor.map(self._iter_commits, git.get_list_commits(rev, **kwargs)):

relates to this:
https://stackoverflow.com/questions/15628720/fatal-bad-default-revision-head

Expected behavior:
either:

  • no commits to traverse, empty list
  • or, offer an api call to check if head points to a revision (is there one?)
   File "<myproj>/.venv/lib/python3.11/site-packages/pydriller/repository.py", line 236, in traverse_commits
      for job in executor.map(self._iter_commits, git.get_list_commits(rev, **kwargs)):
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/opt/homebrew/Cellar/python@3.11/3.11.7/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/_base.py", line 608, in map
      fs = [self.submit(fn, *args) for args in zip(*iterables)]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/opt/homebrew/Cellar/python@3.11/3.11.7/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/_base.py", line 608, in <listcomp>
      fs = [self.submit(fn, *args) for args in zip(*iterables)]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "<myproj>/.venv/lib/python3.11/site-packages/pydriller/git.py", line 121, in get_list_commits
      for commit in self.repo.iter_commits(rev=rev, **kwargs):
    File "<myproj>/.venv/lib/python3.11/site-packages/git/objects/commit.py", line 498, in _iter_from_process_or_stream
      finalize_process(proc_or_stream)
    File "<myproj>/.venv/lib/python3.11/site-packages/git/util.py", line 483, in finalize_process
      proc.wait(**kwargs)
    File "/<myproj>/.venv/lib/python3.11/site-packages/git/cmd.py", line 657, in wait
      raise GitCommandError(remove_password_if_present(self.args), status, errstr)
  git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
    cmdline: git rev-list --reverse --since=1999-04-30 17:27:25.723122+00:00 HEAD --
    stderr: 'fatal: bad revision 'HEAD'

I'm on git 2.39.3, MacOS.

This is Git internal behaviour, so I'd keep it the same. I just tested it in my terminal:

> git init
> git rev-list HEAD --
fatal: bad revision 'HEAD'

We could parse the exception and check for this exact string, but if Git returns this, I'd say let's leave it 😄

Fair, but didn't ask to do a git rev-list HEAD, I was asking to traverse_commits :)
Other than putting a large try around my code, do you know of a better way? is there a call to pre-check HEAD?