Skip to content

Commit

Permalink
Adapted code to latest kotlin features & fixed typos
Browse files Browse the repository at this point in the history
  • Loading branch information
JetpackDuba committed Dec 11, 2023
1 parent c2e69d0 commit f530e48
Show file tree
Hide file tree
Showing 35 changed files with 139 additions and 161 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.jetpackduba.gitnuro.exceptions

class UncommittedChangesDetectedException(msg: String) : GitnuroException(msg)
12 changes: 6 additions & 6 deletions src/main/kotlin/com/jetpackduba/gitnuro/git/CloneState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/main/kotlin/com/jetpackduba/gitnuro/git/DiffEntryType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ 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

override val statusType: StatusType
get() = diffEntry.toStatusType()
}

sealed class UncommitedDiff(val statusEntry: StatusEntry) : DiffEntryType() {
sealed class UncommittedDiff(val statusEntry: StatusEntry) : DiffEntryType {
override val filePath: String
get() = statusEntry.filePath

override val statusType: StatusType
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]
Expand All @@ -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

}
18 changes: 9 additions & 9 deletions src/main/kotlin/com/jetpackduba/gitnuro/git/RawFileManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions src/main/kotlin/com/jetpackduba/gitnuro/git/TabState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -37,7 +37,7 @@ class TabState @Inject constructor(
private val scope: CoroutineScope,
private val findCommitUseCase: FindCommitUseCase,
) {
private val _selectedItem = MutableStateFlow<SelectedItem>(SelectedItem.UncommitedChanges)
private val _selectedItem = MutableStateFlow<SelectedItem>(SelectedItem.UncommittedChanges)
val selectedItem: StateFlow<SelectedItem> = _selectedItem
private val _taskEvent = MutableSharedFlow<TaskEvent>()
val taskEvent: SharedFlow<TaskEvent> = _taskEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -48,8 +46,8 @@ class FormatDiffUseCase @Inject constructor(
diffEntryType.diffEntry
}

is DiffEntryType.UncommitedDiff -> {
getDiffEntryForUncommitedDiffUseCase(git, diffEntryType)
is DiffEntryType.UncommittedDiff -> {
getDiffEntryForUncommittedDiffUseCase(git, diffEntryType)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ class GraphCommitList : RevCommitList<GraphNode>() {

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)
Expand Down Expand Up @@ -104,7 +104,7 @@ class GraphCommitList : RevCommitList<GraphNode>() {
var lengthOfReservedLane = -1


if (isUncommitedChangesNodeParent) {
if (isUncommittedChangesNodeParent) {
val length = laneLength[graphCommit.lane]
if (length != null) {
reservedLane = graphCommit.lane
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.")
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 -> {}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 -> {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/jetpackduba/gitnuro/ui/Blame.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
5 changes: 2 additions & 3 deletions src/main/kotlin/com/jetpackduba/gitnuro/ui/CommitChanges.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -314,7 +313,7 @@ fun CommitLogChanges(
items(items = diffEntries) { diffEntry ->
ContextMenu(
items = {
commitedChangesEntriesContextMenuItems(
committedChangesEntriesContextMenuItems(
diffEntry,
onBlame = { onBlame(diffEntry.filePath) },
onHistory = { onHistory(diffEntry.filePath) },
Expand Down
Loading

0 comments on commit f530e48

Please sign in to comment.