Last active
January 7, 2018 06:15
-
-
Save dkandalov/5984577 to your computer and use it in GitHub Desktop.
Mini-plugin to get files from last N commits.
(This code is for https://github.com/dkandalov/live-plugin)
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
import com.intellij.openapi.project.Project | |
import com.intellij.openapi.roots.ProjectRootManager | |
import com.intellij.openapi.vcs.FilePathImpl | |
import com.intellij.openapi.vcs.ProjectLevelVcsManager | |
import com.intellij.openapi.vcs.VcsRoot | |
import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList | |
import com.intellij.openapi.vfs.VirtualFile | |
import static liveplugin.PluginUtil.* | |
if (isIdeStartup) return | |
static List<VcsRoot> vcsRootsIn(Project project) { | |
ProjectRootManager.getInstance(project).contentSourceRoots | |
.collect{ ProjectLevelVcsManager.getInstance(project).getVcsRootObjectFor(it) } | |
.findAll{ it.path != null }.unique() | |
} | |
static List<CommittedChangeList> lastCommitsIn(VcsRoot vcsRoot, int numberOfCommitsToLoad = 10) { | |
def changesProvider = vcsRoot.vcs.committedChangesProvider | |
def location = changesProvider.getLocationFor(FilePathImpl.create(vcsRoot.path)) | |
def settings = changesProvider.createDefaultSettings() | |
changesProvider.getCommittedChanges(settings, location, numberOfCommitsToLoad) | |
} | |
static Collection<VirtualFile> virtualFilesIn(Collection<CommittedChangeList> commits) { | |
commits.collectMany{it.changes.collect{it.virtualFile}} | |
} | |
def vcsRoot = vcsRootsIn(project).first() // simplification asuuming that normally there is one vcs root in project | |
show(virtualFilesIn(lastCommitsIn(vcsRoot)).join("\n")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I got this exception