diffplug / diffplug/spotless

spotlessApply --staged

未关闭
#623 14 条评论 23 个 reaction 已指派 0 人 在 GitHub 查看
enhancement
主要语言
Java
星标
5.6k
派生
559
平均合并
1 天 14 小时
30 天内合并 PR
43

描述

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!

贡献指南

打开贡献指南

调研方向

首先阅读 issue #178 中链接的 staged 文件 hook 脚本,并检查 Spotless 现有的 git 集成。在选择方案之前,先查看围绕 #603 和 #600 的讨论。完成的标准是提供 staged 模式,用于检查或应用格式化,同时不更改未 staged 的 working-tree 内容。

由索引模型根据 Issue 内容生成。

评估

技术栈
git, java
领域
build-system, tooling
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
冷清
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。