Closed daniel-church closed 2 years ago
Did you use the exact git-hooks files I provided? line 11 shouldn't execute anything at all.
I was using the exact sheet, but took those two commented lines out that were at line 11 to see if it was causing the issue. Now I have the below script and get the below message, which lines up with the if statement that seems to be causing the issue.
#!/bin/sh
#
# Pull before committing
# Credential handling options:
# - hardcode credentials in URL
# - use ssh with key auth
# - https://git-scm.com/docs/git-credential-store
# - git credential helper on windows
output=$(git pull --no-rebase)
# Handle non error output as otherwise it gets shown with any exit code by logseq
if [[ "$output" == "Already up to date." ]]; then
# no ouput
exit 0
else
# probably error print it to screen
echo $output
fi
git add -A
10:36:03.482 › [Git] .git/hooks/pre-commit: 13: [[: not found
Already up to date.
Maybe the space character or the newline character are having issues on windows and linux.
I don't think it's a big problem. But if you very want to get rid of it, maybe you can re-type the pre-commits
. Remember to use the .sample
files in the .git/hooks
as template because the file type is very unique.
Once I made the slight modifications below it began working. May be useful to note for any additional Linux users. I didn't dive too much farther into it, but I am assuming the sh interpreter does not include the double brackets as valid if syntax or something along those lines.
Thanks again for putting this all together, very excited to get this all integrated!
#!/bin/sh
output=$(git pull --no-rebase)
# Handle non error output as otherwise it gets shown with any exit code by logseq
if [ "$output" = "Already up to date." ]
then
# no ouput
exit 0
else
# probably error print it to screen
echo "else"
# echo $output
fi
git add -A
Interesting!
If it's the interpreter that goes wrong, maybe you can try replace #!/bin/bash
with #!/bin/sh
It's not the interpreter. It's a bug in your pre-commit script, which has [[ ]] instead of [ ].
I'll do a pr later.
@romilly thanks! So my pre-commit script will act differently on different platform? Is there a more robust way to do it?
I'm no expert, and I have no access to Windows or OS/X - Linux only I'm afraid.
Also I am now getting a (slightly different) error. I'll do a PR when it's working :)
Cool!
Doh! The code is fine, it's the difference between sh and bash on recent Linuxes.
With #!/bin/bash
as the shebang, all works.
And thanks for an excellent guide!
Cool! So just the shebang? [[ ]]
is actuacally fine? If that's the only problem I'll fix it right now.
Running on Ubuntu 20.04 I get the below error message every time logseq attempts to commit. The script runs fine with bash, but errors out every time it is included in the git process.