Fix bisect script run and level validators
This commit is contained in:
@@ -24,6 +24,27 @@ internal fun directoryCompletionCandidates(repo: RepoState): List<String> {
|
||||
.distinct()
|
||||
}
|
||||
|
||||
internal fun contextualCompletionCandidates(
|
||||
candidates: List<String>,
|
||||
commandBeforeToken: String,
|
||||
token: String,
|
||||
directoriesOnly: Boolean,
|
||||
): List<String> {
|
||||
val matches = candidates.sorted().filter { it.startsWith(token) }
|
||||
if (directoriesOnly) return matches
|
||||
|
||||
val commandTokens = GitSandboxEngine.tokenizeCommand(commandBeforeToken.trim())
|
||||
if (commandTokens == listOf("git", "bisect", "run")) {
|
||||
val scriptMatches = matches.filter { candidate ->
|
||||
val normalized = candidate.removePrefix("./")
|
||||
normalized.endsWith(".sh") && '/' !in normalized && !normalized.startsWith(".")
|
||||
}
|
||||
if (scriptMatches.isNotEmpty()) return scriptMatches
|
||||
}
|
||||
|
||||
return matches
|
||||
}
|
||||
|
||||
private fun RepoState.currentDirPrefix(): String {
|
||||
return if (currentDir == ".") "" else currentDir.trimEnd('/') + "/"
|
||||
}
|
||||
|
||||
@@ -369,7 +369,12 @@ fun GitHugApp() {
|
||||
if (token.isBlank() && !isCdCompletion) return
|
||||
|
||||
val candidates = runtime.completionCandidates(currentLevel, repo, directoriesOnly = isCdCompletion)
|
||||
val matches = candidates.sorted().filter { it.startsWith(token) }
|
||||
val matches = contextualCompletionCandidates(
|
||||
candidates = candidates,
|
||||
commandBeforeToken = beforeCursor.substring(0, tokenStart),
|
||||
token = token,
|
||||
directoriesOnly = isCdCompletion,
|
||||
)
|
||||
if (matches.isEmpty()) return
|
||||
|
||||
val replacement = if (matches.size == 1) matches.first() else commonPrefix(matches)
|
||||
|
||||
@@ -144,7 +144,12 @@ class GitRepositoryRuntime private constructor(
|
||||
|
||||
val result = when (expandedTokens.first()) {
|
||||
"git" -> {
|
||||
val gitResult = runGit(nativeGit, workingDir, expandedTokens.drop(1), invocation.environment)
|
||||
val gitResult = runGit(
|
||||
nativeGit,
|
||||
workingDir,
|
||||
normalizeGitArgumentsForAndroid(expandedTokens.drop(1)),
|
||||
invocation.environment,
|
||||
)
|
||||
AppLog.d(
|
||||
"GitRuntime",
|
||||
"Git command result level=${level.id} exit=${gitResult.exitCode} output=${gitResult.outputLines}",
|
||||
@@ -167,6 +172,19 @@ class GitRepositoryRuntime private constructor(
|
||||
return refreshedRepo to result.second
|
||||
}
|
||||
|
||||
private fun normalizeGitArgumentsForAndroid(arguments: List<String>): List<String> {
|
||||
if (
|
||||
arguments.size >= 3 &&
|
||||
arguments[0] == "bisect" &&
|
||||
arguments[1] == "run" &&
|
||||
arguments[2].startsWith("./") &&
|
||||
arguments[2].endsWith(".sh")
|
||||
) {
|
||||
return arguments.take(2) + listOf("sh", arguments[2]) + arguments.drop(3)
|
||||
}
|
||||
return arguments
|
||||
}
|
||||
|
||||
fun completionCandidates(level: Level, currentRepo: RepoState, directoriesOnly: Boolean): List<String> {
|
||||
requireNativeGit()
|
||||
val sandbox = sandboxDir(level)
|
||||
|
||||
Reference in New Issue
Block a user