I am trying to make some automations with git hooks. I managed to change commit messages with commit-msg hook. But unfortunately post-commit hook is not working with Logseq commits.
If I commit with manually (like git commit --amend for example) it works. If I trigger hook with git hook run post-commit it works. But with Logseq auto commit post-commit is not triggers.
Reproduce:
Create post-commit script in ~/.logseq/git/your_logseq_directory/.git/hooks/ directory
Make it executable (chmod +x post-commit)
Put different commit message in it. Like:
#!/bin/sh
git commit --amend -m "This is a post-commit triggered commit!"
Change something in your Logseq and wait to git auto commit.
Check git log to see if your post-commit hook is triggered and changed the commit message.
for anyone else having this issue - i was able to debug that on Ubuntu Linux it was due to the snap package using AppArmor for security confinement and restricting access to anything ssh.
Tip for debugging to validate this is the same issue you are finding:
in your .git/hook/post-commit file, add the line git push 2>&1 | tee .git/hooks/post-commit.log.
This showed me the error (note Logseq respects the GIT_SSH_COMMAND env variable if you need to modify the key being used):
Git push failed ssh -i ~/.ssh/github: 1: ssh: Permission denied fatal: Could not read from remote repository.
i used snap list | grep logseq to validate my package was managed through snap. the command snap connect <snap-name>:ssh-keys worked to provide the privileges needed to access my key and then the syncing through github works!
for those with flatpak - the analogous commands should be as follows if memory serves correct