Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint-commit-messages does not work by default on Travis CI #2

Open
davidchambers opened this issue Feb 4, 2018 · 9 comments
Open

Comments

@davidchambers
Copy link
Member

Travis CI only checks out the feature branch, so git log --no-merges --format=%s master.. returns no results.

I see two possible solutions:

  • document Travis CI configuration for checking out the default branch; or
  • compare to the remote's default branch rather than to the local repository's default branch.
@davidchambers
Copy link
Member Author

davidchambers commented Feb 5, 2018

After several hours of trial and error I succeeded in getting lint-commit-messages to work on Travis CI. I arrived at this configuration:

before_script:
  - git fetch origin refs/heads/master:refs/heads/master
  - if [ "$TRAVIS_PULL_REQUEST_BRANCH" ] ; then git checkout -b "$TRAVIS_PULL_REQUEST_BRANCH" ; fi

Travis CI performs two checks: push and pr. In both cases the repository is in a “detached HEAD” state. Semantically it would be correct to check out the pull request branch in the push case (since HEAD points to the same commit as the branch pointer), but TRAVIS_PULL_REQUEST_BRANCH is only defined in the pr case. So, we give the detached head the name of the pull request branch in the pr case and let the “branch name” be something like fantasyland/HEAD in the pull push case. The length of the pull request branch name is thus checked in the pr case but not in the pull push case.

@Avaq
Copy link
Member

Avaq commented Feb 5, 2018

In the last few sentences you introduce the term pull. Did you mean push instead?

@davidchambers
Copy link
Member Author

Indeed. I knew I shouldn't try to explain this at three in the morning!

@Avaq
Copy link
Member

Avaq commented Feb 5, 2018

I did notice the post' time, yes. ;)

@Avaq
Copy link
Member

Avaq commented Feb 5, 2018

I understand the solution, but I don't understand the problem.

Travis CI only checks out the feature branch

Do you mean that it fetches only the feature branch?

@Avaq
Copy link
Member

Avaq commented Feb 5, 2018

If so, then only the initial step of your before_script should be necessary, right?

@davidchambers
Copy link
Member Author

Do you mean that it fetches only the feature branch?

Yes. By default git branch --list shows only the detached head.

If so, then only the initial step of your before_script should be necessary, right?

The two lines serve different purposes: the first creates a local master branch; the second ensures that the name of the pull request branch is used when checking the length of the message of the prospective merge commit.

-Merge pull request #999 from fantasyland/HEAD
+Merge pull request #999 from fantasyland/davidchambers/scripts

@Avaq
Copy link
Member

Avaq commented Feb 5, 2018

the second ensures that the name of the pull request branch is used when checking the length of the message of the prospective merge commit.

But shouldn't this particular commit (the detached head) be ignored by --no-merges, seeing as it is a merge commit from $TRAVIS_PULL_REQUEST_BRANCH into master?

@davidchambers
Copy link
Member Author

The script does two distinct things: lints commits on the pull request branch and lints the prospective merge commit. The second check does not depend on the output of git log.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants