pre-commit: fatal: reference is not a tree with older git versions

On CentOS-7 with all updates included, current git version is git version 1.8.3.1 which reproduces this pre-commit bug:

[INFO] Initializing environment for https://github.com/ansible/ansible-lint.git.
An unexpected error has occurred: CalledProcessError: Command: ('/usr/bin/git', 'checkout', 'ad721b6cde91a65e28d1f4fa4052bb721b17ae11')
Return code: 128
Errors:
    fatal: reference is not a tree: ad721b6cde91a65e28d1f4fa4052bb721b17ae11

Hook config:

---
repos:
  - repo: https://github.com/ansible/ansible-lint.git
    rev: ad721b6cde91a65e28d1f4fa4052bb721b17ae11
    hooks:
      - id: ansible-lint

As one of my colleagues described this happens due to pre-commit internals as git itself is perfectly able to clone the repo and get this commit.

Background

[11:39:17] <jpena> zbr: ok, I got the reason for the error, and it’s in pre_commit [11:40:06] <jpena> The sequence of commands it runs is: https://softwarefactory-project.io/paste/show/1648/ [11:40:27] <jpena> since you’re specifying a commit and not a tag or branch, it fails because it didn’t do a full clone [11:40:35] <jpena> I have reproduced it locally [11:41:35] <jpena> it starts in https://github.com/pre-commit/pre-commit/blob/master/pre_commit/store.py#L157-L172, which then calls https://github.com/pre-commit/pre-commit/blob/master/pre_commit/git.py#L152-L158, and finally tries the checkout at https://github.com/pre-commit/pre-commit/blob/master/pre_commit/store.py#L139-L144 [11:49:40] <zbr> jpena: interesting because I used commit in the past and i did not encounter the bug [11:50:19] <zbr> also this does not explain why it works locally for me, i rememeber that I cleaned the cache directory [11:50:39] <zbr> behavior seems to to vary, maybe depends on git version? [11:51:30] <zbr> jpena: what git version do you have where you reproduced it? [11:58:27] <jpena> zbr: 1.8.3.1 [11:58:31] <jpena> let me try it in fedora [11:59:05] <zbr> at least we could raise a valid bug once we narrow it down [11:59:30] <jpena> zbr: in fedora (git version 2.21.0) it does not fail

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (10 by maintainers)

Commits related to this issue

Most upvoted comments

🤷‍♂️ you’re not really forced to do anything 😉