Skip to content

Commit

Permalink
fix: fix some typos
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 8, 2023
1 parent c722922 commit 46b3567
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.archguard.scanner.analyser.count.FileJob
import org.archguard.scanner.analyser.count.LanguageWorker
import java.nio.file.Files
import java.nio.file.Path
import kotlin.io.path.absolutePathString

interface CodePicker

Expand Down Expand Up @@ -51,7 +52,12 @@ class SimpleCodePicker(private val config: PickerConfig) : CodePicker {
* @throws IOException if an I/O error occurs during code checkout or processing.
*/
suspend fun execute() = coroutineScope {
val codeDir = checkoutCode(this@SimpleCodePicker, config.url, config.branch, config.baseDir)
val tempGitDir = Path.of(config.baseDir, ".tmp")
if (!tempGitDir.toFile().exists()) {
Files.createDirectories(tempGitDir)
}

val codeDir = checkoutCode(this@SimpleCodePicker, config.url, config.branch, tempGitDir)
.toFile().canonicalFile

logger.info("start picker")
Expand Down Expand Up @@ -118,25 +124,28 @@ class SimpleCodePicker(private val config: PickerConfig) : CodePicker {
return "$host/$owner/$repo"
}

fun checkoutCode(simpleCodePicker: SimpleCodePicker, url: String, branch: String, baseDir: String): Path {
fun checkoutCode(simpleCodePicker: SimpleCodePicker, url: String, branch: String, baseDir: Path): Path {
if (!gitUrlRegex.matches(url)) {
return Path.of(url)
}

val gitDir = gitUrlToPath(url)
val targetDir = Path.of(baseDir, gitDir)
val targetDir = baseDir.resolve(gitDir)
logger.info("targetDir: $targetDir")
if (targetDir.toFile().exists()) {
logger.info("targetDir exists: $targetDir")
// todo: if exists pull rebase code
return targetDir
}

val settings = GitSourceSettings.fromArgs(arrayOf("--repository", url, "--branch", branch))
val settings = GitSourceSettings(
repository = url,
branch = branch,
workdir = baseDir.absolutePathString(),
)
executeGitCheckout(settings)

// mv settings.repository to targetDir
val sourceRepoDir = Path.of(settings.repositoryPath)
val sourceRepoDir = baseDir.resolve(settings.repositoryPath)
try {
Files.createDirectories(targetDir.parent)
} catch (e: Exception) {
Expand Down

0 comments on commit 46b3567

Please sign in to comment.