Skip to content
This repository was archived by the owner on Nov 10, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions check-diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ function lint_xml_files {
cd "$LINTING_DIRECTORY"
cat "$TEMP_DIRECTORY/paths-scope-xml" | remove_diff_range | xargs xmllint --noout
)
add_commit_message "Xmllint Check" "Passed"
}

function lint_php_files {
Expand Down
10 changes: 10 additions & 0 deletions pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ if [ ! -e "$DEV_LIB_PATH/check-diff.sh" ]; then
exit 1
fi

DEV_LIB_COMMIT_MESSAGE_FILE=".dev-lib-commit-message.$PPID"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcin-lawrowski I suggest storing this file in /tmp

DEV_LIB_COMMIT_MESSAGE=''
function add_commit_message {
label=$1
value=$2
DEV_LIB_COMMIT_MESSAGE+="\n$label: $value"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcin-lawrowski instead of appending to a variable, how about just appending it to the file?

echo "$label: $value" >> $DEV_LIB_COMMIT_MESSAGE_FILE

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When pre-commit terminates with return code other than 0 the file should be cleaned as well. In this approach the file is created only if all tests passed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, but I don't think that's so important now, since the file is getting stored in /tmp. It will automatically get garbage-collected with the next reboot.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, I wasn't aware that Bash supported the += operator. Thanks for enlightening me 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pleasure is all mine ;-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temporary files will be garbage-collected with the next reboot, but what about users that use this tool in some server environment which isn't rebooted often?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The files are super tiny, so I'm not so concerned about it, since this is going to be used on dev environments not servers. Also, there are a lot of other files being written to /tmp when running the pre-commit hook and Travis CI builds (see usages of TEMP_DIRECTORY in https://github.com/xwp/wp-dev-lib/blob/master/check-diff.sh).

}

source "$DEV_LIB_PATH/check-diff.sh"
set_environment_variables --diff-base ${DIFF_BASE:-HEAD} --diff-head ${DIFF_HEAD:-STAGE}
install_tools
Expand All @@ -41,3 +49,5 @@ if [[ $SYNC_README_MD == 1 ]] && [ -e readme.txt ] && cat "$TEMP_DIRECTORY/paths
git add $MARKDOWN_README_PATH
fi
fi

echo -e "$DEV_LIB_COMMIT_MESSAGE" > $DEV_LIB_COMMIT_MESSAGE_FILE
11 changes: 11 additions & 0 deletions prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
# WordPress prepare-commit-msg hook

DEV_LIB_COMMIT_MESSAGE_FILE=".dev-lib-commit-message.$PPID"

if [ -f "$DEV_LIB_COMMIT_MESSAGE_FILE" ]; then
COMMIT_EDITMSG=$1
cat "$DEV_LIB_COMMIT_MESSAGE_FILE" >> $COMMIT_EDITMSG
unlink "$DEV_LIB_COMMIT_MESSAGE_FILE"
fi

7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ To install the pre-commit hook, symlink to [`pre-commit`](pre-commit) from your
cd .git/hooks && ln -s ../../dev-lib/pre-commit . && cd -
```

To install the prepare-commit-msg hook, symlink to [`prepare-commit-msg`](prepare-commit-msg) from your project's `.git/hooks/prepare-commit-msg`:

```bash
cd .git/hooks && ln -s ../../dev-lib/prepare-commit-msg . && cd -
```

Also symlink (or copy) the [`.jshintrc`](.jshint), [`.jshintignore`](.jshintignore), [`.jscsrc`](.jscsrc), [`phpcs.ruleset.xml`](phpcs.ruleset.xml), and [`phpunit-plugin.xml`](phpunit-plugin.xml) (note the PHPUnit config will need its paths modified if it is copied instead of symlinked):

```bash
Expand All @@ -48,6 +54,7 @@ Often installing as a submodule is not viable, for example when contributing to
git clone https://github.com/xwp/wp-dev-lib.git ~/Projects/wp-dev-lib
cd my-plugin/.git/hooks
ln -s ~/Projects/wp-dev-lib/pre-commit
ln -s ~/Projects/wp-dev-lib/prepare-commit-msg
```

For the Travis CI checks, the `.travis.yml` copied and committed to the repo (see below) will clone the repo into the `dev-lib` directory if it doesn't exist (or whatever your `DEV_LIB_PATH` environment variable is set to).
Expand Down