Skip to content

Make pre-commit Git hook POSIX compliant and executable - #629

Merged
Freso merged 2 commits into
devfrom
make-githook-posix-compliant
Aug 4, 2016
Merged

Make pre-commit Git hook POSIX compliant and executable#629
Freso merged 2 commits into
devfrom
make-githook-posix-compliant

Conversation

@Freso

@Freso Freso commented Aug 4, 2016

Copy link
Copy Markdown
Member

See individual commit messages for reasoning.

@Freso Freso self-assigned this Aug 4, 2016
Freso added 2 commits August 4, 2016 21:46
This allows for symlinking it in .git/hooks/ directly[1] or executing
it from within an already existing `pre-commit` hook/script without
calling out to an interpreter in there[2], thus keeping up with any
upstream changes to it automatically.

Follow-up to e3b39b7 / #622

[1] `ln -s ../../scripts/git/pre-commit .git/hooks/pre-commit`
[2] `./scripts/git/pre-commit` vs. `/bin/sh ./scripts/git/pre-commit`
On a lot of systems using bashisms in /bin/sh scripts will be fine,
since /bin/sh is a symlink to /bin/bash, but some systems symlink it to
the more lightweight (and more strictly POSIX) /bin/dash or some other
shell. Safest thing is to not assume a bashism will work.

What has been changed:
1) `[[ … ]]` is a bashism. Replaced with `[ … ]`.
2) `-eq` is for numeric operations. When a variable is quoted, it
   becomes a string and uses `=` for comparison.
3) `&&` is a shell thing, but does not exist in `test`'s syntax.
   (`[ … ]` is shorthand for `test …`.) `-a` is the "and" when
   talking `test`.
@Freso
Freso force-pushed the make-githook-posix-compliant branch from 96ccf6c to abd7970 Compare August 4, 2016 19:47
@Freso Freso added this to the v0.10.0 milestone Aug 4, 2016
@Ortham

Ortham commented Aug 4, 2016

Copy link
Copy Markdown
Member

This doesn't seem to have worked, because it's included a POT file with only the creation date changed. 😕

@Freso

Freso commented Aug 4, 2016

Copy link
Copy Markdown
Member Author

Yeah, in the first of the two commits. Which is how I noticed the error in the hook script and made the second commit. I actually rebased it originally to remove the edit to the .pot, but I guess it snuck in again when I re-rebased it to fix a mistake in the ln -s call in the first commit's comment… I can re-re-rebase to remove the file, or it can stay in as a testament to the issue being fixed. :)

@Ortham

Ortham commented Aug 4, 2016

Copy link
Copy Markdown
Member

Oh, so the if statement was always returning false in your shell?

I've tested your changes out and they work for me. 👍 Though I have discovered that the hook isn't executed if I commit through GitHub Desktop, because it isn't finding xgettext in my PATH, so now I've got to figure why its PATH is different...

@Freso

Freso commented Aug 4, 2016

Copy link
Copy Markdown
Member Author

Oh, so the if statement was always returning false in your shell?

Yeah, exactly. And actually, on that note - it will probably be better to negate the checks. That is, use != instead of = and -o instead of -a. That way, if the test fails for whatever reason, it will default to not update the .pot.

@Freso

Freso commented Aug 4, 2016

Copy link
Copy Markdown
Member Author

Hm. No. I guess that won't work the way I naïvely imagined it.

@Freso
Freso merged commit abd7970 into dev Aug 4, 2016
Freso added a commit that referenced this pull request Aug 4, 2016
@Freso

Freso commented Aug 4, 2016

Copy link
Copy Markdown
Member Author

At half past ten in the evening I couldn't think of a way to do what I wanted to do without making the script significantly more complex. The script works now (for me :)), so merging it as it is now.

@Freso
Freso deleted the make-githook-posix-compliant branch August 4, 2016 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants