From e3e8cdb0928df14d3f93e2a69739af24133f363c Mon Sep 17 00:00:00 2001 From: Magnus Ihse Bursie Date: Fri, 28 Jul 2023 15:04:57 +0200 Subject: [PATCH 1/2] Add information about using ratchetFrom on CI systems Add the important TL;DR from #710 to the documentation where it is pertinent. --- plugin-gradle/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 3484e3cd59..33d3ede9d6 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -1326,6 +1326,15 @@ However, we strongly recommend that you use a non-local branch, such as a tag or This is especially helpful for injecting accurate copyright dates using the [license step](#license-header). +### Using ratchetFrom on CI systems + +If you are running Spotless on a CI system, make sure you do not have a shallow clone, or `ratchetFrom` will fail with `No such reference`. Many CI systems use a shallow clone by default for performance reasons. Here is how you turn off shallow clones for some common CI systems: + +* **GitHub Actions**: Ad `fetch-depth: 0` to `.yml` +* **GitLab CI**: Add `GIT_DEPTH: 0` under the `variables:` section of `.gitlab-ci.yml` +* **BitBucket Pipelines**: Add `clone: depth: full` to the build step +* **Travis**: Add `git: depth: false` in `travis.yml` + ## `spotless:off` and `spotless:on` Sometimes there is a chunk of code which you have carefully handcrafted, and you would like to exclude just this one little part from getting clobbered by the autoformat. Some formatters have a way to do this, many don't, but who cares. If you setup your spotless like this: From 16f41e7d25a86913e5d0e97bc2265779466c59bb Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 28 Jul 2023 13:58:45 -0700 Subject: [PATCH 2/2] Condense the `ratchetFrom` CI info. --- plugin-gradle/README.md | 10 ++++------ plugin-maven/README.md | 7 +++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 33d3ede9d6..fc0aa45a3f 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -1326,14 +1326,12 @@ However, we strongly recommend that you use a non-local branch, such as a tag or This is especially helpful for injecting accurate copyright dates using the [license step](#license-header). -### Using ratchetFrom on CI systems +### Using `ratchetFrom` on CI systems -If you are running Spotless on a CI system, make sure you do not have a shallow clone, or `ratchetFrom` will fail with `No such reference`. Many CI systems use a shallow clone by default for performance reasons. Here is how you turn off shallow clones for some common CI systems: +Many popular CI systems (GitHub, GitLab, BitBucket, and Travis) use a "shallow clone". This means that `ratchetFrom 'origin/main'` will fail with `No such reference`. You can fix this by: -* **GitHub Actions**: Ad `fetch-depth: 0` to `.yml` -* **GitLab CI**: Add `GIT_DEPTH: 0` under the `variables:` section of `.gitlab-ci.yml` -* **BitBucket Pipelines**: Add `clone: depth: full` to the build step -* **Travis**: Add `git: depth: false` in `travis.yml` +- calling `git fetch origin main` before you call Spotless +- disabling the shallow clone [like so](https://github.com/diffplug/spotless/issues/710) ## `spotless:off` and `spotless:on` diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 62f2a4ea57..2d14c6edc7 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -1526,6 +1526,13 @@ You can explicitly disable ratchet functionality by providing the value 'NONE': ``` This is useful for disabling the ratchet functionality in child projects where the parent defines a ratchetFrom value. +### Using `ratchetFrom` on CI systems + +Many popular CI systems (GitHub, GitLab, BitBucket, and Travis) use a "shallow clone". This means that `origin/main` will fail with `No such reference`. You can fix this by: + +- calling `git fetch origin main` before you call Spotless +- disabling the shallow clone [like so](https://github.com/diffplug/spotless/issues/710) + ## `spotless:off` and `spotless:on` Sometimes there is a chunk of code which you have carefully handcrafted, and you would like to exclude just this one little part from getting clobbered by the autoformat. Some formatters have a way to do this, many don't, but who cares. If you setup your spotless like this: