From f530e487c746dceebaa11847d212fbc8fbeb5acb Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Mon, 11 Dec 2023 19:41:34 +0100 Subject: [PATCH] Adapted code to latest kotlin features & fixed typos --- README.md | 2 +- .../UncommitedChangesDetectedException.kt | 3 -- .../UncommittedChangesDetectedException.kt | 3 ++ .../com/jetpackduba/gitnuro/git/CloneState.kt | 12 +++--- .../jetpackduba/gitnuro/git/DiffEntryType.kt | 14 +++---- .../jetpackduba/gitnuro/git/RawFileManager.kt | 18 ++++----- .../com/jetpackduba/gitnuro/git/TabState.kt | 4 +- .../git/branches/MergeBranchUseCase.kt | 4 +- .../gitnuro/git/diff/FormatDiffUseCase.kt | 8 ++-- ... GetDiffEntryForUncommittedDiffUseCase.kt} | 4 +- .../gitnuro/git/graph/GraphCommitList.kt | 10 ++--- ...Node.kt => UncommittedChangesGraphNode.kt} | 4 +- .../gitnuro/git/log/GetLogUseCase.kt | 6 +-- .../gitnuro/git/log/RevertCommitUseCase.kt | 2 +- .../gitnuro/git/rebase/RebaseBranchUseCase.kt | 4 +- .../rebase/ResumeRebaseInteractiveUseCase.kt | 8 ++-- .../rebase/StartRebaseInteractiveUseCase.kt | 8 ++-- .../remote_operations/PullBranchUseCase.kt | 2 +- .../PullFromSpecificBranchUseCase.kt | 2 +- ...t => CheckHasUncommittedChangesUseCase.kt} | 2 +- .../com/jetpackduba/gitnuro/ui/Blame.kt | 2 +- .../jetpackduba/gitnuro/ui/CommitChanges.kt | 5 +-- .../jetpackduba/gitnuro/ui/RepositoryOpen.kt | 13 +++---- .../gitnuro/ui/UncommitedChanges.kt | 12 +++--- .../CommitedChangesEntriesContextMenu.kt | 2 +- .../ui/dialogs/settings/SettingsDialog.kt | 6 +-- .../com/jetpackduba/gitnuro/ui/diff/Diff.kt | 12 +++--- .../com/jetpackduba/gitnuro/ui/log/Log.kt | 24 ++++++------ .../jetpackduba/gitnuro/ui/log/LogDialog.kt | 12 +++--- .../viewmodels/CommitChangesViewModel.kt | 6 +-- .../gitnuro/viewmodels/DiffViewModel.kt | 4 +- .../gitnuro/viewmodels/LogViewModel.kt | 38 +++++++++---------- .../gitnuro/viewmodels/SettingsViewModel.kt | 2 +- .../gitnuro/viewmodels/StatusViewModel.kt | 34 +++++------------ .../gitnuro/viewmodels/TabViewModel.kt | 8 ++-- 35 files changed, 139 insertions(+), 161 deletions(-) delete mode 100644 src/main/kotlin/com/jetpackduba/gitnuro/exceptions/UncommitedChangesDetectedException.kt create mode 100644 src/main/kotlin/com/jetpackduba/gitnuro/exceptions/UncommittedChangesDetectedException.kt rename src/main/kotlin/com/jetpackduba/gitnuro/git/diff/{GetDiffEntryForUncommitedDiffUseCase.kt => GetDiffEntryForUncommittedDiffUseCase.kt} (93%) rename src/main/kotlin/com/jetpackduba/gitnuro/git/graph/{UncommitedChangesGraphNode.kt => UncommittedChangesGraphNode.kt} (64%) rename src/main/kotlin/com/jetpackduba/gitnuro/git/workspace/{CheckHasUncommitedChangesUseCase.kt => CheckHasUncommittedChangesUseCase.kt} (88%) diff --git a/README.md b/README.md index dab1cdb..d7579da 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Gitnuro has support for the following features: - View your history log and all its branches. - Add (stage) & reset (unstage) files. - Stage & unstage of hunks. -- Checkout files (revert changes of uncommited files). +- Checkout files (revert changes of uncommitted files). - Clone. - Commit. - Reset commits. diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/exceptions/UncommitedChangesDetectedException.kt b/src/main/kotlin/com/jetpackduba/gitnuro/exceptions/UncommitedChangesDetectedException.kt deleted file mode 100644 index 0611e66..0000000 --- a/src/main/kotlin/com/jetpackduba/gitnuro/exceptions/UncommitedChangesDetectedException.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.jetpackduba.gitnuro.exceptions - -class UncommitedChangesDetectedException(msg: String) : GitnuroException(msg) \ No newline at end of file diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/exceptions/UncommittedChangesDetectedException.kt b/src/main/kotlin/com/jetpackduba/gitnuro/exceptions/UncommittedChangesDetectedException.kt new file mode 100644 index 0000000..cc74092 --- /dev/null +++ b/src/main/kotlin/com/jetpackduba/gitnuro/exceptions/UncommittedChangesDetectedException.kt @@ -0,0 +1,3 @@ +package com.jetpackduba.gitnuro.exceptions + +class UncommittedChangesDetectedException(msg: String) : GitnuroException(msg) \ No newline at end of file diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/CloneState.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/CloneState.kt index 518ca89..561fae6 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/CloneState.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/CloneState.kt @@ -3,12 +3,12 @@ package com.jetpackduba.gitnuro.git import org.eclipse.jgit.transport.RemoteRefUpdate import java.io.File -sealed class CloneState { - object None : CloneState() - data class Cloning(val taskName: String, val progress: Int, val total: Int) : CloneState() - object Cancelling : CloneState() - data class Fail(val reason: String) : CloneState() - data class Completed(val repoDir: File) : CloneState() +sealed interface CloneState { + data object None : CloneState + data class Cloning(val taskName: String, val progress: Int, val total: Int) : CloneState + data object Cancelling : CloneState + data class Fail(val reason: String) : CloneState + data class Completed(val repoDir: File) : CloneState } val RemoteRefUpdate.Status.isRejected: Boolean diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/DiffEntryType.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/DiffEntryType.kt index d05e01e..bc823fe 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/DiffEntryType.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/DiffEntryType.kt @@ -6,8 +6,8 @@ import com.jetpackduba.gitnuro.git.workspace.StatusEntry import com.jetpackduba.gitnuro.git.workspace.StatusType import org.eclipse.jgit.diff.DiffEntry -sealed class DiffEntryType { - class CommitDiff(val diffEntry: DiffEntry) : DiffEntryType() { +sealed interface DiffEntryType { + class CommitDiff(val diffEntry: DiffEntry) : DiffEntryType { override val filePath: String get() = diffEntry.filePath @@ -15,7 +15,7 @@ sealed class DiffEntryType { get() = diffEntry.toStatusType() } - sealed class UncommitedDiff(val statusEntry: StatusEntry) : DiffEntryType() { + sealed class UncommittedDiff(val statusEntry: StatusEntry) : DiffEntryType { override val filePath: String get() = statusEntry.filePath @@ -23,8 +23,8 @@ sealed class DiffEntryType { get() = statusEntry.statusType } - sealed class UnstagedDiff(statusEntry: StatusEntry) : UncommitedDiff(statusEntry) - sealed class StagedDiff(statusEntry: StatusEntry) : UncommitedDiff(statusEntry) + sealed class UnstagedDiff(statusEntry: StatusEntry) : UncommittedDiff(statusEntry) + sealed class StagedDiff(statusEntry: StatusEntry) : UncommittedDiff(statusEntry) /** * State used to represent staged changes when the repository state is not [org.eclipse.jgit.lib.RepositoryState.SAFE] @@ -39,7 +39,7 @@ sealed class DiffEntryType { class SafeStagedDiff(statusEntry: StatusEntry) : StagedDiff(statusEntry) class SafeUnstagedDiff(statusEntry: StatusEntry) : UnstagedDiff(statusEntry) - abstract val filePath: String - abstract val statusType: StatusType + val filePath: String + val statusType: StatusType } diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/RawFileManager.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/RawFileManager.kt index abe8236..16940b6 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/RawFileManager.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/RawFileManager.kt @@ -108,13 +108,13 @@ class RawFileManager @Inject constructor( } } -sealed class EntryContent { - object Missing : EntryContent() - object InvalidObjectBlob : EntryContent() - data class Text(val rawText: RawText) : EntryContent() - object Submodule : EntryContent() - sealed class BinaryContent : EntryContent() - data class ImageBinary(val imagePath: String, val contentType: String) : BinaryContent() - object Binary : BinaryContent() - object TooLargeEntry : EntryContent() +sealed interface EntryContent { + data object Missing : EntryContent + data object InvalidObjectBlob : EntryContent + data class Text(val rawText: RawText) : EntryContent + data object Submodule : EntryContent + sealed interface BinaryContent : EntryContent + data class ImageBinary(val imagePath: String, val contentType: String) : BinaryContent + data object Binary : BinaryContent + data object TooLargeEntry : EntryContent } \ No newline at end of file diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/TabState.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/TabState.kt index 7e6e844..54bb08a 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/TabState.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/TabState.kt @@ -23,7 +23,7 @@ interface ProcessingInfo { } sealed interface ProcessingState { - object None : ProcessingState + data object None : ProcessingState data class Processing( val title: String, val subtitle: String, @@ -37,7 +37,7 @@ class TabState @Inject constructor( private val scope: CoroutineScope, private val findCommitUseCase: FindCommitUseCase, ) { - private val _selectedItem = MutableStateFlow(SelectedItem.UncommitedChanges) + private val _selectedItem = MutableStateFlow(SelectedItem.UncommittedChanges) val selectedItem: StateFlow = _selectedItem private val _taskEvent = MutableSharedFlow() val taskEvent: SharedFlow = _taskEvent diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/branches/MergeBranchUseCase.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/branches/MergeBranchUseCase.kt index ae9276b..e6ad1c6 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/branches/MergeBranchUseCase.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/branches/MergeBranchUseCase.kt @@ -1,6 +1,6 @@ package com.jetpackduba.gitnuro.git.branches -import com.jetpackduba.gitnuro.exceptions.UncommitedChangesDetectedException +import com.jetpackduba.gitnuro.exceptions.UncommittedChangesDetectedException import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.eclipse.jgit.api.Git @@ -23,7 +23,7 @@ class MergeBranchUseCase @Inject constructor() { .call() if (mergeResult.mergeStatus == MergeResult.MergeStatus.FAILED) { - throw UncommitedChangesDetectedException("Merge failed, makes sure you repository doesn't contain uncommited changes.") + throw UncommittedChangesDetectedException("Merge failed, makes sure you repository doesn't contain uncommitted changes.") } } } \ No newline at end of file diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/diff/FormatDiffUseCase.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/diff/FormatDiffUseCase.kt index 609397e..15ad311 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/diff/FormatDiffUseCase.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/diff/FormatDiffUseCase.kt @@ -10,8 +10,6 @@ import org.eclipse.jgit.api.Git import org.eclipse.jgit.diff.DiffEntry import org.eclipse.jgit.diff.DiffFormatter import org.eclipse.jgit.dircache.DirCacheIterator -import org.eclipse.jgit.submodule.SubmoduleStatus -import org.eclipse.jgit.submodule.SubmoduleStatusType import org.eclipse.jgit.treewalk.FileTreeIterator import java.io.ByteArrayOutputStream import java.io.InvalidObjectException @@ -21,7 +19,7 @@ class FormatDiffUseCase @Inject constructor( private val formatHunksUseCase: FormatHunksUseCase, private val getDiffContentUseCase: GetDiffContentUseCase, private val canGenerateTextDiffUseCase: CanGenerateTextDiffUseCase, - private val getDiffEntryForUncommitedDiffUseCase: GetDiffEntryForUncommitedDiffUseCase, + private val getDiffEntryForUncommittedDiffUseCase: GetDiffEntryForUncommittedDiffUseCase, private val getSubmodulesUseCase: GetSubmodulesUseCase, ) { suspend operator fun invoke( @@ -48,8 +46,8 @@ class FormatDiffUseCase @Inject constructor( diffEntryType.diffEntry } - is DiffEntryType.UncommitedDiff -> { - getDiffEntryForUncommitedDiffUseCase(git, diffEntryType) + is DiffEntryType.UncommittedDiff -> { + getDiffEntryForUncommittedDiffUseCase(git, diffEntryType) } } diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/diff/GetDiffEntryForUncommitedDiffUseCase.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/diff/GetDiffEntryForUncommittedDiffUseCase.kt similarity index 93% rename from src/main/kotlin/com/jetpackduba/gitnuro/git/diff/GetDiffEntryForUncommitedDiffUseCase.kt rename to src/main/kotlin/com/jetpackduba/gitnuro/git/diff/GetDiffEntryForUncommittedDiffUseCase.kt index c77194b..77e4dc7 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/diff/GetDiffEntryForUncommitedDiffUseCase.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/diff/GetDiffEntryForUncommittedDiffUseCase.kt @@ -12,13 +12,13 @@ import org.eclipse.jgit.treewalk.EmptyTreeIterator import org.eclipse.jgit.treewalk.filter.PathFilter import javax.inject.Inject -class GetDiffEntryForUncommitedDiffUseCase @Inject constructor( +class GetDiffEntryForUncommittedDiffUseCase @Inject constructor( private val getRepositoryStateUseCase: GetRepositoryStateUseCase, private val getCurrentBranchUseCase: GetCurrentBranchUseCase, ) { suspend operator fun invoke( git: Git, - diffEntryType: DiffEntryType.UncommitedDiff, + diffEntryType: DiffEntryType.UncommittedDiff, ) = withContext(Dispatchers.IO) { val statusEntry = diffEntryType.statusEntry val cached = diffEntryType is DiffEntryType.StagedDiff diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/graph/GraphCommitList.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/graph/GraphCommitList.kt index 240ff77..8cbb8b2 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/graph/GraphCommitList.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/graph/GraphCommitList.kt @@ -55,19 +55,19 @@ class GraphCommitList : RevCommitList() { private var parentId: AnyObjectId? = null - private val graphCommit = UncommitedChangesGraphNode() + private val graphCommit = UncommittedChangesGraphNode() - fun addUncommitedChangesGraphCommit(parent: RevCommit) { + fun addUncommittedChangesGraphCommit(parent: RevCommit) { parentId = parent.id graphCommit.lane = nextFreeLane() } override fun enter(index: Int, currCommit: GraphNode) { - var isUncommitedChangesNodeParent = false + var isUncommittedChangesNodeParent = false if (currCommit.id == parentId) { graphCommit.graphParent = currCommit currCommit.addChild(graphCommit, addFirst = true) - isUncommitedChangesNodeParent = true + isUncommittedChangesNodeParent = true } setupChildren(currCommit) @@ -104,7 +104,7 @@ class GraphCommitList : RevCommitList() { var lengthOfReservedLane = -1 - if (isUncommitedChangesNodeParent) { + if (isUncommittedChangesNodeParent) { val length = laneLength[graphCommit.lane] if (length != null) { reservedLane = graphCommit.lane diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/graph/UncommitedChangesGraphNode.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/graph/UncommittedChangesGraphNode.kt similarity index 64% rename from src/main/kotlin/com/jetpackduba/gitnuro/git/graph/UncommitedChangesGraphNode.kt rename to src/main/kotlin/com/jetpackduba/gitnuro/git/graph/UncommittedChangesGraphNode.kt index 2df3c2a..916abf5 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/graph/UncommitedChangesGraphNode.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/graph/UncommittedChangesGraphNode.kt @@ -2,12 +2,12 @@ package com.jetpackduba.gitnuro.git.graph import org.eclipse.jgit.lib.ObjectId -class UncommitedChangesGraphNode : GraphNode(ObjectId(0, 0, 0, 0, 0)) { +class UncommittedChangesGraphNode : GraphNode(ObjectId(0, 0, 0, 0, 0)) { var graphParent: GraphNode? = null override val graphParentCount: Int - get() = 1 // Uncommited changes can have a max of 1 parent commit + get() = 1 // Uncommitted changes can have a max of 1 parent commit override fun getGraphParent(nth: Int): GraphNode { return requireNotNull(graphParent) diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/log/GetLogUseCase.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/log/GetLogUseCase.kt index 90bdd71..44b02b3 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/log/GetLogUseCase.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/log/GetLogUseCase.kt @@ -15,7 +15,7 @@ import javax.inject.Inject class GetLogUseCase @Inject constructor() { private var graphWalkCached: GraphWalk? = null - suspend operator fun invoke(git: Git, currentBranch: Ref?, hasUncommitedChanges: Boolean, commitsLimit: Int) = + suspend operator fun invoke(git: Git, currentBranch: Ref?, hasUncommittedChanges: Boolean, commitsLimit: Int) = withContext(Dispatchers.IO) { val commitList = GraphCommitList() val repositoryState = git.repository.repositoryState @@ -35,8 +35,8 @@ class GetLogUseCase @Inject constructor() { walk.markStartAllRefs(Constants.R_TAGS) walk.markStartAllRefs(Constants.R_STASH) - if (hasUncommitedChanges) - commitList.addUncommitedChangesGraphCommit(logList.first()) + if (hasUncommittedChanges) + commitList.addUncommittedChangesGraphCommit(logList.first()) commitList.source(walk) commitList.fillTo(commitsLimit) diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/log/RevertCommitUseCase.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/log/RevertCommitUseCase.kt index 0b76660..958b92c 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/log/RevertCommitUseCase.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/log/RevertCommitUseCase.kt @@ -19,7 +19,7 @@ class RevertCommitUseCase @Inject constructor() { val failingResult: MergeResult? = revertCommand.failingResult when (failingResult?.mergeStatus) { - MergeResult.MergeStatus.FAILED -> throw RevertCommitException("Revert failed. Clear your workspace from uncommited changes.") + MergeResult.MergeStatus.FAILED -> throw RevertCommitException("Revert failed. Clear your workspace from uncommitted changes.") MergeResult.MergeStatus.CONFLICTING -> throw RevertCommitException("Revert failed. Fix the conflicts and commit the desired changes.") MergeResult.MergeStatus.ABORTED -> throw RevertCommitException("Revert aborted.") else -> {} diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/rebase/RebaseBranchUseCase.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/rebase/RebaseBranchUseCase.kt index fd7b4bf..7f29d18 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/rebase/RebaseBranchUseCase.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/rebase/RebaseBranchUseCase.kt @@ -1,6 +1,6 @@ package com.jetpackduba.gitnuro.git.rebase -import com.jetpackduba.gitnuro.exceptions.UncommitedChangesDetectedException +import com.jetpackduba.gitnuro.exceptions.UncommittedChangesDetectedException import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.eclipse.jgit.api.Git @@ -17,7 +17,7 @@ class RebaseBranchUseCase @Inject constructor() { .call() if (rebaseResult.status == RebaseResult.Status.UNCOMMITTED_CHANGES) { - throw UncommitedChangesDetectedException("Rebase failed, the repository contains uncommited changes.") + throw UncommittedChangesDetectedException("Rebase failed, the repository contains uncommitted changes.") } } } \ No newline at end of file diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/rebase/ResumeRebaseInteractiveUseCase.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/rebase/ResumeRebaseInteractiveUseCase.kt index ab55595..61b3e7f 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/rebase/ResumeRebaseInteractiveUseCase.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/rebase/ResumeRebaseInteractiveUseCase.kt @@ -1,6 +1,6 @@ package com.jetpackduba.gitnuro.git.rebase -import com.jetpackduba.gitnuro.exceptions.UncommitedChangesDetectedException +import com.jetpackduba.gitnuro.exceptions.UncommittedChangesDetectedException import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.eclipse.jgit.api.Git @@ -18,9 +18,9 @@ class ResumeRebaseInteractiveUseCase @Inject constructor() { when (rebaseResult.status) { - RebaseResult.Status.FAILED -> throw UncommitedChangesDetectedException("Rebase interactive failed.") - RebaseResult.Status.UNCOMMITTED_CHANGES, RebaseResult.Status.CONFLICTS -> throw UncommitedChangesDetectedException( - "You can't have uncommited changes before starting a rebase interactive" + RebaseResult.Status.FAILED -> throw UncommittedChangesDetectedException("Rebase interactive failed.") + RebaseResult.Status.UNCOMMITTED_CHANGES, RebaseResult.Status.CONFLICTS -> throw UncommittedChangesDetectedException( + "You can't have uncommitted changes before starting a rebase interactive" ) else -> {} diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/rebase/StartRebaseInteractiveUseCase.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/rebase/StartRebaseInteractiveUseCase.kt index e850d8c..7cd2ed8 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/rebase/StartRebaseInteractiveUseCase.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/rebase/StartRebaseInteractiveUseCase.kt @@ -1,6 +1,6 @@ package com.jetpackduba.gitnuro.git.rebase -import com.jetpackduba.gitnuro.exceptions.UncommitedChangesDetectedException +import com.jetpackduba.gitnuro.exceptions.UncommittedChangesDetectedException import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.eclipse.jgit.api.Git @@ -29,9 +29,9 @@ class StartRebaseInteractiveUseCase @Inject constructor() { .call() when (rebaseResult.status) { - RebaseResult.Status.FAILED -> throw UncommitedChangesDetectedException("Rebase interactive failed.") - RebaseResult.Status.UNCOMMITTED_CHANGES, RebaseResult.Status.CONFLICTS -> throw UncommitedChangesDetectedException( - "You can't have uncommited changes before starting a rebase interactive" + RebaseResult.Status.FAILED -> throw UncommittedChangesDetectedException("Rebase interactive failed.") + RebaseResult.Status.UNCOMMITTED_CHANGES, RebaseResult.Status.CONFLICTS -> throw UncommittedChangesDetectedException( + "You can't have uncommitted changes before starting a rebase interactive" ) else -> {} diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/remote_operations/PullBranchUseCase.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/remote_operations/PullBranchUseCase.kt index 20d1dcb..6ccbb8e 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/remote_operations/PullBranchUseCase.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/remote_operations/PullBranchUseCase.kt @@ -33,7 +33,7 @@ class PullBranchUseCase @Inject constructor( if (pullWithRebase) { message = when (pullResult.rebaseResult.status) { - RebaseResult.Status.UNCOMMITTED_CHANGES -> "The pull with rebase has failed because you have got uncommited changes" + RebaseResult.Status.UNCOMMITTED_CHANGES -> "The pull with rebase has failed because you have got uncommitted changes" RebaseResult.Status.CONFLICTS -> "Pull with rebase has conflicts, fix them to continue" else -> message } diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/remote_operations/PullFromSpecificBranchUseCase.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/remote_operations/PullFromSpecificBranchUseCase.kt index f86647f..52a71ba 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/remote_operations/PullFromSpecificBranchUseCase.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/remote_operations/PullFromSpecificBranchUseCase.kt @@ -30,7 +30,7 @@ class PullFromSpecificBranchUseCase @Inject constructor( if (rebase) { message = when (pullResult.rebaseResult.status) { - RebaseResult.Status.UNCOMMITTED_CHANGES -> "The pull with rebase has failed because you have got uncommited changes" + RebaseResult.Status.UNCOMMITTED_CHANGES -> "The pull with rebase has failed because you have got uncommitted changes" RebaseResult.Status.CONFLICTS -> "Pull with rebase has conflicts, fix them to continue" else -> message } diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/workspace/CheckHasUncommitedChangesUseCase.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/workspace/CheckHasUncommittedChangesUseCase.kt similarity index 88% rename from src/main/kotlin/com/jetpackduba/gitnuro/git/workspace/CheckHasUncommitedChangesUseCase.kt rename to src/main/kotlin/com/jetpackduba/gitnuro/git/workspace/CheckHasUncommittedChangesUseCase.kt index 16f2b37..abe5116 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/workspace/CheckHasUncommitedChangesUseCase.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/workspace/CheckHasUncommittedChangesUseCase.kt @@ -6,7 +6,7 @@ import kotlinx.coroutines.withContext import org.eclipse.jgit.api.Git import javax.inject.Inject -class CheckHasUncommitedChangesUseCase @Inject constructor() { +class CheckHasUncommittedChangesUseCase @Inject constructor() { suspend operator fun invoke(git: Git) = withContext(Dispatchers.IO) { val status = git .status() diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ui/Blame.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ui/Blame.kt index 63b1e1e..928a913 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ui/Blame.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ui/Blame.kt @@ -107,7 +107,7 @@ fun Blame( style = MaterialTheme.typography.body2, ) Text( - text = commit?.shortMessage ?: "Uncommited change", + text = commit?.shortMessage ?: "Uncommitted change", style = MaterialTheme.typography.caption, maxLines = 1, modifier = Modifier.padding(start = 16.dp), diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ui/CommitChanges.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ui/CommitChanges.kt index c664746..293eb68 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ui/CommitChanges.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ui/CommitChanges.kt @@ -26,13 +26,12 @@ import com.jetpackduba.gitnuro.git.DiffEntryType import com.jetpackduba.gitnuro.theme.* import com.jetpackduba.gitnuro.ui.components.* import com.jetpackduba.gitnuro.ui.context_menu.ContextMenu -import com.jetpackduba.gitnuro.ui.context_menu.commitedChangesEntriesContextMenuItems +import com.jetpackduba.gitnuro.ui.context_menu.committedChangesEntriesContextMenuItems import com.jetpackduba.gitnuro.viewmodels.CommitChangesState import com.jetpackduba.gitnuro.viewmodels.CommitChangesViewModel import kotlinx.coroutines.delay import kotlinx.coroutines.launch import org.eclipse.jgit.diff.DiffEntry -import org.eclipse.jgit.lib.ObjectId import org.eclipse.jgit.lib.PersonIdent import org.eclipse.jgit.revwalk.RevCommit @@ -314,7 +313,7 @@ fun CommitLogChanges( items(items = diffEntries) { diffEntry -> ContextMenu( items = { - commitedChangesEntriesContextMenuItems( + committedChangesEntriesContextMenuItems( diffEntry, onBlame = { onBlame(diffEntry.filePath) }, onHistory = { onHistory(diffEntry.filePath) }, diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ui/RepositoryOpen.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ui/RepositoryOpen.kt index 326a327..76c8eec 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ui/RepositoryOpen.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ui/RepositoryOpen.kt @@ -30,7 +30,6 @@ import com.jetpackduba.gitnuro.ui.diff.Diff import com.jetpackduba.gitnuro.ui.log.Log import com.jetpackduba.gitnuro.viewmodels.BlameState import com.jetpackduba.gitnuro.viewmodels.TabViewModel -import org.eclipse.jgit.lib.Ref import org.eclipse.jgit.lib.RepositoryState import org.eclipse.jgit.revwalk.RevCommit import org.jetbrains.compose.splitpane.ExperimentalSplitPaneApi @@ -338,8 +337,8 @@ fun MainContentView( .fillMaxHeight() ) { when (selectedItem) { - SelectedItem.UncommitedChanges -> { - UncommitedChanges( + SelectedItem.UncommittedChanges -> { + UncommittedChanges( selectedEntryType = diffSelected, repositoryState = repositoryState, onStagedDiffEntrySelected = { diffEntry -> @@ -410,10 +409,10 @@ fun SplitterScope.repositorySplitter() { } } -sealed class SelectedItem { - object None : SelectedItem() - object UncommitedChanges : SelectedItem() - sealed class CommitBasedItem(val revCommit: RevCommit) : SelectedItem() +sealed interface SelectedItem { + data object None : SelectedItem + data object UncommittedChanges : SelectedItem + sealed class CommitBasedItem(val revCommit: RevCommit) : SelectedItem class Ref(val ref: org.eclipse.jgit.lib.Ref, revCommit: RevCommit) : CommitBasedItem(revCommit) class Commit(revCommit: RevCommit) : CommitBasedItem(revCommit) class Stash(revCommit: RevCommit) : CommitBasedItem(revCommit) diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ui/UncommitedChanges.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ui/UncommitedChanges.kt index 698d38c..4d15979 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ui/UncommitedChanges.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ui/UncommitedChanges.kt @@ -51,7 +51,7 @@ import com.jetpackduba.gitnuro.viewmodels.StatusViewModel import org.eclipse.jgit.lib.RepositoryState @Composable -fun UncommitedChanges( +fun UncommittedChanges( statusViewModel: StatusViewModel = gitnuroViewModel(), selectedEntryType: DiffEntryType?, repositoryState: RepositoryState, @@ -61,7 +61,7 @@ fun UncommitedChanges( onHistoryFile: (String) -> Unit, ) { val stageStatus = statusViewModel.stageState.collectAsState().value - val swapUncommitedChanges by statusViewModel.swapUncommitedChanges.collectAsState() + val swapUncommittedChanges by statusViewModel.swapUncommittedChanges.collectAsState() var commitMessage by remember(statusViewModel) { mutableStateOf(statusViewModel.savedCommitMessage.message) } val stagedListState by statusViewModel.stagedLazyListState.collectAsState() val unstagedListState by statusViewModel.unstagedLazyListState.collectAsState() @@ -221,7 +221,7 @@ fun UncommitedChanges( ) } - if (swapUncommitedChanges) { + if (swapUncommittedChanges) { unstagedView() stagedView() } else { @@ -319,7 +319,7 @@ fun UncommitedChanges( } ) - else -> UncommitedChangesButtons( + else -> UncommittedChangesButtons( canCommit = canCommit, canAmend = canAmend, isAmend = isAmend, @@ -335,7 +335,7 @@ fun UncommitedChanges( } @Composable -fun UncommitedChangesButtons( +fun UncommittedChangesButtons( canCommit: Boolean, canAmend: Boolean, isAmend: Boolean, @@ -678,7 +678,7 @@ private fun EntriesList( ) { items(statusEntries, key = { it.filePath }) { statusEntry -> val isEntrySelected = selectedEntryType != null && - selectedEntryType is DiffEntryType.UncommitedDiff && // Added for smartcast + selectedEntryType is DiffEntryType.UncommittedDiff && // Added for smartcast selectedEntryType.statusEntry == statusEntry FileEntry( statusEntry = statusEntry, diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ui/context_menu/CommitedChangesEntriesContextMenu.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ui/context_menu/CommitedChangesEntriesContextMenu.kt index 54e1c0c..251d465 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ui/context_menu/CommitedChangesEntriesContextMenu.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ui/context_menu/CommitedChangesEntriesContextMenu.kt @@ -6,7 +6,7 @@ import com.jetpackduba.gitnuro.AppIcons import org.eclipse.jgit.diff.DiffEntry @OptIn(ExperimentalFoundationApi::class) -fun commitedChangesEntriesContextMenuItems( +fun committedChangesEntriesContextMenuItems( diffEntry: DiffEntry, onBlame: () -> Unit, onHistory: () -> Unit, diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ui/dialogs/settings/SettingsDialog.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ui/dialogs/settings/SettingsDialog.kt index 61c93e9..7004a57 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ui/dialogs/settings/SettingsDialog.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ui/dialogs/settings/SettingsDialog.kt @@ -402,14 +402,14 @@ private fun Branches(settingsViewModel: SettingsViewModel) { @Composable private fun Layout(settingsViewModel: SettingsViewModel) { - val swapUncommitedChanges by settingsViewModel.swapUncommittedChangesFlow.collectAsState() + val swapUncommittedChanges by settingsViewModel.swapUncommittedChangesFlow.collectAsState() SettingToggle( title = "Swap position for staged/unstaged views", subtitle = "Show the list of unstaged changes above the list of staged changes", - value = swapUncommitedChanges, + value = swapUncommittedChanges, onValueChanged = { value -> - settingsViewModel.swapUncommitedChanges = value + settingsViewModel.swapUncommittedChanges = value } ) } diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ui/diff/Diff.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ui/diff/Diff.kt index 8ea8d42..fa1cabc 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ui/diff/Diff.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ui/diff/Diff.kt @@ -798,7 +798,7 @@ fun HunkHeader( // Hunks options are only visible when repository is a normal state (not during merge/rebase) if ( (diffEntryType is DiffEntryType.SafeStagedDiff || diffEntryType is DiffEntryType.SafeUnstagedDiff) && - (diffEntryType is DiffEntryType.UncommitedDiff && // Added just to make smartcast work + (diffEntryType is DiffEntryType.UncommittedDiff && // Added just to make smartcast work diffEntryType.statusEntry.statusType == StatusType.MODIFIED) ) { val buttonText: String @@ -914,8 +914,8 @@ private fun DiffHeader( ) } - if (diffEntryType is DiffEntryType.UncommitedDiff) { - UncommitedDiffFileHeaderButtons( + if (diffEntryType is DiffEntryType.UncommittedDiff) { + UncommittedDiffFileHeaderButtons( diffEntryType, onUnstageFile = onUnstageFile, onStageFile = onStageFile @@ -1020,8 +1020,8 @@ fun DiffTypeButtons( } @Composable -fun UncommitedDiffFileHeaderButtons( - diffEntryType: DiffEntryType.UncommitedDiff, +fun UncommittedDiffFileHeaderButtons( + diffEntryType: DiffEntryType.UncommittedDiff, onUnstageFile: (StatusEntry) -> Unit, onStageFile: (StatusEntry) -> Unit ) { @@ -1167,7 +1167,7 @@ fun DiffLineText(line: Line, diffEntryType: DiffEntryType, onActionTriggered: () val isHovered by hoverInteraction.collectIsHoveredAsState() Box(modifier = Modifier.hoverable(hoverInteraction)) { - if (isHovered && diffEntryType is DiffEntryType.UncommitedDiff && line.lineType != LineType.CONTEXT) { + if (isHovered && diffEntryType is DiffEntryType.UncommittedDiff && line.lineType != LineType.CONTEXT) { val color: Color = if (diffEntryType is DiffEntryType.StagedDiff) { MaterialTheme.colors.error } else { diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ui/log/Log.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ui/log/Log.kt index 21c2417..a24ac89 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ui/log/Log.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ui/log/Log.kt @@ -28,7 +28,6 @@ import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.graphics.drawscope.clipRect import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.input.key.onPreviewKeyEvent -import androidx.compose.ui.input.pointer.PointerIcon import androidx.compose.ui.input.pointer.pointerHoverIcon import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.painterResource @@ -59,7 +58,6 @@ import kotlinx.coroutines.launch import org.eclipse.jgit.lib.Ref import org.eclipse.jgit.lib.RepositoryState import org.eclipse.jgit.revwalk.RevCommit -import java.awt.Cursor private val colors = listOf( Color(0xFF42a5f5), @@ -151,8 +149,8 @@ private fun LogLoaded( } } launch { - logViewModel.scrollToUncommitedChanges.collect { - scrollToUncommitedChanges(verticalScrollState, commitList) + logViewModel.scrollToUncommittedChanges.collect { + scrollToUncommittedChanges(verticalScrollState, commitList) } } } @@ -318,7 +316,7 @@ suspend fun scrollToCommit( if (index >= 0) verticalScrollState.scrollToItem(index) } -suspend fun scrollToUncommitedChanges( +suspend fun scrollToUncommittedChanges( verticalScrollState: LazyListState, commitList: GraphCommitList, ) { @@ -459,17 +457,17 @@ fun MessagesList( modifier = Modifier.height(LINE_HEIGHT.dp) .clipToBounds() .fillMaxWidth() - .clickable { logViewModel.selectUncommitedChanges() } + .clickable { logViewModel.selectUncommittedChanges() } ) { - UncommitedChangesGraphNode( + UncommittedChangesGraphNode( hasPreviousCommits = commitList.isNotEmpty(), - isSelected = selectedItem is SelectedItem.UncommitedChanges, + isSelected = selectedItem is SelectedItem.UncommittedChanges, modifier = Modifier.offset(-horizontalScrollState.value.dp) ) - UncommitedChangesLine( + UncommittedChangesLine( graphWidth = graphWidth, - isSelected = selectedItem == SelectedItem.UncommitedChanges, + isSelected = selectedItem == SelectedItem.UncommittedChanges, statusSummary = logStatus.statusSummary, repositoryState = repositoryState, ) @@ -630,7 +628,7 @@ fun GraphHeader( } @Composable -fun UncommitedChangesLine( +fun UncommittedChangesLine( graphWidth: Dp, isSelected: Boolean, repositoryState: RepositoryState, @@ -649,7 +647,7 @@ fun UncommitedChangesLine( repositoryState.isMerging -> "Pending changes to merge" repositoryState.isCherryPicking -> "Pending changes to cherry-pick" repositoryState.isReverting -> "Pending changes to revert" - else -> "Uncommited changes" + else -> "Uncommitted changes" } Text( @@ -1078,7 +1076,7 @@ fun CommitNode( } @Composable -fun UncommitedChangesGraphNode( +fun UncommittedChangesGraphNode( modifier: Modifier = Modifier, hasPreviousCommits: Boolean, isSelected: Boolean, diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ui/log/LogDialog.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ui/log/LogDialog.kt index 5fd6410..0118de2 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ui/log/LogDialog.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ui/log/LogDialog.kt @@ -3,10 +3,10 @@ package com.jetpackduba.gitnuro.ui.log import com.jetpackduba.gitnuro.git.graph.GraphNode import org.eclipse.jgit.lib.Ref -sealed class LogDialog { - object None : LogDialog() - data class NewBranch(val graphNode: GraphNode) : LogDialog() - data class NewTag(val graphNode: GraphNode) : LogDialog() - data class ResetBranch(val graphNode: GraphNode) : LogDialog() - data class ChangeDefaultBranch(val ref: Ref) : LogDialog() +sealed interface LogDialog { + data object None : LogDialog + data class NewBranch(val graphNode: GraphNode) : LogDialog + data class NewTag(val graphNode: GraphNode) : LogDialog + data class ResetBranch(val graphNode: GraphNode) : LogDialog + data class ChangeDefaultBranch(val ref: Ref) : LogDialog } \ No newline at end of file diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/CommitChangesViewModel.kt b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/CommitChangesViewModel.kt index 10b84aa..81f262a 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/CommitChangesViewModel.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/CommitChangesViewModel.kt @@ -115,9 +115,9 @@ class CommitChangesViewModel @Inject constructor( } } -sealed class CommitChangesState { - object Loading : CommitChangesState() +sealed interface CommitChangesState { + data object Loading : CommitChangesState data class Loaded(val commit: RevCommit, val changes: List, val changesFiltered: List) : - CommitChangesState() + CommitChangesState } diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/DiffViewModel.kt b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/DiffViewModel.kt index 7461aee..11fa94c 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/DiffViewModel.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/DiffViewModel.kt @@ -106,8 +106,8 @@ class DiffViewModel @Inject constructor( // If it's a different file or different state (index or workdir), reset the scroll state if ( oldDiffEntryType?.filePath != diffEntryType.filePath || - oldDiffEntryType is DiffEntryType.UncommitedDiff && - diffEntryType is DiffEntryType.UncommitedDiff && + oldDiffEntryType is DiffEntryType.UncommittedDiff && + diffEntryType is DiffEntryType.UncommittedDiff && oldDiffEntryType.statusEntry.filePath == diffEntryType.statusEntry.filePath && oldDiffEntryType::class != diffEntryType::class ) { diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/LogViewModel.kt b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/LogViewModel.kt index 224b083..8aa2255 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/LogViewModel.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/LogViewModel.kt @@ -19,7 +19,7 @@ import com.jetpackduba.gitnuro.git.remote_operations.PullFromSpecificBranchUseCa import com.jetpackduba.gitnuro.git.remote_operations.PushToSpecificBranchUseCase import com.jetpackduba.gitnuro.git.tags.CreateTagOnCommitUseCase import com.jetpackduba.gitnuro.git.tags.DeleteTagUseCase -import com.jetpackduba.gitnuro.git.workspace.CheckHasUncommitedChangesUseCase +import com.jetpackduba.gitnuro.git.workspace.CheckHasUncommittedChangesUseCase import com.jetpackduba.gitnuro.git.workspace.GetStatusSummaryUseCase import com.jetpackduba.gitnuro.git.workspace.StatusSummary import com.jetpackduba.gitnuro.preferences.AppSettings @@ -50,7 +50,7 @@ private const val LOG_MIN_TIME_IN_MS_TO_SHOW_LOAD = 500L class LogViewModel @Inject constructor( private val getLogUseCase: GetLogUseCase, private val getStatusSummaryUseCase: GetStatusSummaryUseCase, - private val checkHasUncommittedChangesUseCase: CheckHasUncommitedChangesUseCase, + private val checkHasUncommittedChangesUseCase: CheckHasUncommittedChangesUseCase, private val getCurrentBranchUseCase: GetCurrentBranchUseCase, private val checkoutRefUseCase: CheckoutRefUseCase, private val createBranchOnCommitUseCase: CreateBranchOnCommitUseCase, @@ -86,7 +86,7 @@ class LogViewModel @Inject constructor( .filterIsInstance() .map { it.revCommit } - val scrollToUncommitedChanges: Flow = tabState.taskEvent + val scrollToUncommittedChanges: Flow = tabState.taskEvent .filterIsInstance() .map { it.selectedItem } .filterIsInstance() @@ -123,7 +123,7 @@ class LogViewModel @Inject constructor( RefreshType.UNCOMMITTED_CHANGES_AND_LOG, ) { refreshType -> if (refreshType == RefreshType.UNCOMMITTED_CHANGES) { - uncommitedChangesLoadLog(tabState.git) + uncommittedChangesLoadLog(tabState.git) } else refresh(tabState.git) } @@ -143,7 +143,7 @@ class LogViewModel @Inject constructor( git = git, ) - val hasUncommitedChanges = statusSummary.total > 0 + val hasUncommittedChanges = statusSummary.total > 0 val commitsLimit = if (appSettings.commitsLimitEnabled) { appSettings.commitsLimit } else @@ -154,10 +154,10 @@ class LogViewModel @Inject constructor( } else -1 - val log = getLogUseCase(git, currentBranch, hasUncommitedChanges, commitsLimit) + val log = getLogUseCase(git, currentBranch, hasUncommittedChanges, commitsLimit) _logStatus.value = - LogStatus.Loaded(hasUncommitedChanges, log, currentBranch, statusSummary, commitsLimitDisplayed) + LogStatus.Loaded(hasUncommittedChanges, log, currentBranch, statusSummary, commitsLimitDisplayed) // Remove search filter if the log has been updated _logSearchFilterResults.value = LogSearch.NotSearching @@ -271,11 +271,11 @@ class LogViewModel @Inject constructor( deleteTagUseCase(git, tag) } - private suspend fun uncommitedChangesLoadLog(git: Git) { + private suspend fun uncommittedChangesLoadLog(git: Git) { val currentBranch = getCurrentBranchUseCase(git) - val hasUncommitedChanges = checkHasUncommittedChangesUseCase(git) + val hasUncommittedChanges = checkHasUncommittedChangesUseCase(git) - val statsSummary = if (hasUncommitedChanges) { + val statsSummary = if (hasUncommittedChanges) { getStatusSummaryUseCase( git = git, ) @@ -286,7 +286,7 @@ class LogViewModel @Inject constructor( if (previousLogStatusValue is LogStatus.Loaded) { val newLogStatusValue = LogStatus.Loaded( - hasUncommittedChanges = hasUncommitedChanges, + hasUncommittedChanges = hasUncommittedChanges, plotCommitList = previousLogStatusValue.plotCommitList, currentBranch = currentBranch, statusSummary = statsSummary, @@ -309,10 +309,10 @@ class LogViewModel @Inject constructor( rebaseBranchUseCase(git, ref) } - fun selectUncommitedChanges() = tabState.runOperation( + fun selectUncommittedChanges() = tabState.runOperation( refreshType = RefreshType.NONE, ) { - tabState.newSelectedItem(SelectedItem.UncommitedChanges) + tabState.newSelectedItem(SelectedItem.UncommittedChanges) val searchValue = _logSearchFilterResults.value if (searchValue is LogSearch.SearchResults) { @@ -445,22 +445,22 @@ class LogViewModel @Inject constructor( } } -sealed class LogStatus { - data object Loading : LogStatus() +sealed interface LogStatus { + data object Loading : LogStatus class Loaded( val hasUncommittedChanges: Boolean, val plotCommitList: GraphCommitList, val currentBranch: Ref?, val statusSummary: StatusSummary, val commitsLimit: Int, - ) : LogStatus() + ) : LogStatus } -sealed class LogSearch { - data object NotSearching : LogSearch() +sealed interface LogSearch { + data object NotSearching : LogSearch data class SearchResults( val commits: List, val index: Int, val totalCount: Int = commits.count(), - ) : LogSearch() + ) : LogSearch } diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/SettingsViewModel.kt b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/SettingsViewModel.kt index 2aedbb8..7799f22 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/SettingsViewModel.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/SettingsViewModel.kt @@ -44,7 +44,7 @@ class SettingsViewModel @Inject constructor( appSettings.commitsLimitEnabled = value } - var swapUncommitedChanges: Boolean + var swapUncommittedChanges: Boolean get() = appSettings.swapUncommittedChanges set(value) { appSettings.swapUncommittedChanges = value diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/StatusViewModel.kt b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/StatusViewModel.kt index d5035a5..3e2e762 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/StatusViewModel.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/StatusViewModel.kt @@ -49,7 +49,7 @@ class StatusViewModel @Inject constructor( private val getStatusUseCase: GetStatusUseCase, private val getStagedUseCase: GetStagedUseCase, private val getUnstagedUseCase: GetUnstagedUseCase, - private val checkHasUncommitedChangesUseCase: CheckHasUncommitedChangesUseCase, + private val checkHasUncommittedChangesUseCase: CheckHasUncommittedChangesUseCase, private val doCommitUseCase: DoCommitUseCase, private val loadAuthorUseCase: LoadAuthorUseCase, private val saveAuthorUseCase: SaveAuthorUseCase, @@ -72,7 +72,7 @@ class StatusViewModel @Inject constructor( private val _searchFilterStaged = MutableStateFlow(TextFieldValue("")) val searchFilterStaged: StateFlow = _searchFilterStaged - val swapUncommitedChanges = appSettings.swapUncommittedChangesFlow + val swapUncommittedChanges = appSettings.swapUncommittedChangesFlow val rebaseInteractiveState = sharedRepositoryStateManager.rebaseInteractiveState private val _stageState = MutableStateFlow(StageState.Loading) @@ -128,7 +128,7 @@ class StatusViewModel @Inject constructor( var hasPreviousCommits = true // When false, disable "amend previous commit" - private var lastUncommitedChangesState = false + private var lastUncommittedChangesState = false val stagedLazyListState = MutableStateFlow(LazyListState(0, 0)) val unstagedLazyListState = MutableStateFlow(LazyListState(0, 0)) @@ -276,8 +276,8 @@ class StatusViewModel @Inject constructor( return message.orEmpty().replace("\t", " ") } - private suspend fun loadHasUncommitedChanges(git: Git) = withContext(Dispatchers.IO) { - lastUncommitedChangesState = checkHasUncommitedChangesUseCase(git) + private suspend fun loadHasUncommittedChanges(git: Git) = withContext(Dispatchers.IO) { + lastUncommittedChangesState = checkHasUncommittedChangesUseCase(git) } fun amend(isAmend: Boolean) { @@ -346,23 +346,7 @@ class StatusViewModel @Inject constructor( suspend fun refresh(git: Git) = withContext(Dispatchers.IO) { loadStatus(git) - loadHasUncommitedChanges(git) - } - - /** - * Checks if there are uncommited changes and returns if the state has changed ( - */ - suspend fun updateHasUncommitedChanges(git: Git): Boolean { - val hadUncommitedChanges = this.lastUncommitedChangesState - - loadStatus(git) - loadHasUncommitedChanges(git) - - val hasNowUncommitedChanges = this.lastUncommitedChangesState - hasPreviousCommits = checkHasPreviousCommitsUseCase(git) - - // Return true to update the log only if the uncommitedChanges status has changed - return (hasNowUncommitedChanges != hadUncommitedChanges) + loadHasUncommittedChanges(git) } fun continueRebase(message: String) = tabState.safeProcessing( @@ -469,15 +453,15 @@ class StatusViewModel @Inject constructor( } } -sealed class StageState { - object Loading : StageState() +sealed interface StageState { + data object Loading : StageState data class Loaded( val staged: List, val stagedFiltered: List, val unstaged: List, val unstagedFiltered: List, val isPartiallyReloading: Boolean - ) : StageState() + ) : StageState } data class CommitMessage(val message: String, val messageType: MessageType) diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt index 276b587..2938c37 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt @@ -169,7 +169,7 @@ class TabViewModel @Inject constructor( directory.absolutePath onRepositoryChanged(path) - tabState.newSelectedItem(selectedItem = SelectedItem.UncommitedChanges) + tabState.newSelectedItem(selectedItem = SelectedItem.UncommittedChanges) newDiffSelected = null refreshRepositoryInfo() @@ -272,11 +272,11 @@ class TabViewModel @Inject constructor( } else { printLog(TAG, "Changes detected, partial refresh") - checkUncommitedChanges() + checkUncommittedChanges() } } - private suspend fun checkUncommitedChanges() = tabState.runOperation( + private suspend fun checkUncommittedChanges() = tabState.runOperation( refreshType = RefreshType.NONE, ) { updateDiffEntry() @@ -445,5 +445,5 @@ sealed interface BlameState { data class Loaded(val filePath: String, val blameResult: BlameResult, val isMinimized: Boolean = false) : BlameState - object None : BlameState + data object None : BlameState } \ No newline at end of file