Skip to content

Commit

Permalink
Added positive feedback for all the required operations
Browse files Browse the repository at this point in the history
  • Loading branch information
JetpackDuba committed Jul 9, 2024
1 parent 2a226e9 commit f5fcaf9
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/com/jetpackduba/gitnuro/git/TabState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class TabState @Inject constructor(
title: String = "",
subtitle: String = "",
taskType: TaskType,
positiveFeedbackText: String? = null,
positiveFeedbackText: String?,
// TODO For now have it always as false because the data refresh is cancelled even when the git process couldn't be cancelled
isCancellable: Boolean = false,
refreshEvenIfCrashes: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class HistoryViewModel @Inject constructor(
title = "History",
subtitle = "Loading file history",
taskType = TaskType.HISTORY_FILE,
positiveFeedbackText = null,
) { git ->
this@HistoryViewModel.filePath = filePath
_historyState.value = HistoryState.Loading(filePath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class LogViewModel @Inject constructor(
title = "Commit checkout",
subtitle = "Checking out commit ${revCommit.name}",
taskType = TaskType.CHECKOUT_COMMIT,
positiveFeedbackText = "Commit checked out",
) { git ->
checkoutCommitUseCase(git, revCommit)
}
Expand All @@ -173,6 +174,7 @@ class LogViewModel @Inject constructor(
subtitle = "Reverting commit ${revCommit.name}",
refreshEvenIfCrashes = true,
taskType = TaskType.REVERT_COMMIT,
positiveFeedbackText = "Commit reverted",
) { git ->
revertCommitUseCase(git, revCommit)
}
Expand All @@ -182,6 +184,7 @@ class LogViewModel @Inject constructor(
title = "Branch reset",
subtitle = "Resetting branch to commit ${revCommit.shortName}",
taskType = TaskType.RESET_TO_COMMIT,
positiveFeedbackText = "Reset completed",
) { git ->
resetToCommitUseCase(git, revCommit, resetType = resetType)
}
Expand All @@ -192,6 +195,7 @@ class LogViewModel @Inject constructor(
subtitle = "Cherry-picking commit ${revCommit.shortName}",
taskType = TaskType.CHERRY_PICK_COMMIT,
refreshEvenIfCrashes = true,
positiveFeedbackText = "Commit cherry-picked"
) { git ->
cherryPickCommitUseCase(git, revCommit)
}
Expand All @@ -202,6 +206,7 @@ class LogViewModel @Inject constructor(
subtitle = "Creating new branch \"$branch\" on commit ${revCommit.shortName}",
refreshEvenIfCrashesInteractive = { it is CheckoutConflictException },
taskType = TaskType.CREATE_BRANCH,
positiveFeedbackText = "Branch \"$branch\" created",
) { git ->
createBranchOnCommitUseCase(git, branch, revCommit)
}
Expand All @@ -211,6 +216,7 @@ class LogViewModel @Inject constructor(
title = "New tag",
subtitle = "Creating new tag \"$tag\" on commit ${revCommit.shortName}",
taskType = TaskType.CREATE_TAG,
positiveFeedbackText = "Tag created",
) { git ->
createTagOnCommitUseCase(git, tag, revCommit)
}
Expand Down Expand Up @@ -369,6 +375,7 @@ class LogViewModel @Inject constructor(
fun rebaseInteractive(revCommit: RevCommit) = tabState.safeProcessing(
refreshType = RefreshType.REBASE_INTERACTIVE_STATE,
taskType = TaskType.REBASE_INTERACTIVE,
positiveFeedbackText = null,
) { git ->
startRebaseInteractiveUseCase(git, revCommit)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MenuViewModel @Inject constructor(
refreshType = RefreshType.ALL_DATA,
title = "Pulling",
subtitle = "Pulling changes from the remote branch to the current branch",
positiveFeedbackText = "Pull completed successfully",
positiveFeedbackText = "Pull completed",
refreshEvenIfCrashes = true,
taskType = TaskType.PULL,
) { git ->
Expand All @@ -48,6 +48,7 @@ class MenuViewModel @Inject constructor(
isCancellable = false,
refreshEvenIfCrashes = true,
taskType = TaskType.FETCH,
positiveFeedbackText = "Fetch all completed",
) { git ->
fetchAllBranchesUseCase(git)
}
Expand All @@ -59,14 +60,15 @@ class MenuViewModel @Inject constructor(
isCancellable = false,
refreshEvenIfCrashes = true,
taskType = TaskType.PUSH,
positiveFeedbackText = "Push completed",
) { git ->
pushBranchUseCase(git, force, pushTags)
}

fun stash() = tabState.safeProcessing(
refreshType = RefreshType.UNCOMMITTED_CHANGES_AND_LOG,
taskType = TaskType.STASH,
positiveFeedbackText = "Changes have been stashed",
positiveFeedbackText = "Changes stashed",
) { git ->
stashChangesUseCase(git, null)
}
Expand All @@ -75,6 +77,7 @@ class MenuViewModel @Inject constructor(
refreshType = RefreshType.UNCOMMITTED_CHANGES_AND_LOG,
refreshEvenIfCrashes = true,
taskType = TaskType.POP_STASH,
positiveFeedbackText = "Stash popped",
) { git ->
popLastStashUseCase(git)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class RebaseInteractiveViewModel @Inject constructor(
fun loadRebaseInteractiveData() = tabState.safeProcessing(
refreshType = RefreshType.NONE,
taskType = TaskType.REBASE_INTERACTIVE,// TODO Perhaps this should be more specific such as TaskType.LOAD_ABORT_REBASE
positiveFeedbackText = null,
) { git ->
val state = getRepositoryStateUseCase(git)

Expand Down Expand Up @@ -125,6 +126,7 @@ class RebaseInteractiveViewModel @Inject constructor(
fun continueRebaseInteractive() = tabState.safeProcessing(
refreshType = RefreshType.ALL_DATA,
taskType = TaskType.REBASE_INTERACTIVE, // TODO Perhaps be more precise with the task type
positiveFeedbackText = null,
) { git ->
resumeRebaseInteractiveUseCase(git, interactiveHandlerContinue)
_rebaseState.value = RebaseInteractiveViewState.Loading
Expand Down Expand Up @@ -179,6 +181,7 @@ class RebaseInteractiveViewModel @Inject constructor(
fun selectLine(line: RebaseLine) = tabState.safeProcessing(
refreshType = RefreshType.NONE,
taskType = TaskType.ABORT_REBASE, // TODO Perhaps be more precise with the task type
positiveFeedbackText = null,
) { git ->
val fullCommit = getCommitFromRebaseLineUseCase(git, line.commit, line.shortMessage)
tabState.newSelectedCommit(fullCommit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class SharedBranchesViewModel @Inject constructor(
title = "Branch merge",
subtitle = "Merging branch ${ref.simpleName}",
taskType = TaskType.MERGE_BRANCH,
positiveFeedbackText = "Merged from \"${ref.simpleName}\"",
) { git ->
mergeBranchUseCase(git, ref, appSettingsRepository.ffMerge)
}
Expand All @@ -43,6 +44,7 @@ class SharedBranchesViewModel @Inject constructor(
title = "Branch delete",
subtitle = "Deleting branch ${branch.simpleName}",
taskType = TaskType.DELETE_BRANCH,
positiveFeedbackText = "\"${branch.simpleName}\" deleted",
) { git ->
deleteBranchUseCase(git, branch)
}
Expand All @@ -52,6 +54,7 @@ class SharedBranchesViewModel @Inject constructor(
title = "Branch checkout",
subtitle = "Checking out branch ${ref.simpleName}",
taskType = TaskType.CHECKOUT_BRANCH,
positiveFeedbackText = "\"${ref.simpleName}\" checked out",
) { git ->
checkoutRefUseCase(git, ref)
}
Expand All @@ -61,6 +64,7 @@ class SharedBranchesViewModel @Inject constructor(
title = "Branch rebase",
subtitle = "Rebasing branch ${ref.simpleName}",
taskType = TaskType.REBASE_BRANCH,
positiveFeedbackText = "\"${ref.simpleName}\" rebased",
) { git ->
rebaseBranchUseCase(git, ref)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ class SharedRemotesViewModel @Inject constructor(
title = "Deleting remote branch",
subtitle = "Remote branch ${ref.simpleName} will be deleted from the remote",
taskType = TaskType.DELETE_REMOTE_BRANCH,
positiveFeedbackText = "Remote branch \"${ref.simpleName}\" deleted",
) { git ->
deleteRemoteBranchUseCase(git, ref)
}

override fun checkoutRemoteBranch(remoteBranch: Ref) = tabState.safeProcessing(
refreshType = RefreshType.ALL_DATA,
taskType = TaskType.CHECKOUT_REMOTE_BRANCH,
positiveFeedbackText = "\"${remoteBranch.simpleName}\" checked out",
) { git ->
checkoutRefUseCase(git, remoteBranch)
}
Expand All @@ -47,6 +49,7 @@ class SharedRemotesViewModel @Inject constructor(
title = "Push",
subtitle = "Pushing current branch to ${branch.simpleName}",
taskType = TaskType.PUSH_TO_BRANCH,
positiveFeedbackText = "Pushed to \"${branch.simpleName}\"",
) { git ->
pushToSpecificBranchUseCase(
git = git,
Expand All @@ -61,6 +64,7 @@ class SharedRemotesViewModel @Inject constructor(
title = "Pull",
subtitle = "Pulling changes from ${branch.simpleName} to the current branch",
taskType = TaskType.PULL_FROM_BRANCH,
positiveFeedbackText = "Pulled from \"${branch.simpleName}\"",
) { git ->
pullFromSpecificBranchUseCase(
git = git,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class SharedStashViewModel @Inject constructor(
refreshType = RefreshType.UNCOMMITTED_CHANGES_AND_LOG,
refreshEvenIfCrashes = true,
taskType = TaskType.APPLY_STASH,
positiveFeedbackText = "Stash applied",
) { git ->
applyStashUseCase(git, stashInfo)
}
Expand All @@ -37,6 +38,7 @@ class SharedStashViewModel @Inject constructor(
refreshType = RefreshType.UNCOMMITTED_CHANGES_AND_LOG,
refreshEvenIfCrashes = true,
taskType = TaskType.POP_STASH,
positiveFeedbackText = "Stash popped",
) { git ->
popStashUseCase(git, stash)

Expand All @@ -46,6 +48,7 @@ class SharedStashViewModel @Inject constructor(
override fun deleteStash(stash: RevCommit) = tabState.safeProcessing(
refreshType = RefreshType.STASHES,
taskType = TaskType.DELETE_STASH,
positiveFeedbackText = "Stash deleted",
) { git ->
deleteStashUseCase(git, stash)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class SharedTagsViewModel @Inject constructor(
title = "Tag delete",
subtitle = "Deleting tag ${tag.simpleName}",
taskType = TaskType.DELETE_TAG,
positiveFeedbackText = "Tag \"${tag.simpleName}\" deleted",
) { git ->
deleteTagUseCase(git, tag)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,15 @@ class StatusViewModel @Inject constructor(
fun unstageAll() = tabState.safeProcessing(
refreshType = RefreshType.UNCOMMITTED_CHANGES,
taskType = TaskType.UNSTAGE_ALL_FILES,
positiveFeedbackText = null,
) { git ->
unstageAllUseCase(git)
}

fun stageAll() = tabState.safeProcessing(
refreshType = RefreshType.UNCOMMITTED_CHANGES,
taskType = TaskType.STAGE_ALL_FILES,
positiveFeedbackText = null,
) { git ->
stageAllUseCase(git)
}
Expand Down Expand Up @@ -347,6 +349,7 @@ class StatusViewModel @Inject constructor(
fun commit(message: String) = tabState.safeProcessing(
refreshType = RefreshType.ALL_DATA,
taskType = TaskType.DO_COMMIT,
positiveFeedbackText = "New commit added",
) { git ->
val amend = isAmend.value

Expand Down Expand Up @@ -401,6 +404,7 @@ class StatusViewModel @Inject constructor(
fun continueRebase(message: String) = tabState.safeProcessing(
refreshType = RefreshType.ALL_DATA,
taskType = TaskType.CONTINUE_REBASE,
positiveFeedbackText = null,
) { git ->
val repositoryState = sharedRepositoryStateManager.repositoryState.value
val rebaseInteractiveState = sharedRepositoryStateManager.rebaseInteractiveState.value
Expand All @@ -424,20 +428,23 @@ class StatusViewModel @Inject constructor(
fun abortRebase() = tabState.safeProcessing(
refreshType = RefreshType.ALL_DATA,
taskType = TaskType.ABORT_REBASE,
positiveFeedbackText = "Rebase aborted",
) { git ->
abortRebaseUseCase(git)
}

fun skipRebase() = tabState.safeProcessing(
refreshType = RefreshType.ALL_DATA,
taskType = TaskType.SKIP_REBASE,
positiveFeedbackText = null,
) { git ->
skipRebaseUseCase(git)
}

fun resetRepoState() = tabState.safeProcessing(
refreshType = RefreshType.ALL_DATA,
taskType = TaskType.RESET_REPO_STATE,
positiveFeedbackText = "Repository state has been reset",
) { git ->
resetRepositoryStateUseCase(git)
}
Expand Down
48 changes: 25 additions & 23 deletions src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import org.eclipse.jgit.blame.BlameResult
import org.eclipse.jgit.lib.Repository
import org.eclipse.jgit.lib.RepositoryState
import org.eclipse.jgit.revwalk.RevCommit
import uniffi.gitnuro.WatcherInitException
import java.awt.Desktop
import java.io.File
import javax.inject.Inject
Expand Down Expand Up @@ -252,31 +251,31 @@ class TabViewModel @Inject constructor(
}
}

try {
// try {
fileChangesWatcher.watchDirectoryPath(
repository = git.repository,
)
} catch (ex: WatcherInitException) {
val message = when (ex) {
is WatcherInitException.Generic -> ex.error
is WatcherInitException.InvalidConfig -> "Invalid configuration"
is WatcherInitException.Io -> ex.error
is WatcherInitException.MaxFilesWatch -> "Reached the limit of files that can be watched. Please increase the system inotify limit to be able to detect the changes on this repository."
is WatcherInitException.PathNotFound -> "Path not found, check if your repository still exists"
is WatcherInitException.WatchNotFound -> null // This should never trigger as we don't unwatch files
}

if (message != null) {
errorsManager.addError(
newErrorNow(
exception = ex,
taskType = TaskType.CHANGES_DETECTION,
// title = "Repository changes detection has stopped working",
// message = message,
),
)
}
}
// } catch (ex: WatcherInitException) {
// val message = when (ex) {
// is WatcherInitException.Generic -> ex.error
// is WatcherInitException.InvalidConfig -> "Invalid configuration"
// is WatcherInitException.Io -> ex.error
// is WatcherInitException.MaxFilesWatch -> "Reached the limit of files that can be watched. Please increase the system inotify limit to be able to detect the changes on this repository."
// is WatcherInitException.PathNotFound -> "Path not found, check if your repository still exists"
// is WatcherInitException.WatchNotFound -> null // This should never trigger as we don't unwatch files
// }
//
// if (message != null) {
// errorsManager.addError(
// newErrorNow(
// exception = ex,
// taskType = TaskType.CHANGES_DETECTION,
//// title = "Repository changes detection has stopped working",
//// message = message,
// ),
// )
// }
// }
}

private suspend fun updateApp(hasGitDirChanged: Boolean) {
Expand Down Expand Up @@ -355,6 +354,7 @@ class TabViewModel @Inject constructor(
fun blameFile(filePath: String) = tabState.safeProcessing(
refreshType = RefreshType.NONE,
taskType = TaskType.BLAME_FILE,
positiveFeedbackText = null,
) { git ->
_blameState.value = BlameState.Loading(filePath)
try {
Expand Down Expand Up @@ -419,13 +419,15 @@ class TabViewModel @Inject constructor(
refreshType = RefreshType.ALL_DATA,
refreshEvenIfCrashesInteractive = { it is CheckoutConflictException },
taskType = TaskType.CREATE_BRANCH,
positiveFeedbackText = "Branch \"${branchName}\" created",
) { git ->
createBranchUseCase(git, branchName)
}

fun stashWithMessage(message: String) = tabState.safeProcessing(
refreshType = RefreshType.UNCOMMITTED_CHANGES_AND_LOG,
taskType = TaskType.STASH,
positiveFeedbackText = "Changes stashed",
) { git ->
stageUntrackedFileUseCase(git)
stashChangesUseCase(git, message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class RemotesViewModel @AssistedInject constructor(
fun deleteRemote(remoteName: String, isNew: Boolean) = tabState.safeProcessing(
refreshType = if (isNew) RefreshType.REMOTES else RefreshType.ALL_DATA,
taskType = TaskType.DELETE_REMOTE,
positiveFeedbackText = "Remote $remoteName deleted",
) { git ->
deleteRemoteUseCase(git, remoteName)

Expand Down
Loading

0 comments on commit f5fcaf9

Please sign in to comment.