From c6dec4518ad8495bbb07bbe76f6c9806842f2b98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederik=20=E2=80=9CFreso=E2=80=9D=20S=2E=20Olesen?= Date: Thu, 4 Aug 2016 21:08:09 +0200 Subject: [PATCH 1/2] Make the pre-commit Git hook executable. 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 e3b39b72336ac07724afa8ef659ba4301df12d21 / https://github.com/loot/loot/issues/622 [1] `ln -s ../../scripts/git/pre-commit .git/hooks/pre-commit` [2] `./scripts/git/pre-commit` vs. `/bin/sh ./scripts/git/pre-commit` --- resources/l10n/template.pot | 2 +- scripts/git/pre-commit | 0 2 files changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 scripts/git/pre-commit diff --git a/resources/l10n/template.pot b/resources/l10n/template.pot index ddad5d25..00accbbe 100644 --- a/resources/l10n/template.pot +++ b/resources/l10n/template.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: LOOT 0.9.2\n" "Report-Msgid-Bugs-To: https://github.com/loot/loot/issues\n" -"POT-Creation-Date: 2016-08-04 18:29+0100\n" +"POT-Creation-Date: 2016-08-04 21:46+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/scripts/git/pre-commit b/scripts/git/pre-commit old mode 100644 new mode 100755 From abd79707afe67baab7748dbeab1ad866f58d5194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederik=20=E2=80=9CFreso=E2=80=9D=20S=2E=20Olesen?= Date: Thu, 4 Aug 2016 21:34:17 +0200 Subject: [PATCH 2/2] Make the `git-commit` hook script POSIX compliant. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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`. --- scripts/git/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/git/pre-commit b/scripts/git/pre-commit index 1ea1f348..9bd5b00e 100755 --- a/scripts/git/pre-commit +++ b/scripts/git/pre-commit @@ -12,7 +12,7 @@ sed -i 's|charset=CHARSET|charset=UTF-8|' resources/l10n/template.pot LINES_ADDED=$(git diff --numstat resources/l10n/template.pot | cut -f 1) LINES_REMOVED=$(git diff --numstat resources/l10n/template.pot | cut -f 2) -if [[ "$LINES_ADDED" -eq "$LINES_REMOVED" && "$LINES_ADDED" -eq 1 ]]; then +if [ "$LINES_ADDED" = "$LINES_REMOVED" -a "$LINES_ADDED" = "1" ]; then git checkout -- resources/l10n/template.pot else git add resources/l10n/template.pot