forked from scalacenter/scalafix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f63b5b
commit 51abefa
Showing
5 changed files
with
170 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
scalafix-sbt/src/main/scala/scalafix/internal/sbt/JGitCompletions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package scalafix.internal.sbt | ||
|
||
import java.nio.file.Path | ||
import org.eclipse.jgit.storage.file.FileRepositoryBuilder | ||
import org.eclipse.jgit.api.Git | ||
import org.eclipse.jgit.lib.RefDatabase | ||
import org.eclipse.jgit.lib.Repository | ||
import org.eclipse.jgit.util.GitDateFormatter | ||
import scala.collection.JavaConverters._ | ||
|
||
class JGitCompletion(cwd: Path) { | ||
val builder = new FileRepositoryBuilder() | ||
val repo = builder.readEnvironment().setWorkTree(cwd.toFile).build() | ||
val refList = repo.getRefDatabase().getRefs(RefDatabase.ALL).asScala | ||
val branchAndTags = refList.map { | ||
case (a, b) => Repository.shortenRefName(a) | ||
} | ||
val git = new Git(repo) | ||
val refs = git.log().setMaxCount(20).call().asScala.toList | ||
val dateFormatter = new GitDateFormatter(GitDateFormatter.Format.RELATIVE) | ||
|
||
val last20Commits = refs.map { ref => | ||
val relativeCommitTime = | ||
dateFormatter.formatDate(refs.head.getCommitterIdent) | ||
val abrev = ref.abbreviate(8).name | ||
val short = ref.getShortMessage | ||
// TODO: figure out how to display the whole message but only auto-complete on abrev | ||
s"$abrev -- $short ($relativeCommitTime)" | ||
} | ||
|
||
def all: Iterable[String] = branchAndTags ++ last20Commits | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters