Fix config level completion on device

This commit is contained in:
Joe Tretter
2026-06-24 20:32:23 -05:00
parent 1e87bd9aa7
commit 82e38de3bb
5 changed files with 89 additions and 17 deletions

View File

@@ -200,9 +200,33 @@ internal class GitRepositoryInspector(
userEmailResult.outputLines.firstOrNull()
?.takeIf { userEmailResult.exitCode == 0 && it.isNotBlank() }
?.let { put("user.email", it) }
putAll(readGitConfigFile(inspectionRoot).filterKeys { it !in keys })
}
}
private fun readGitConfigFile(inspectionRoot: File): Map<String, String> {
val configFile = File(inspectionRoot, ".git/config")
if (!configFile.isFile) return emptyMap()
val entries = linkedMapOf<String, String>()
var section = ""
configFile.forEachLine { rawLine ->
val line = rawLine.trim()
when {
line.isBlank() || line.startsWith("#") || line.startsWith(";") -> return@forEachLine
line.startsWith("[") && line.endsWith("]") -> {
section = line.removePrefix("[").removeSuffix("]").trim().substringBefore(' ')
}
"=" in line && section.isNotBlank() -> {
val key = line.substringBefore('=').trim()
val value = line.substringAfter('=').trim()
entries["$section.$key"] = value
}
}
}
return entries
}
private fun inspectRemoteRefs(git: File, inspectionRoot: File, remoteLines: List<String>): RemoteRefs {
val remotes = remoteLines.mapNotNull { line ->
val parts = line.trim().split(Regex("\\s+"))