So I am using GitPython in a script to get the start branch of a commit. It works for some, but for others I eventually get errors like these:
[10] => Failed to process commit: Cmd('git') failed due to: exit code(128)
[11] => cmdline: git branch -a --contains SHA --sort=committerdate
[12] => stderr: 'fatal: couldn't read .git/packed-refs: Stale file handle'
[13] => Failed to process commit: Cmd('git') failed due to: exit code(128)
[14] => cmdline: git diff-tree SHA SHA -r --abbrev=40 --full-index -M --raw -z --no-color
This is the line I use and it generates the error:
repo = git.Repo(self.repo_path)
branch = repo.git.branch('-a', '--contains', commit.hexsha, '--sort=committerdate').split('\n')[0].split("remotes/origin/")[-1].split('* ')[-1] if repo.git.branch('-a', '--contains', commit.hexsha, '--sort=committerdate').split('\n')[0].split("remotes/origin/")[-1].split('* ')[-1] else ''
Any ideas what I could do in this case, what generates the error?
Some more info:
- it does not do this for every repository, it just does it randomly (I think?)
- if I go into the folder and run the command manually it works without error