From 2dd6fb106e4c7f5b72e9212f86c165a2397cf4a9 Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Thu, 31 Mar 2022 22:09:59 +0200 Subject: [PATCH] Filtered out uninitialized submodules from git diff --- src/main/kotlin/app/git/StatusManager.kt | 8 +++++++- src/main/kotlin/app/git/SubmodulesManager.kt | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/app/git/SubmodulesManager.kt diff --git a/src/main/kotlin/app/git/StatusManager.kt b/src/main/kotlin/app/git/StatusManager.kt index 998aa8f..8746fe1 100644 --- a/src/main/kotlin/app/git/StatusManager.kt +++ b/src/main/kotlin/app/git/StatusManager.kt @@ -19,6 +19,7 @@ import org.eclipse.jgit.diff.RawText import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit import org.eclipse.jgit.dircache.DirCacheEntry import org.eclipse.jgit.lib.* +import org.eclipse.jgit.submodule.SubmoduleStatusType import org.eclipse.jgit.treewalk.EmptyTreeIterator import java.io.ByteArrayInputStream import java.io.IOException @@ -29,6 +30,7 @@ import javax.inject.Inject class StatusManager @Inject constructor( private val rawFileManagerFactory: RawFileManagerFactory, + private val submodulesManager: SubmodulesManager, ) { suspend fun hasUncommitedChanges(git: Git) = withContext(Dispatchers.IO) { val status = git @@ -259,10 +261,14 @@ class StatusManager @Inject constructor( } suspend fun getUnstaged(git: Git, repositoryState: RepositoryState) = withContext(Dispatchers.IO) { + val uninitializedSubmodules = submodulesManager.uninitializedSubmodules(git) + return@withContext git .diff() - .setShowNameAndStatusOnly(true) .call() + .filter { + !uninitializedSubmodules.containsKey(it.oldPath) // Filter out uninitialized modules directories + } .groupBy { if (it.oldPath != "/dev/null") it.oldPath diff --git a/src/main/kotlin/app/git/SubmodulesManager.kt b/src/main/kotlin/app/git/SubmodulesManager.kt new file mode 100644 index 0000000..f0af74e --- /dev/null +++ b/src/main/kotlin/app/git/SubmodulesManager.kt @@ -0,0 +1,18 @@ +package app.git + +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +import org.eclipse.jgit.api.Git +import org.eclipse.jgit.submodule.SubmoduleStatusType +import javax.inject.Inject + +class SubmodulesManager @Inject constructor() { + suspend fun uninitializedSubmodules(git: Git) = withContext(Dispatchers.IO) { + return@withContext git + .submoduleStatus() + .call() + .filter { + it.value.type == SubmoduleStatusType.UNINITIALIZED + } + } +} \ No newline at end of file