spotless: ratchetFrom 'origin/main' does not fetch if not present

If you specify rachetFrom and the branch doesn’t exist locally, it should be fetched by the ratchet infrastructure.

https://github.com/JLLeitschuh/spotless/runs/1200916598?check_suite_focus=true#step:5:56

  [2020-10-02 21:07:06] [autobuild] * What went wrong:
  [2020-10-02 21:07:06] [autobuild] A problem occurred evaluating project ':ide'.
  [2020-10-02 21:07:06] [autobuild] > Could not create task ':lib:spotlessJava'.
  [2020-10-02 21:07:06] [autobuild]    > No such reference 'origin/main'

EDIT: Summary of workarounds from below

  • GitHub Actions: add fetch-depth: 0 to <action>.yml
  • GitLab CI: add GIT_DEPTH: 0 under the variables: section of .gitlab-ci.yml
  • BitBucket Pipelines: clone: depth: full
  • Travis: git: depth: false

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 5
  • Comments: 26 (18 by maintainers)

Commits related to this issue

Most upvoted comments

I would use environment variables and do something like:

String ratchetAnchor = if (System.getenv('CI') == 'true') 'origin/main' else 'upstream/main'
spotless {
  ratchetFrom ratchetAnchor

Easy short-term fix?

→ Internally convert all spotless tasks to no-ops when the ratchetFrom branch can’t be found.

  1. Avoids
    1. Pulling extra data during CI/CD
    2. Manually working around alternate branch names
  • Even on full clones, our CI/CD system doesn’t appear to create an origin/upstream remote ref.
  • We aren’t overly concerned with checking formatting in the CI/CD pipeline. We are happy having integrated spotlessApply into the local build steps.

Anyone using travis can override by adding the following in the travis.yml

git:
  depth: false

In case anyone runs into this issue with BitBucket Pipelines, adding clone: depth: full to the build step resolved it for me.

Let’s keep it open, I still think it’s a good idea.