From cf136a35d03f32bfbd84d083b09a2b0c17164553 Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Fri, 22 Mar 2024 18:42:27 +0100 Subject: [PATCH] Fixed GH cli with default args failing --- .../credentials/HttpCredentialsProvider.kt | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/credentials/HttpCredentialsProvider.kt b/src/main/kotlin/com/jetpackduba/gitnuro/credentials/HttpCredentialsProvider.kt index d8e378d..890de93 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/credentials/HttpCredentialsProvider.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/credentials/HttpCredentialsProvider.kt @@ -20,6 +20,7 @@ import kotlin.coroutines.cancellation.CancellationException private const val TIMEOUT_MIN = 1L private const val TAG = "HttpCredentialsProvider" +private const val GH_CLI_ARGS = "auth git-credential" class HttpCredentialsProvider @AssistedInject constructor( private val credentialsStateManager: CredentialsStateManager, @@ -132,7 +133,8 @@ class HttpCredentialsProvider @AssistedInject constructor( externalCredentialsHelper: ExternalCredentialsHelper, credentials: CredentialsAccepted.HttpCredentialsAccepted ) { - val process = shellManager.runCommandProcess(listOf(externalCredentialsHelper.path, "store")) + val arguments = listOf("store") + val process = shellManager.runCommandProcess(externalCredentialsHelper.sanitizedCommand() + arguments) val output = process.outputStream // write to the input stream of the helper val bufferedWriter = BufferedWriter(OutputStreamWriter(output)) @@ -164,11 +166,11 @@ class HttpCredentialsProvider @AssistedInject constructor( } private fun handleExternalCredentialHelper( - externalCredentialsHelper: ExternalCredentialsHelper, - uri: URIish, - items: Array + externalCredentialsHelper: ExternalCredentialsHelper, uri: URIish, items: Array ): ExternalCredentialsRequestResult { - val process = shellManager.runCommandProcess(listOf(externalCredentialsHelper.path, "get")) + // auth git-credential + val arguments = listOf("get") + val process = shellManager.runCommandProcess(externalCredentialsHelper.sanitizedCommand() + arguments) val output = process.outputStream // write to the input stream of the helper val input = process.inputStream // reads from the output stream of the helper @@ -284,7 +286,22 @@ class HttpCredentialsProvider @AssistedInject constructor( data class ExternalCredentialsHelper( val path: String, val useHttpPath: Boolean, -) +) { + /** + * Sometimes the git credentials manager path also includes these arguments (detected on Linux), they should be + * treated as arguments instead of part of the binary path + */ + fun sanitizedCommand(): List { + return if (path.endsWith(GH_CLI_ARGS)) { + val path = path.removeSuffix(GH_CLI_ARGS).trim() + val arguments = GH_CLI_ARGS.split(" ") + + listOf(path) + arguments + } else { + listOf(path) + } + } +} enum class ExternalCredentialsRequestResult { SUCCESS,