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

Log debug messages about git filtering #183

Merged
merged 1 commit into from
Dec 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,26 @@ object ScalafmtPlugin extends AutoPlugin {

private def getFileFilter(): Path => Boolean = {
def gitOps = GitOps.FactoryImpl(AbsoluteFile(currentProject.base.toPath))
val files =
if (filterMode == FilterMode.diffDirty)
gitOps.status()
else if (filterMode.startsWith(FilterMode.diffRefPrefix))
gitOps.diff(filterMode.substring(FilterMode.diffRefPrefix.length))
else if (scalafmtSession.isGitOnly)
gitOps.lsTree()
else null
if (files eq null) _ => true
else FileOps.getFileMatcher(files.map(_.path))
def getFromFiles(getFiles: => Seq[AbsoluteFile], gitCmd: => String) =
Try(getFiles) match {
case Failure(x) =>
log.error(s"format all files; [git $gitCmd]: ${x.getMessage}")
_: Path => true
case Success(x) =>
log.debug(s"considering ${x.length} files [git $gitCmd]")
FileOps.getFileMatcher(x.map(_.path))
}
if (filterMode == FilterMode.diffDirty)
getFromFiles(gitOps.status(), "status")
else if (filterMode.startsWith(FilterMode.diffRefPrefix)) {
val branch = filterMode.substring(FilterMode.diffRefPrefix.length)
getFromFiles(gitOps.diff(branch), s"diff $branch")
} else if (scalafmtSession.isGitOnly)
getFromFiles(gitOps.lsTree(), "ls-files")
else {
log.debug("considering all files (no git)")
_ => true
}
}

private def withFormattedSources[T](sources: Seq[File])(
Expand Down