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

a freshly initialized repository without commits fails here #292

Open
lenntt opened this issue Apr 30, 2024 · 2 comments
Open

a freshly initialized repository without commits fails here #292

lenntt opened this issue Apr 30, 2024 · 2 comments

Comments

@lenntt
Copy link

lenntt commented Apr 30, 2024

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/[email protected]/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/[email protected]/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.

@ishepard
Copy link
Owner

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 😄

@lenntt
Copy link
Author

lenntt commented May 2, 2024

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?

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

No branches or pull requests

2 participants