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

[Regression] Worktree support #1777

Closed
s0undt3ch opened this issue Jan 27, 2021 · 7 comments · Fixed by #1778
Closed

[Regression] Worktree support #1777

s0undt3ch opened this issue Jan 27, 2021 · 7 comments · Fixed by #1778
Labels

Comments

@s0undt3ch
Copy link
Contributor

Latest release 2.9.3 broke git worktrees support

version information

pre-commit version: 2.9.3
sys.version:
    3.6.8 (default, Apr 15 2020, 09:32:35)
    [GCC 9.3.0]
sys.executable: /home/vampas/.dotfiles/.ext/pyenv/versions/3.6.8/envs/SaltPriv-3.6/bin/python3.6
os.name: posix
sys.platform: linux

error information

An error has occurred: FatalError: git toplevel unexpectedly empty! make sure you are not inside the `.git` directory of your repository.
Traceback (most recent call last):
  File "/home/vampas/.dotfiles/.ext/pyenv/versions/3.6.8/envs/SaltPriv-3.6/lib/python3.6/site-packages/pre_commit/error_handler.py", line 65, in error_handler
    yield
  File "/home/vampas/.dotfiles/.ext/pyenv/versions/3.6.8/envs/SaltPriv-3.6/lib/python3.6/site-packages/pre_commit/main.py", line 330, in main
    _adjust_args_and_chdir(args)
  File "/home/vampas/.dotfiles/.ext/pyenv/versions/3.6.8/envs/SaltPriv-3.6/lib/python3.6/site-packages/pre_commit/main.py", line 147, in _adjust_args_and_chdir
    toplevel = git.get_root()
  File "/home/vampas/.dotfiles/.ext/pyenv/versions/3.6.8/envs/SaltPriv-3.6/lib/python3.6/site-packages/pre_commit/git.py", line 66, in get_root
    'git toplevel unexpectedly empty! make sure you are not '
pre_commit.errors.FatalError: git toplevel unexpectedly empty! make sure you are not inside the `.git` directory of your repository.
❯ pre-commit run -av bandit-salt
An error has occurred: FatalError: git toplevel unexpectedly empty! make sure you are not inside the `.git` directory of your repository.
Check the log at /home/vampas/.cache/pre-commit/pre-commit.log

Version 2.9.2 works fine:

❯ pip install pre-commit==2.9.2
Collecting pre-commit==2.9.2
  Using cached pre_commit-2.9.2-py2.py3-none-any.whl (184 kB)
