Skip to content

Commit

Permalink
Added fetching tags from current branch only as default
Browse files Browse the repository at this point in the history
  • Loading branch information
diareuse committed Apr 13, 2021
1 parent 6ddd693 commit 78200c0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/main/kotlin/dev/chainmail/taggy/git/GitCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,18 @@ class GitCommand private constructor(
}

fun getTags(): Sequence<String> {
println("Fetching all tags…")
if (args.everywhere) {
println("Fetching all tags…")
return commander
.runCatching { run("git", "tag", "-l") }
.getOrDefault(emptySequence())
}

println("Fetching current branch…")
return commander
.runCatching { run("git", "tag", "-l") }
.runCatching { run("git", "branch", "--show-current") }
.mapCatching { it.first().also { b -> println("Fetching tags from $b") } }
.mapCatching { commander.run("git", "tag", "--merged", it) }
.getOrDefault(emptySequence())
}

Expand Down
12 changes: 9 additions & 3 deletions src/main/kotlin/dev/chainmail/taggy/startup/Args.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Args(private val options: CommandLine) {

val push by Args.push.withFlag()
val force by Args.force.withFlag()
val everywhere by Args.everywhere.withFlag()

val pushTarget by Args.pushTarget.withDefaultNull()

Expand Down Expand Up @@ -47,9 +48,7 @@ class Args(private val options: CommandLine) {
.longOpt("postfix-separator")
.required(false)
.hasArg()
.desc(
"Separator which will be used for parsing appended postfix and appending the postfix when constructing tag. Beware that if you want to change separator, you need to provide the entire ensemble. (ie. postfix, postfix-separator and version)"
)
.desc("Separator which will be used for parsing appended postfix and appending the postfix when constructing tag. Beware that if you want to change separator, you need to provide the entire ensemble. (ie. postfix, postfix-separator and version)")
.build()

private val version: Option = Option.builder("v")
Expand Down Expand Up @@ -87,6 +86,12 @@ class Args(private val options: CommandLine) {
.desc("Specifies java regex pattern for the program to use when listing tags. It bypasses git's implementation since it uses non-robust wildcard implementation. This parameter is required.")
.build()

private val everywhere: Option = Option.builder()
.longOpt("everywhere")
.required(false)
.desc("Instructs the program to look in every branch for tags.")
.build()

}


Expand All @@ -100,6 +105,7 @@ class Args(private val options: CommandLine) {
addOption(pushTarget)
addOption(force)
addOption(pattern)
addOption(everywhere)
}
private var help: HelpFormatter = HelpFormatter()
private var parser: CommandLineParser = DefaultParser()
Expand Down

0 comments on commit 78200c0

Please sign in to comment.