gabyx / Githooks

🦎 Githooks: per-repo and shared Git hooks with version control and auto update. [✩Star] if you're using it!
MIT License
103 stars 4 forks source link

Cannot git init #178

Closed nf-brentsaner closed 23 hours ago

nf-brentsaner commented 1 day ago

This seems to be related to a recent update.

$ mkdir /var/tmp/testrepo

$ cd /var/tmp/testrepo

$ git init
⛔ Could not get git directory.
   -> errors:
   ✗  Command failed: 'git ["rev-parse" "--absolute-git-dir"]' [cwd: '/var/tmp/testrepo', env: [], err: 'fatal: not a git repository: '/var/tmp/testrepo/.git'
     '].
   ✗  exit status 128
⛔ Fatal error -> Abort.
⛔ Could not get git directory.
   -> errors:
   ✗  Command failed: 'git ["rev-parse" "--absolute-git-dir"]' [cwd: '/var/tmp/testrepo', env: [], err: 'fatal: not a git repository: '/var/tmp/testrepo/.git'
     '].
   ✗  exit status 128
⛔ Fatal error -> Abort.
fatal: ref updates aborted by hook

This creates a half-created broken .git subdirectory:

$ tree .git
.git
├── config
├── hooks
│   ├── applypatch-msg
│   ├── commit-msg
│   ├── githooks-contains-run-wrappers
│   ├── post-applypatch
│   ├── post-checkout
│   ├── post-commit
│   ├── post-index-change
│   ├── post-merge
│   ├── post-receive
│   ├── post-rewrite
│   ├── post-update
│   ├── pre-applypatch
│   ├── pre-auto-gc
│   ├── pre-commit
│   ├── pre-merge-commit
│   ├── prepare-commit-msg
│   ├── pre-push
│   ├── pre-rebase
│   ├── pre-receive
│   ├── push-to-checkout
│   ├── reference-transaction
│   ├── sendemail-validate
│   └── update
└── refs
    ├── heads
    └── tags

5 directories, 24 files

$ git status
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

This seems to be triggered by ~/.githooks/release/githooks/git/gitcommon.go, i.e. git(x).GetGitDirWorktree() (https://github.com/gabyx/Githooks/blob/main/githooks/git/gitcommon.go#L113).

This being called on a repo as part of initialization will (and does, as seen) fail.

gabyx commented 1 day ago

@nf-brentsaner : Thanks alot for the pointers. I have seen this on the Windows build fail! But not on the Linux, obviously its also a Linux problem. So what I see is that git init already lunches some hooks, apparently and now Githooks fails, which is pretty bad. I need to investigate, I guess its a new Git feature...?

gabyx commented 1 day ago

@nf-brentsaner : This seems to be an issue in Githooks with Git 2.46, I need to find out what git init does, which hook it triggers and then somehow fix it.

gabyx commented 1 day ago

Maybe you can add also some more info: Can you run:

GITHOOKS_LOG_LEVEL=debug git init
# or
export GITHOOKS_LOG_LEVEL=debug
git init
nf-brentsaner commented 1 day ago

Maybe you can add also some more info: Can you run:

GITHOOKS_LOG_LEVEL=debug git init
# or
export GITHOOKS_LOG_LEVEL=debug
git init

of course, would be glad to- give me about 30m-1h when i'll be back at my keyboard.

gabyx commented 1 day ago

@nf-brentsaner : Ok, it seems that reference-transaction hook runs on git init and inside the hook a git rev-parse --git-dir does not work althoug the GIT_DIR variable is defined AND the docs says the git rev-parse --git-dir command reads $GIT_DIR if defined. This is sad. So I probably have to workaround this, by first looking at GIT_DIR myself. Maybe report this upstream.

gabyx commented 1 day ago

@nf-brentsaner : Fast fix: Disable reference-transaction with git hooks installer --maintained-hooks "all,!reference-transaction" ... OR do not use --centralized, which will not run hooks on git init (since you have no global core.hooksPath set).

gabyx commented 23 hours ago

Closed by #176

nf-brentsaner commented 16 hours ago

Just checking in (...it took a bit longer than an hour to get back to my keyboard, heh), I've just tried 3.0.3 and I wanted to confirm the issue is fixed for me, looks like you nailed it. Thank you for being so responsive and fixing it so quickly!