Niedzielski has uploaded a new change for review. https://gerrit.wikimedia.org/r/305757
Change subject: move repeat code to function #chore ...................................................................... move repeat code to function #chore • move `git diff --name-only --cached` to function, git-staged-files. the new function includes the following changes: • -C -C: try hard to detect renames • -z: null terminate output. remaining greps have been updated to -z. • --diff-filter: filter out deleted files. remove -f tests • replace some grep calls with git glob in a new function, git-is-staged. suppress output • quote filenames and update conditional expressions from [ to [[. remove occurrence of needless quoting Change-Id: I3c576fde879841476db776f126e1c47f28756886 --- M dev-scripts/pre-commit 1 file changed, 21 insertions(+), 19 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/57/305757/1 diff --git a/dev-scripts/pre-commit b/dev-scripts/pre-commit index d0d8f5f..52392dc 100755 --- a/dev-scripts/pre-commit +++ b/dev-scripts/pre-commit @@ -2,45 +2,47 @@ # Enable this pre-commit hook by running 'make installhooks' set -euo pipefail +git-staged-files() { + git diff --cached -C -C -z --name-only --diff-filter=ACMRTUXB "$@" +} + +git-is-staged() { + local diff=0 + git-staged-files --quiet "$@" 2> /dev/null || diff=$? + [[ diff -eq 1 ]] || return 1 +} + # check for trailing whitespace git diff --cached --check make jshint make jscs -if git diff --name-only --cached | grep --regexp '\.js$' ; then +if git-is-staged \*.js; then make qunit fi -if git diff --name-only --cached | grep --regexp '\.*php$' ; then +if git-is-staged \*.php; then make phplint fi -if git diff --name-only --cached | grep --regexp 'includes/skins/.*php$' ; then +if git-is-staged 'includes/skins/*.php'; then make validatehtml > $result fi -for file in `git diff --cached --name-only | grep -i ".png\$"` +for file in `git-staged-files | grep -zi '\.png$'` do echo "Compressing $file" - if [ -f $file ]; then - optipng -q -o7 "$file" && advpng -z -4 "$file" && advdef -z -4 "$file" | grep "Output" - git add "$file" - else - echo 'file was removed' - fi + optipng -q -o7 "$file" && advpng -z -4 "$file" && advdef -z -4 "$file" | grep Output + git add "$file" done -for file in `git diff --cached --name-only | grep -i ".svg\$"` +for file in `git-staged-files | grep -zi '\.svg$'` do make nodecheck echo "Compressing $file" - if [ -f $file ]; then - # If anyone can figure out how to get the pretty option to work from the config - # file, feel free to remove it here. - node_modules/.bin/svgo --config=.svgo.yml "$file" --pretty - git add "$file" - else - echo 'file was removed' - fi + # If anyone can figure out how to get the pretty option to work from the config + # file, feel free to remove it here. + node_modules/.bin/svgo --config=.svgo.yml "$file" --pretty + git add "$file" done -- To view, visit https://gerrit.wikimedia.org/r/305757 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3c576fde879841476db776f126e1c47f28756886 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Niedzielski <sniedziel...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits