diffplug / diffplug/spotless

spotlessApply --staged

Offen
#623 14 Kommentare 23 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
enhancement
Vorherrschende Sprache
Java
Sterne
5.6k
Forks
559
Ø Merge
1 T. 13 Std.
Gemergte PRs (30 T.)
34

Beschreibung

Spotless applies itself to the files on disk. However, when git makes a commit, it does not use the files on disk, it uses the staging area. If you do this:

```
change foo.txt
spotlessApply
git add foo.txt
git commit -m "blah"
```

Then your commit will definitely pass a `spotlessCheck`. But if you do this, it might not:

```
change foo.txt
git add foo.txt
spotlessApply (changes foo on disk, but not the staged/index foo)
git commit -m "blah" (you committed the dirty foo, not the clean foo)
```

*aside: this three-files-per-file model, with an independent index, is confusing to beginners, and imo of limited utility even to experts, which is why [DiffPlug doesn't have a staging area](https://www.gitfromscratch.com/epilogue/departures/#no-index--staging-area).*

@lowwor made an excellent [git hook script](https://github.com/diffplug/spotless/issues/178#issuecomment-351638034) which uses the stash to run `spotlessCheck` on staged files.

With our new git integration, it would now be relatively easy for Spotless to have a mode which operates on the staging area directly. This is especially useful for pre-commit hooks, which could either fail on badly formatted content `spotlessCheck --staged`, or silently fix the commit right before it is created `spotlessApply --staged`.

~~Due to merge conflicts that this is likely to generate, implementing this is blocked on #603 and #600.~~ PR's welcome!

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.