0

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
3
  • 1
    "stale file handle" indicates that a network mount has failed. Disconnect the mount point and then re-mount it (the network equivalent of "have you tried turning it off and on again"...).
    – torek
    Commented Apr 23, 2021 at 8:38
  • What is strange is that if I go into the folder and run the command it does it without error... Only in the script it gives those errors...
    – Alexander
    Commented Apr 23, 2021 at 8:43
  • 1
    Weird. Is perhaps the GitPython script doing its own mount-unmount stuff?
    – torek
    Commented Apr 23, 2021 at 8:52

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.