Skip to content

Commit

Permalink
support sui git paths (#129)
Browse files Browse the repository at this point in the history
Co-authored-by: qingfengzs <[email protected]>
  • Loading branch information
mkurnikov and qingfengzs authored Jan 15, 2024
1 parent 3cd8cf4 commit c6010b0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
24 changes: 19 additions & 5 deletions src/main/kotlin/org/move/cli/manifest/TomlDependency.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.move.cli.manifest

import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths

Expand All @@ -24,15 +25,28 @@ sealed class TomlDependency {

override fun localPath(): Path {
val home = System.getProperty("user.home")
val dirName = dirName(repo, rev)
return Paths.get(home, ".move", dirName, subdir)
// TODO: add choice based on selected blockchain
val dirNameAptos = dirNameAptos(repo, rev)
val aptosPath = Paths.get(home, ".move", dirNameAptos, subdir)
if (Files.exists(aptosPath)) {
return aptosPath
} else {
val dirNameSui = dirNameSui(repo, rev)
val suiPath = Paths.get(home, ".move", dirNameSui, subdir)
return suiPath
}
}

companion object {
fun dirName(repo: String, rev: String): String {
fun dirNameAptos(repo: String, rev: String): String {
val sanitizedRepoName = repo.replace(Regex("[/:.@]"), "_")
val aptosRevName = rev.replace("/", "_")
return "${sanitizedRepoName}_$aptosRevName"
}
fun dirNameSui(repo: String, rev: String): String {
val sanitizedRepoName = repo.replace(Regex("[/:.@]"), "_")
val revName = rev.replace('/', '_')
return "${sanitizedRepoName}_$revName"
val suiRevName = rev.replace("/", "__")
return "${sanitizedRepoName}_$suiRevName"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/move/utils/tests/FileTree.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ interface FileTreeBuilder {
)

fun git(repo: String, rev: String, builder: TreeBuilder = {}) {
val dirName = TomlDependency.Git.dirName(repo, rev)
val dirName = TomlDependency.Git.dirNameAptos(repo, rev)
return dir(dirName, builder)
}

Expand Down

0 comments on commit c6010b0

Please sign in to comment.