Fixed fetch not working for newly added remotes

This commit is contained in:
Abdelilah El Aissaoui 2022-10-21 18:35:13 +02:00
parent 6d6cf3ffda
commit a65b990a49

View file

@ -4,6 +4,8 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.transport.CredentialsProvider
import org.eclipse.jgit.transport.RefSpec
import org.eclipse.jgit.transport.RemoteConfig
import javax.inject.Inject
class FetchAllBranchesUseCase @Inject constructor(
@ -13,9 +15,14 @@ class FetchAllBranchesUseCase @Inject constructor(
val remotes = git.remoteList().call()
for (remote in remotes) {
val refSpecs = remote.fetchRefSpecs.ifEmpty {
listOf(RefSpec("refs/heads/*:refs/remotes/${remote.name}/*"))
}
git.fetch()
.setRemote(remote.name)
.setRefSpecs(remote.fetchRefSpecs)
.setRefSpecs(refSpecs)
.setRemoveDeletedRefs(true)
.setTransportConfigCallback { handleTransportUseCase(it, git) }
.setCredentialsProvider(CredentialsProvider.getDefault())
.call()