git-hooks.nix icon indicating copy to clipboard operation
git-hooks.nix copied to clipboard

`lorri` breaks if you also have `git` in your shell

Open michaelpj opened this issue 4 years ago • 2 comments

There's a guard to avoid doing the installation in a lorri shell by testing for the existence of git: https://github.com/cachix/pre-commit-hooks.nix/blob/e5ef518936a3f2f4575de064c74fb6383d2d330d/modules/pre-commit.nix#L304

This works fine... unless one happens to have also included git in one's shell. In which case it fails horribly.

I'm not sure what to do about this, but it's a slightly tricky failure to track down!

michaelpj avatar Oct 29 '20 18:10 michaelpj

Pasting the error I get for posterity:

building '/nix/store/kvxfsi5mhq77sf5sh1x1x252nsxd4q2y-lorri-keep-env-hack-ghc-shell-for-packages.drv'...                                                                                                                                                                                                                   
nix-pre-commit-hooks: updating /build repo                                                                                                                                                                                                                                                                                 
An error has occurred: FatalError: git failed. Is it installed, and are you in a Git repository directory?                                                                                                                                                                                                                 
Traceback (most recent call last):                                                                                                                                                                                                                                                                                         
  File "/nix/store/dqlx77d224grs7ch39jhgfplf68mg6sl-python3.8-pre-commit-2.7.1/lib/python3.8/site-packages/pre_commit/main.py", line 150, in _adjust_args_and_chdir                                                                                                                                                        
    toplevel = git.get_root()                                                                                                                                                                                                                                                                                              
  File "/nix/store/dqlx77d224grs7ch39jhgfplf68mg6sl-python3.8-pre-commit-2.7.1/lib/python3.8/site-packages/pre_commit/git.py", line 46, in get_root                                                                                                                                                                        
    return cmd_output('git', 'rev-parse', '--show-toplevel')[1].strip()                                                                                                                                                                                                                                                    
  File "/nix/store/dqlx77d224grs7ch39jhgfplf68mg6sl-python3.8-pre-commit-2.7.1/lib/python3.8/site-packages/pre_commit/util.py", line 163, in cmd_output                                                                                                                                                                    
    returncode, stdout_b, stderr_b = cmd_output_b(*cmd, **kwargs)                                                                                                                                                                                                                                                          
  File "/nix/store/dqlx77d224grs7ch39jhgfplf68mg6sl-python3.8-pre-commit-2.7.1/lib/python3.8/site-packages/pre_commit/util.py", line 157, in cmd_output_b                                                                                                                                                                  
    raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)                                                                                                                                                                                                                                                 
pre_commit.util.CalledProcessError: command: ('/nix/store/kp7wp760l4gryq9s36x481b2x4rfklcy-git-2.25.4/bin/git', 'rev-parse', '--show-toplevel')                                                                                                                                                                            
return code: 128                                                                                                                                                                                                                                                                                                           
expected return code: 0                                                                                                                                                                                                                                                                                                    
stdout: (none)
stderr:
    fatal: not a git repository (or any parent up to mount point /)
    Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set). 

michaelpj avatar Nov 02 '20 10:11 michaelpj

Looking at this again I think I slightly mis-diagnosed it: it's the Python pre_commit script that fails when it tries to call git (since it's not in a git repository). Ultimately it still gets triggered because we ran the installation script, though.

michaelpj avatar Nov 02 '20 10:11 michaelpj