Skip to content

Commit

Permalink
refactor: try to fetch header
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 8, 2023
1 parent 230372b commit 0cca6a4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ class GitCommandManager(var workingDirectory: String = ".", private var lfs: Boo

if (output != null) {
// Satisfy compiler, will always be set
return parseDefaultBranch(output!!.stdout)
return parseDefaultBranch(output!!.stdout) ?: throw Error("Unexpected output when retrieving default branch")
}

throw Error("Unexpected output when retrieving default branch")
}

@TestOnly
fun parseDefaultBranch(lines: String): String {
fun parseDefaultBranch(lines: String): String? {
for (splitLine in lines.trim().split("\n")) {
val line = splitLine.trim()
if (line.startsWith("ref:") && line.endsWith("HEAD")) {
Expand All @@ -163,7 +163,9 @@ class GitCommandManager(var workingDirectory: String = ".", private var lfs: Boo
}
}

throw Error("Unexpected output when retrieving default branch")
logger.error("Output: $lines")
logger.error("Unexpected output when retrieving default branch")
return null
}

fun submoduleForeach(command: String, recursive: Boolean): GitOutput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class GitSourceSettings(
val serverSide: Boolean = false,
val submodule: Boolean = false,
var fetchDepth: Int = 0,
val workdir: String = "",
var workdir: String = "",
) : CommandSetting {
val gitServerUrl: String = "https://github.com"
val nestedSubmodules: Boolean = false
Expand All @@ -35,7 +35,7 @@ class GitSourceSettings(
sshKey = argsMap["--ssh-key"] ?: "",
serverSide = argsMap["--server-side"]?.toBoolean() ?: false,
submodule = argsMap["--submodule"]?.toBoolean() ?: false,
workdir = argsMap["--workdir"] ?: "",
workdir = argsMap["--workdir"] ?: ".",
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ class GitSourceSettingsTest {
val branch = "master"

val settings = GitSourceSettings.fromArgs(arrayOf("--repository", repository, "--branch", branch))
settings.repositoryPath = ".tmp/codedb"

// settings.repository shouldBe repository
// settings.branch shouldBe branch
settings.workdir = ".tmp"

val commandManager = GitCommandManager(settings.repositoryPath)
doCheckout(commandManager, settings)
Expand Down

0 comments on commit 0cca6a4

Please sign in to comment.