From 181a1f885670955069816c4959b85677bb5901ce Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Tue, 9 May 2023 18:41:50 +0200 Subject: [PATCH] Added SSH support for submodules Fixes #109 --- .../gitnuro/git/submodules/AddSubmoduleUseCase.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/submodules/AddSubmoduleUseCase.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/submodules/AddSubmoduleUseCase.kt index 0c6d48d..d931d79 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/submodules/AddSubmoduleUseCase.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/submodules/AddSubmoduleUseCase.kt @@ -1,21 +1,24 @@ package com.jetpackduba.gitnuro.git.submodules -import com.jetpackduba.gitnuro.models.ProgressMonitorInfo +import com.jetpackduba.gitnuro.git.remote_operations.HandleTransportUseCase import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.isActive import kotlinx.coroutines.withContext import org.eclipse.jgit.api.Git import org.eclipse.jgit.lib.ProgressMonitor +import org.eclipse.jgit.transport.CredentialsProvider import javax.inject.Inject -class AddSubmoduleUseCase @Inject constructor() { - suspend operator fun invoke(git: Git, name: String, path: String, uri: String) = withContext(Dispatchers.IO) { - +class AddSubmoduleUseCase @Inject constructor( + private val handleTransportUseCase: HandleTransportUseCase, +) { + suspend operator fun invoke(git: Git, name: String, path: String, uri: String): Unit = withContext(Dispatchers.IO) { git.submoduleAdd() .setName(name) .setPath(path) .setURI(uri) + .setTransportConfigCallback { handleTransportUseCase(it, git) } + .setCredentialsProvider(CredentialsProvider.getDefault()) .setProgressMonitor(object : ProgressMonitor { override fun start(totalTasks: Int) {} override fun beginTask(title: String?, totalWork: Int) {}