Skip to content

Commit

Permalink
Change pattern to avoid using quotes because of pipe syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
goodwinnk committed Apr 4, 2018
1 parent 8ea1085 commit 83cc569
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/nk/patchsets/git/general.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ fun main(args: Array<String>) {
restore - for restore branch state
Example:
<program> restore C:/Projects/kotlin 173->172->171->as30
<program> restore . 173_as31_as32
""".trimIndent())

return
}

val command = args[0]
val commandArgs = args.sliceArray(1..args.size)
val commandArgs = args.toList().drop(1).toTypedArray()

when (command) {
"cp" -> cherryPick(commandArgs)
Expand Down
14 changes: 9 additions & 5 deletions src/main/kotlin/nk/patchsets/git/restore-branch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import nk.patchsets.git.FileChange
import nk.patchsets.git.commitChanges
import java.io.File

class Settings(val repoPath: String, val rule: String, val commitTitle: String = "==== switch ====")
data class Settings(val repoPath: String, val rule: String, val commitTitle: String = "==== switch ====")

val patchesSettings = Settings(
repoPath = "patches",
Expand All @@ -30,12 +30,12 @@ fun restore(args: Array<String>) {
Usage: <git-path> <branches-rule> <commit-title>?
<git-path> - Directory with repository (parent directory for .git folder)
<branches-rule> - Set of file suffixes separated with `->` showing what files should be affected and priority
<branches-rule> - Set of file suffixes separated with `_` showing what files should be affected and priority
of application.
<commit-title> - Title for switch commit. "==== switch ====" is used by default.
Example:
<program> C:/Projects/kotlin 173->172->171->as30
<program> C:/Projects/kotlin 173_as31_as32
""".trimIndent())

return
Expand All @@ -47,7 +47,11 @@ fun restore(args: Array<String>) {
commitTitle = args.getOrElse(2, { "==== switch ====" })
)

val suffixes = settings.rule.split("->")
val suffixes = settings.rule.split("_")
if (suffixes.size < 2) {
System.err.println("There should be at least source and target branches in pattern: ${settings.rule}")
return
}

val originBranchExtension = suffixes.first()
val donorExtensionsPrioritized = suffixes.subList(1, suffixes.size).reversed().toSet()
Expand Down Expand Up @@ -76,7 +80,7 @@ fun restore(args: Array<String>) {
val branchCopyFile = originFile.toPatchFile(originBranchExtension)

if (branchCopyFile.exists()) {
System.err.println("Can't store copy of origin file, because branch file is already exist: ${branchCopyFile}")
System.err.println("Can't store copy of the origin file, because branch file is already exist: ${branchCopyFile}")
return
}

Expand Down

0 comments on commit 83cc569

Please sign in to comment.