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] 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