Requirement already satisfied: importlib-metadata in /home/vampas/.dotfiles/.ext/pyenv/versions/3.6.8/envs/SaltPriv-3.6/lib/python3.6/site-packages (from pre-commit==2.9.2) (3.1.1)
Requirement already satisfied: virtualenv>=20.0.8 in /home/vampas/.dotfiles/.ext/pyenv/versions/3.6.8/envs/SaltPriv-3.6/lib/python3.6/site-packages (from pre-commit==2.9.2) (20.2.2)
Requirement already satisfied: pyyaml>=5.1 in /home/vampas/.dotfiles/.ext/pyenv/versions/3.6.8/envs/SaltPriv-3.6/lib/python3.6/site-packages (from pre-commit==2.9.2) (5.3.1)
Requirement already satisfied: nodeenv>=0.11.1 in /home/vampas/.dotfiles/.ext/pyenv/versions/3.6.8/envs/SaltPriv-3.6/lib/python3.6/site-packages (from pre-commit==2.9.2) (1.5.0)
Requirement already satisfied: cfgv>=2.0.0 in /home/vampas/.dotfiles/.ext/pyenv/versions/3.6.8/envs/SaltPriv-3.6/lib/python3.6/site-packages (from pre-commit==2.9.2) (3.2.0)
Requirement already satisfied: identify>=1.0.0 in /home/vampas/.dotfiles/.ext/pyenv/versions/3.6.8/envs/SaltPriv-3.6/lib/python3.6/site-packages (from pre-commit==2.9.2) (1.5.10)
Requirement already satisfied: toml in /home/vampas/.dotfiles/.ext/pyenv/versions/3.6.8/envs/SaltPriv-3.6/lib/python3.6/site-packages (from pre-commit==2.9.2) (0.10.2)
Requirement already satisfied: importlib-resources in /home/vampas/.dotfiles/.ext/pyenv/versions/3.6.8/envs/SaltPriv-3.6/lib/python3.6/site-packages (from pre-commit==2.9.2) (3.3.0)
Requirement already satisfied: zipp>=0.5 in /home/vampas/.dotfiles/.ext/pyenv/versions/3.6.8/envs/SaltPriv-3.6/lib/python3.6/site-packages (from importlib-metadata->pre-commit==2.9.2) (3.4.0)
Requirement already satisfied: zipp>=0.5 in /home/vampas/.dotfiles/.ext/pyenv/versions/3.6.8/envs/SaltPriv-3.6/lib/python3.6/site-packages (from importlib-metadata->pre-commit==2.9.2) (3.4.0)
Requirement already satisfied: importlib-resources in /home/vampas/.dotfiles/.ext/pyenv/versions/3.6.8/envs/SaltPriv-3.6/lib/python3.6/site-packages (from pre-commit==2.9.2) (3.3.0)
Requirement already satisfied: six<2,>=1.9.0 in /home/vampas/.dotfiles/.ext/pyenv/versions/3.6.8/envs/SaltPriv-3.6/lib/python3.6/site-packages (from virtualenv>=20.0.8->pre-commit==2.9.2) (1.15.0)
Requirement already satisfied: filelock<4,>=3.0.0 in /home/vampas/.dotfiles/.ext/pyenv/versions/3.6.8/envs/SaltPriv-3.6/lib/python3.6/site-packages (from virtualenv>=20.0.8->pre-commit==2.9.2) (3.0.12)
Requirement already satisfied: distlib<1,>=0.3.1 in /home/vampas/.dotfiles/.ext/pyenv/versions/3.6.8/envs/SaltPriv-3.6/lib/python3.6/site-packages (from virtualenv>=20.0.8->pre-commit==2.9.2) (0.3.1)
Requirement already satisfied: importlib-metadata in /home/vampas/.dotfiles/.ext/pyenv/versions/3.6.8/envs/SaltPriv-3.6/lib/python3.6/site-packages (from pre-commit==2.9.2) (3.1.1)
Requirement already satisfied: appdirs<2,>=1.4.3 in /home/vampas/.dotfiles/.ext/pyenv/versions/3.6.8/envs/SaltPriv-3.6/lib/python3.6/site-packages (from virtualenv>=20.0.8->pre-commit==2.9.2) (1.4.4)
Installing collected packages: pre-commit
  Attempting uninstall: pre-commit
    Found existing installation: pre-commit 2.9.3
    Uninstalling pre-commit-2.9.3:
      Successfully uninstalled pre-commit-2.9.3
Successfully installed pre-commit-2.9.2
WARNING: You are using pip version 20.3.1; however, version 21.0 is available.
You should consider upgrading via the '/home/vampas/.dotfiles/.ext/pyenv/versions/3.6.8/envs/SaltPriv-3.6/bin/python3.6 -m pip install --upgrade pip' command.
~/projects/SaltStack/CVEs/salt/salt-priv/features/bandit (features/bandit|✔) SaltPriv-3.6
❯ pre-commit run -av bandit-salt
Run bandit against Salt..................................................^CInterrupted (^C): KeyboardInterrupt:
Check the log at /home/vampas/.cache/pre-commit/pre-commit.log
@asottile
Copy link
Member

It works correctly for me, and the testsuite -- what version of git are you using and what is your working directory ?

$ git rev-parse --show-cdup

$ git rev-parse --git-common-dir
/tmp/zz/astpretty/.git
$ pwd
/tmp/zz/wat

@s0undt3ch
Copy link
Contributor Author

❯ git --version
git version 2.30.0

Let me run this in a public repo, can't share info on the repo I'm currently working, but basically, I do a bare clone into /the/path and then the repo branches go into /the/path/branches/<branch-name> and, for this particular case, a feature branch it goes into /the/path/features/<feature-name> which is also my cwd when I got the error.

@s0undt3ch
Copy link
Contributor Author

The above all using worktrees.

@asottile
Copy link
Member

ah it seems to be a check specifically for "is the worktree inside the git dir" -- I wasn't using a bare clone for the base repository so it didn't hit that

if os.path.commonpath((root, git_dir)) == git_dir:

@asottile
Copy link
Member

the specific combination for this is:

  • base repo is a bare repo
  • inside a worktree of that bare repo
  • that worktree is a subdirectory of the bare repo

@asottile asottile added the bug label Jan 27, 2021
@asottile
Copy link
Member

would you be able to try out the patch in #1778?

@s0undt3ch
Copy link
Contributor Author

Sorry, didn't saw your message until now.
Thank You for the fast response.
I'll let you know next time I'm on my laptop.

This was referenced Mar 8, 2021
This was referenced Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants