Fix config level completion on device
This commit is contained in:
@@ -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+"))
|
||||
|
||||
Reference in New Issue
Block a user