Skip to content
This repository was archived by the owner on Nov 10, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 11 additions & 9 deletions check-diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function set_environment_variables {
PROJECT_SLUG=${PROJECT_SLUG:-$( basename "$PROJECT_DIR" | sed 's/^wp-//' )}
PATH_INCLUDES=${PATH_INCLUDES:-./}
PATH_EXCLUDES_PATTERN=${PATH_EXCLUDES_PATTERN:-'^(.*/)?(vendor|bower_components|node_modules)/.*'}
DEFAULT_BASE_BRANCH=${DEFAULT_BASE_BRANCH:-master}

if [ -z "$PROJECT_TYPE" ]; then
if [ -e style.css ]; then
Expand All @@ -57,17 +58,18 @@ function set_environment_variables {

if [ "$TRAVIS" == true ]; then
if [[ "$TRAVIS_PULL_REQUEST" != 'false' ]]; then

# Make sure the remote branch is fetched.
if [[ -z "$DIFF_BASE" ]] && ! git rev-parse --verify --quiet "$TRAVIS_BRANCH"; then
git fetch origin "$TRAVIS_BRANCH"
git branch "$TRAVIS_BRANCH" FETCH_HEAD
fi

DIFF_BASE=${DIFF_BASE:-$TRAVIS_BRANCH}
DIFF_BASE_BRANCH=$TRAVIS_BRANCH
else
DIFF_BASE=${DIFF_BASE:-$TRAVIS_COMMIT^}
DIFF_BASE_BRANCH=$DEFAULT_BASE_BRANCH
fi

# Make sure the remote branch is fetched.
if [[ -z "$DIFF_BASE" ]] && ! git rev-parse --verify --quiet "$DIFF_BASE_BRANCH" > /dev/null; then
git fetch origin "$DIFF_BASE_BRANCH"
git branch "$DIFF_BASE_BRANCH" FETCH_HEAD
fi

DIFF_BASE=${DIFF_BASE:-$DIFF_BASE_BRANCH}
DIFF_HEAD=${DIFF_HEAD:-$TRAVIS_COMMIT}
else
DIFF_BASE=${DIFF_BASE:-HEAD}
Expand Down
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ You may customize the behavior of the `.travis.yml` and `pre-commit` hook by
specifying a `.dev-lib` (formerly `.ci-env.sh`) Bash script in the root of the repo, for example:

```bash
DEFAULT_BASE_BRANCH=develop
PHPCS_GITHUB_SRC=xwp/PHP_CodeSniffer
PHPCS_GIT_TREE=phpcs-patch
PHPCS_IGNORE='tests/*,includes/vendor/*' # See also PATH_INCLUDES below
Expand All @@ -139,7 +140,7 @@ PATH_INCLUDES="docroot/wp-content/plugins/acme-* docroot/wp-content/themes/acme-
CHECK_SCOPE=patches
```

The `PATH_INCLUDES` is especially useful when the dev-lib is used in the context of an entire site, so you can target just the themes and plugins that you're responsible for. For *excludes*, you can specify a `PHPCS_IGNORE` var and override the `.jshintignore` (it would be better to have a `PATH_EXCLUDES` as well).
Set `DEFAULT_BASE_BRANCH` to be whatever your default branch is in GitHub; this is use when doing diff-checks on changes in a branch build on Travis CI. The `PATH_INCLUDES` is especially useful when the dev-lib is used in the context of an entire site, so you can target just the themes and plugins that you're responsible for. For *excludes*, you can specify a `PHPCS_IGNORE` var and override the `.jshintignore`; there is a `PATH_EXCLUDES_PATTERN` as well.

## Pre-commit tips

Expand Down