new feature refetch remotes config sync hooks fail
SirNoSir opened this issue ยท 15 comments
๐ง Summary
I test the new feature refetch #736 but a problem occured while synchronizing git hooks.
Lefthook version
I test version 1.6.15
in windows environment.
Steps to reproduce
set refetch: true
and send a commit.
Expected results
Actual results
sync hooks fail, and git hooks files was removed after executing the commit.
Possible Solution
I suspect that the reason for the problem may be that the git hooks script(like prepare-commit-msg etc.) is trying to update itself during execution, the operating system reject this update command.
Also, before using refetch feature I add lefthook install
command in the rc file, the result is the same and error was file prepare-commit-msg access denied.
Maybe just download the remote file without updating git hooks is a way to fix this problem?
Logs / Screenshots
+ '[' '' = 0 ']'
+ '[' -f ./lefthookrc ']'
+ . ./lefthookrc
+ call_lefthook run prepare-commit-msg .git/COMMIT_EDITMSG
+ test -n ''
+ lefthook.exe -h
+ lefthook.exe run prepare-commit-msg .git/COMMIT_EDITMSG
โ [lefthook] cmd: [git rev-parse --show-toplevel]
โ [lefthook] err: <nil>
โ [lefthook] out: D:/source/
โ [lefthook] cmd: [git rev-parse --git-path hooks]
โ [lefthook] err: <nil>
โ [lefthook] out: .git/hooks
โ [lefthook] cmd: [git rev-parse --git-path info]
โ [lefthook] err: <nil>
โ [lefthook] out: .git/info
โ [lefthook] cmd: [git rev-parse --git-dir]
โ [lefthook] err: <nil>
โ [lefthook] out: .git
โ [lefthook] cmd: [git hash-object -t tree /dev/null]
โ [lefthook] err: <nil>
โ [lefthook] out: 4b825dc642cb6eb9a060e54bf8d69288fbee4904
โ Merging remote config: http://***/tools/lefthook-config: .git\info\lefthook-remotes\lefthook-config\remote_main.yml
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ ๐ฅ lefthook v1.6.15 hook: prepare-commit-msg โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ Updating remote config repository: .git\info\lefthook-remotes\lefthook-config
โ [lefthook] cmd: [git -C .git\info\lefthook-remotes\lefthook-config pull --quiet]
โ [lefthook] dir: D:/source/
โ [lefthook] err: <nil>
โ [lefthook] out:
โ Searching config in:D:/source/
โ Merging remote config: http://***/tools/lefthook-config: .git\info\lefthook-remotes\lefthook-config\remote_main.yml
sync hooks: โ
โ ๏ธ There was a problem with synchronizing git hooks.
Run 'lefthook install' manually.
Hey! I found a place where the error happens however lefthook does not log the error, so it's hard to say what was the actual problem. Does it fail the same way if you don't use refetch: true
and manually run lefthook install && lefthook run prepare-commit-msg
?
whether I set refetch true or false, It works well when i run lefthook install && lefthook run prepare-commit-msg
. Any ideas?
lefthook install && lefthook run prepare-commit-msg
sync hooks: โ๏ธ (prepare-commit-msg)
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ ๐ฅ lefthook v1.6.15 hook: prepare-commit-msg โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ remote-script.sh โฏ
d in %PATH%
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
summary: (done in 0.06 seconds)
๐ฅ remote-script.sh
So, it only fails if you run lefthook implicitly with git commit ...
command, right?
Could you please check these steps:
- remove
refetch: true
from the remotes - remove
lefthook install
from the rc file git add -A && git commit
Since you've touched the lefthook.yml
file lefthook should try to overwrite the hooks and display sync hooks: โ๏ธ (prepare-commit-msg)
. I just wonder if it fails to overwrite the hooks or the problem is related to fetching/merging the configs after fetching the remotes.
These are the details of my operations, I hope it can help.
- When I followed the steps above, the hooks sync failed. However, it still ran my script anyway.
- After that, I checked ./.git/hooks/ in my project, and the prepare-commit-msg file was removed.
- The next time I ran git commit, lefthook was not triggered since the hooks file was not present.
git add -A && git commit
warning: in the working copy of 'lefthook.yml', LF will be replaced by CRLF the next time Git touches it
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ ๐ฅ lefthook v1.6.15 hook: prepare-commit-msg โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
sync hooks: โ
โ ๏ธ There was a problem with synchronizing git hooks.
Run 'lefthook install' manually.
โ remote-script.sh โฏ
git add -A && git commit
Aborting commit due to empty commit message.
Ok, I will try to prepare a fix that at least displays the error.
I assume that this may be related to configuration merging and prepare-commig-msg
file may be dropped while being installed.
Could you share your lefthook.yml
hooks and the remote config (just the basic structure without the real commands/scripts)?
Of course, My config is very simple like:
# lefthook.yml
remotes:
- git_url: http://git_address/tools/lefthook-config
configs:
- remote_main.yml
# remote_main.yml
source_dir: ./
prepare-commit-msg:
scripts:
"remote-script.sh":
runner: bash
Thank you. I could not reproduce the error but I will release a new version that prints the error so we can have more context on what is the reason.
If you have a chance to install lefthook with go install github.com/evilmartians/lefthook@latest
, could you try the lefthook version that is currently in master?
Hey, The log I used master version with refetch option is as follows:
+ call_lefthook run prepare-commit-msg .git/COMMIT_EDITMSG
+ test -n ''
+ lefthook.exe -h
+ lefthook.exe run prepare-commit-msg .git/COMMIT_EDITMSG
โ [lefthook] cmd: [git rev-parse --show-toplevel]
โ [lefthook] err: <nil>
โ [lefthook] out: D:/source/IA-Git/main
โ [lefthook] cmd: [git rev-parse --git-path hooks]
โ [lefthook] err: <nil>
โ [lefthook] out: .git/hooks
โ [lefthook] cmd: [git rev-parse --git-path info]
โ [lefthook] err: <nil>
โ [lefthook] out: .git/info
โ [lefthook] cmd: [git rev-parse --git-dir]
โ [lefthook] err: <nil>
โ [lefthook] out: .git
โ [lefthook] cmd: [git hash-object -t tree /dev/null]
โ [lefthook] err: <nil>
โ [lefthook] out: 4b825dc642cb6eb9a060e54bf8d69288fbee4904
โ Merging remote config: http://git_address/tools/lefthook-config: .git\info\lefthook-remotes\lefthook-config\remote_main.yml
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ ๐ฅ lefthook v1.6.15 hook: prepare-commit-msg โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ Updating remote config repository: .git\info\lefthook-remotes\lefthook-config
โ [lefthook] cmd: [git -C .git\info\lefthook-remotes\lefthook-config pull --quiet]
โ [lefthook] dir: D:/source/MyProject/main
โ [lefthook] err: <nil>
โ [lefthook] out:
โ Searching config in:D:/source/MyProject/main
โ Merging remote config: http://git_address/tools/lefthook-config: .git\info\lefthook-remotes\lefthook-config\remote_main.yml
sync hooks: โ
โ ๏ธ There was a problem with synchronizing git hooks. Run 'lefthook install' manually.
Error: could not add the hook: open D:\source\MyProject\main\.git\hooks\prepare-commit-msg: Access is denied.
โ remote-script.sh โฏ
My config was like this:
# lefthook.yml
remotes:
- git_url: http://git_address/tools/lefthook-config
refetch: true
configs:
- remote_main.yml
Ok, I see that the problem is related to opening a file which is probably being executed at the moment of calling the script. I will need to think out a solution for this issue ๐ค
Hey, thank you for your reply. Although I am not familiar with Go and Bash, I would like to share my approach. I don't think updating prepare-commit-msg scripts during execution is necessary in this "refetch" case. Would it be feasible to update only remote scripts in the ./.git/info directory instead?
Yes, I think so, I will try to implement this approach ๐
@SirNoSir , could you please check the unpublished version (using the same go install ...
command as before). I've skipped installing the hooks if nothing is touched in the main config. So, this should fix the "Access is denied" error.
Great! I just tested the latest version. It ran perfectly and correctly, executed the script I had just modified on Git. Thank you for your help! ๐
Nice! I will prepare the release later this week ๐