Fixed diff on index files when a repository is empty
This commit is contained in:
parent
685769a154
commit
5982c65c79
@ -4,6 +4,7 @@ import app.di.HunkDiffGeneratorFactory
|
|||||||
import app.di.RawFileManagerFactory
|
import app.di.RawFileManagerFactory
|
||||||
import app.exceptions.MissingDiffEntryException
|
import app.exceptions.MissingDiffEntryException
|
||||||
import app.extensions.fullData
|
import app.extensions.fullData
|
||||||
|
import app.extensions.isMerging
|
||||||
import app.git.diff.DiffResult
|
import app.git.diff.DiffResult
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@ -17,6 +18,7 @@ import org.eclipse.jgit.revwalk.RevTree
|
|||||||
import org.eclipse.jgit.revwalk.RevWalk
|
import org.eclipse.jgit.revwalk.RevWalk
|
||||||
import org.eclipse.jgit.treewalk.AbstractTreeIterator
|
import org.eclipse.jgit.treewalk.AbstractTreeIterator
|
||||||
import org.eclipse.jgit.treewalk.CanonicalTreeParser
|
import org.eclipse.jgit.treewalk.CanonicalTreeParser
|
||||||
|
import org.eclipse.jgit.treewalk.EmptyTreeIterator
|
||||||
import org.eclipse.jgit.treewalk.FileTreeIterator
|
import org.eclipse.jgit.treewalk.FileTreeIterator
|
||||||
import org.eclipse.jgit.treewalk.filter.PathFilter
|
import org.eclipse.jgit.treewalk.filter.PathFilter
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
@ -26,6 +28,8 @@ import javax.inject.Inject
|
|||||||
class DiffManager @Inject constructor(
|
class DiffManager @Inject constructor(
|
||||||
private val rawFileManagerFactory: RawFileManagerFactory,
|
private val rawFileManagerFactory: RawFileManagerFactory,
|
||||||
private val hunkDiffGeneratorFactory: HunkDiffGeneratorFactory,
|
private val hunkDiffGeneratorFactory: HunkDiffGeneratorFactory,
|
||||||
|
private val branchesManager: BranchesManager,
|
||||||
|
private val repositoryManager: RepositoryManager,
|
||||||
) {
|
) {
|
||||||
suspend fun diffFormat(git: Git, diffEntryType: DiffEntryType): DiffResult = withContext(Dispatchers.IO) {
|
suspend fun diffFormat(git: Git, diffEntryType: DiffEntryType): DiffResult = withContext(Dispatchers.IO) {
|
||||||
val byteArrayOutputStream = ByteArrayOutputStream()
|
val byteArrayOutputStream = ByteArrayOutputStream()
|
||||||
@ -47,10 +51,20 @@ class DiffManager @Inject constructor(
|
|||||||
}
|
}
|
||||||
is DiffEntryType.UncommitedDiff -> {
|
is DiffEntryType.UncommitedDiff -> {
|
||||||
val statusEntry = diffEntryType.statusEntry
|
val statusEntry = diffEntryType.statusEntry
|
||||||
|
val cached = diffEntryType is DiffEntryType.StagedDiff
|
||||||
val firstDiffEntry = git.diff()
|
val firstDiffEntry = git.diff()
|
||||||
.setPathFilter(PathFilter.create(statusEntry.filePath))
|
.setPathFilter(PathFilter.create(statusEntry.filePath))
|
||||||
.setCached(diffEntryType is DiffEntryType.StagedDiff)
|
.setCached(cached).apply {
|
||||||
|
val repositoryState = repositoryManager.getRepositoryState(git)
|
||||||
|
if (
|
||||||
|
branchesManager.currentBranchRef(git) == null &&
|
||||||
|
!repositoryState.isMerging &&
|
||||||
|
!repositoryState.isRebasing &&
|
||||||
|
cached
|
||||||
|
) {
|
||||||
|
setOldTree(EmptyTreeIterator()) // Required if the repository is empty
|
||||||
|
}
|
||||||
|
}
|
||||||
.call()
|
.call()
|
||||||
.firstOrNull()
|
.firstOrNull()
|
||||||
?: throw MissingDiffEntryException("Diff entry not found")
|
?: throw MissingDiffEntryException("Diff entry not found")
|
||||||
|
Loading…
Reference in New Issue
Block a user