Skip to content

Commit

Permalink
Add new VCS/git operations
Browse files Browse the repository at this point in the history
Added:
- getCurrentBranch
- getBranches
- getRemoteBranches
- createBranch
  • Loading branch information
LouisCAD committed Jul 11, 2021
1 parent 0d9c851 commit 4b043cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,17 @@ private object Git : Vcs {
}

override fun getTags() = "git tag".execute().trimEnd().lineSequence()

override fun getCurrentBranch() = "git branch --show-current".execute().trimEnd()

override fun getBranches() = "git branch".execute().trimEnd().lineSequence().map {
it.substringAfter("* ").trimStart()
}

override fun getRemoteBranches() = "git branch -r".execute().trimEnd().lineSequence().mapNotNull {
if (it.startsWith("warning: ")) null
else it.trimStart()
}

override fun createBranch(branchName: String) = "git branch $branchName".executeAndPrint()
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ interface Vcs {
fun getRemotePushUrl(repository: String): String
fun mergeBranchIntoCurrent(sourceBranch: String)
fun getTags(): Sequence<String>
fun getCurrentBranch(): String
fun getBranches(): Sequence<String>
fun getRemoteBranches(): Sequence<String>
fun createBranch(branchName: String)
}

fun Vcs.isOnMainBranch() = isOnBranch(expectedBranchName = "main")
Expand Down

0 comments on commit 4b043cc

Please sign in to comment.