diff --git a/check-diff.sh b/check-diff.sh index 07d6b57..06697d0 100755 --- a/check-diff.sh +++ b/check-diff.sh @@ -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 @@ -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} diff --git a/readme.md b/readme.md index 37151b3..fa3e4a1 100644 --- a/readme.md +++ b/readme.md @@ -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 @@ -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