parent
b62684e29d
commit
3a473142ae
@ -1,5 +1,6 @@
|
|||||||
package com.jetpackduba.gitnuro.git.remote_operations
|
package com.jetpackduba.gitnuro.git.remote_operations
|
||||||
|
|
||||||
|
import com.jetpackduba.gitnuro.preferences.AppSettings
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
@ -9,19 +10,26 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
class PullBranchUseCase @Inject constructor(
|
class PullBranchUseCase @Inject constructor(
|
||||||
private val handleTransportUseCase: HandleTransportUseCase,
|
private val handleTransportUseCase: HandleTransportUseCase,
|
||||||
|
private val appSettings: AppSettings,
|
||||||
) {
|
) {
|
||||||
suspend operator fun invoke(git: Git, rebase: Boolean) = withContext(Dispatchers.IO) {
|
suspend operator fun invoke(git: Git, pullType: PullType) = withContext(Dispatchers.IO) {
|
||||||
|
val pullWithRebase = when (pullType) {
|
||||||
|
PullType.REBASE -> true
|
||||||
|
PullType.MERGE -> false
|
||||||
|
PullType.DEFAULT -> appSettings.pullRebase
|
||||||
|
}
|
||||||
|
|
||||||
val pullResult = git
|
val pullResult = git
|
||||||
.pull()
|
.pull()
|
||||||
.setTransportConfigCallback { handleTransportUseCase(it, git) }
|
.setTransportConfigCallback { handleTransportUseCase(it, git) }
|
||||||
.setRebase(rebase)
|
.setRebase(pullWithRebase)
|
||||||
.setCredentialsProvider(CredentialsProvider.getDefault())
|
.setCredentialsProvider(CredentialsProvider.getDefault())
|
||||||
.call()
|
.call()
|
||||||
|
|
||||||
if (!pullResult.isSuccessful) {
|
if (!pullResult.isSuccessful) {
|
||||||
var message = "Pull failed"
|
var message = "Pull failed"
|
||||||
|
|
||||||
if (rebase) {
|
if (pullWithRebase) {
|
||||||
message = when (pullResult.rebaseResult.status) {
|
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 uncommited changes"
|
||||||
RebaseResult.Status.CONFLICTS -> "Pull with rebase has conflicts, fix them to continue"
|
RebaseResult.Status.CONFLICTS -> "Pull with rebase has conflicts, fix them to continue"
|
||||||
@ -32,4 +40,11 @@ class PullBranchUseCase @Inject constructor(
|
|||||||
throw Exception(message)
|
throw Exception(message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
enum class PullType {
|
||||||
|
REBASE,
|
||||||
|
MERGE,
|
||||||
|
DEFAULT
|
||||||
}
|
}
|
@ -30,6 +30,7 @@ private const val PREF_DIFF_TYPE = "diffType"
|
|||||||
|
|
||||||
|
|
||||||
private const val PREF_GIT_FF_MERGE = "gitFFMerge"
|
private const val PREF_GIT_FF_MERGE = "gitFFMerge"
|
||||||
|
private const val PREF_GIT_PULL_REBASE = "gitPullRebase"
|
||||||
|
|
||||||
private const val DEFAULT_COMMITS_LIMIT = 1000
|
private const val DEFAULT_COMMITS_LIMIT = 1000
|
||||||
private const val DEFAULT_COMMITS_LIMIT_ENABLED = true
|
private const val DEFAULT_COMMITS_LIMIT_ENABLED = true
|
||||||
@ -48,6 +49,9 @@ class AppSettings @Inject constructor() {
|
|||||||
private val _ffMergeFlow = MutableStateFlow(ffMerge)
|
private val _ffMergeFlow = MutableStateFlow(ffMerge)
|
||||||
val ffMergeFlow: StateFlow<Boolean> = _ffMergeFlow
|
val ffMergeFlow: StateFlow<Boolean> = _ffMergeFlow
|
||||||
|
|
||||||
|
private val _pullRebaseFlow = MutableStateFlow(pullRebase)
|
||||||
|
val pullRebaseFlow: StateFlow<Boolean> = _pullRebaseFlow
|
||||||
|
|
||||||
private val _commitsLimitFlow = MutableSharedFlow<Int>()
|
private val _commitsLimitFlow = MutableSharedFlow<Int>()
|
||||||
val commitsLimitFlow: SharedFlow<Int> = _commitsLimitFlow
|
val commitsLimitFlow: SharedFlow<Int> = _commitsLimitFlow
|
||||||
|
|
||||||
@ -117,6 +121,18 @@ class AppSettings @Inject constructor() {
|
|||||||
_ffMergeFlow.value = value
|
_ffMergeFlow.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property that decides if the merge should fast-forward when possible
|
||||||
|
*/
|
||||||
|
var pullRebase: Boolean
|
||||||
|
get() {
|
||||||
|
return preferences.getBoolean(PREF_GIT_PULL_REBASE, false)
|
||||||
|
}
|
||||||
|
set(value) {
|
||||||
|
preferences.putBoolean(PREF_GIT_PULL_REBASE, value)
|
||||||
|
_pullRebaseFlow.value = value
|
||||||
|
}
|
||||||
|
|
||||||
val commitsLimit: Int
|
val commitsLimit: Int
|
||||||
get() {
|
get() {
|
||||||
return preferences.getInt(PREF_COMMITS_LIMIT, DEFAULT_COMMITS_LIMIT)
|
return preferences.getInt(PREF_COMMITS_LIMIT, DEFAULT_COMMITS_LIMIT)
|
||||||
|
@ -22,6 +22,7 @@ import com.jetpackduba.gitnuro.AppIcons
|
|||||||
import com.jetpackduba.gitnuro.extensions.handMouseClickable
|
import com.jetpackduba.gitnuro.extensions.handMouseClickable
|
||||||
import com.jetpackduba.gitnuro.extensions.handOnHover
|
import com.jetpackduba.gitnuro.extensions.handOnHover
|
||||||
import com.jetpackduba.gitnuro.extensions.ignoreKeyEvents
|
import com.jetpackduba.gitnuro.extensions.ignoreKeyEvents
|
||||||
|
import com.jetpackduba.gitnuro.git.remote_operations.PullType
|
||||||
import com.jetpackduba.gitnuro.ui.components.gitnuroViewModel
|
import com.jetpackduba.gitnuro.ui.components.gitnuroViewModel
|
||||||
import com.jetpackduba.gitnuro.ui.context_menu.*
|
import com.jetpackduba.gitnuro.ui.context_menu.*
|
||||||
import com.jetpackduba.gitnuro.viewmodels.MenuViewModel
|
import com.jetpackduba.gitnuro.viewmodels.MenuViewModel
|
||||||
@ -37,6 +38,8 @@ fun Menu(
|
|||||||
onQuickActions: () -> Unit,
|
onQuickActions: () -> Unit,
|
||||||
onShowSettingsDialog: () -> Unit,
|
onShowSettingsDialog: () -> Unit,
|
||||||
) {
|
) {
|
||||||
|
val isPullWithRebaseDefault by menuViewModel.isPullWithRebaseDefault.collectAsState()
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
horizontalArrangement = Arrangement.Center,
|
horizontalArrangement = Arrangement.Center,
|
||||||
@ -56,10 +59,18 @@ fun Menu(
|
|||||||
modifier = Modifier.padding(end = 4.dp),
|
modifier = Modifier.padding(end = 4.dp),
|
||||||
title = "Pull",
|
title = "Pull",
|
||||||
icon = painterResource(AppIcons.DOWNLOAD),
|
icon = painterResource(AppIcons.DOWNLOAD),
|
||||||
onClick = { menuViewModel.pull() },
|
onClick = { menuViewModel.pull(PullType.DEFAULT) },
|
||||||
extendedListItems = pullContextMenuItems(
|
extendedListItems = pullContextMenuItems(
|
||||||
onPullRebase = {
|
isPullWithRebaseDefault = isPullWithRebaseDefault,
|
||||||
menuViewModel.pull(true)
|
onPullWith = {
|
||||||
|
// Do the reverse of the default
|
||||||
|
val pullType = if (isPullWithRebaseDefault) {
|
||||||
|
PullType.MERGE
|
||||||
|
} else {
|
||||||
|
PullType.REBASE
|
||||||
|
}
|
||||||
|
|
||||||
|
menuViewModel.pull(pullType = pullType)
|
||||||
},
|
},
|
||||||
onFetchAll = {
|
onFetchAll = {
|
||||||
menuViewModel.fetchAll()
|
menuViewModel.fetchAll()
|
||||||
|
@ -1,13 +1,20 @@
|
|||||||
package com.jetpackduba.gitnuro.ui.context_menu
|
package com.jetpackduba.gitnuro.ui.context_menu
|
||||||
|
|
||||||
fun pullContextMenuItems(
|
fun pullContextMenuItems(
|
||||||
onPullRebase: () -> Unit,
|
onPullWith: () -> Unit,
|
||||||
onFetchAll: () -> Unit,
|
onFetchAll: () -> Unit,
|
||||||
|
isPullWithRebaseDefault: Boolean,
|
||||||
): List<DropDownContentData> {
|
): List<DropDownContentData> {
|
||||||
|
val pullWithText = if (isPullWithRebaseDefault) {
|
||||||
|
"Pull with merge"
|
||||||
|
} else {
|
||||||
|
"Pull with rebase"
|
||||||
|
}
|
||||||
|
|
||||||
return mutableListOf(
|
return mutableListOf(
|
||||||
DropDownContentData(
|
DropDownContentData(
|
||||||
label = "Pull with rebase",
|
label = pullWithText,
|
||||||
onClick = onPullRebase,
|
onClick = onPullWith,
|
||||||
),
|
),
|
||||||
DropDownContentData(
|
DropDownContentData(
|
||||||
label = "Fetch all",
|
label = "Fetch all",
|
||||||
|
@ -116,6 +116,7 @@ fun SettingsDialog(
|
|||||||
fun GitSettings(settingsViewModel: SettingsViewModel) {
|
fun GitSettings(settingsViewModel: SettingsViewModel) {
|
||||||
val commitsLimitEnabled by settingsViewModel.commitsLimitEnabledFlow.collectAsState()
|
val commitsLimitEnabled by settingsViewModel.commitsLimitEnabledFlow.collectAsState()
|
||||||
val ffMerge by settingsViewModel.ffMergeFlow.collectAsState()
|
val ffMerge by settingsViewModel.ffMergeFlow.collectAsState()
|
||||||
|
val pullRebase by settingsViewModel.pullRebaseFlow.collectAsState()
|
||||||
var commitsLimit by remember { mutableStateOf(settingsViewModel.commitsLimit) }
|
var commitsLimit by remember { mutableStateOf(settingsViewModel.commitsLimit) }
|
||||||
|
|
||||||
SettingToggle(
|
SettingToggle(
|
||||||
@ -146,6 +147,15 @@ fun GitSettings(settingsViewModel: SettingsViewModel) {
|
|||||||
settingsViewModel.ffMerge = value
|
settingsViewModel.ffMerge = value
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
SettingToggle(
|
||||||
|
title = "Pull with rebase as default",
|
||||||
|
subtitle = "Rebase changes instead of merging when pulling",
|
||||||
|
value = pullRebase,
|
||||||
|
onValueChanged = { value ->
|
||||||
|
settingsViewModel.pullRebase = value
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -4,10 +4,12 @@ import com.jetpackduba.gitnuro.git.RefreshType
|
|||||||
import com.jetpackduba.gitnuro.git.TabState
|
import com.jetpackduba.gitnuro.git.TabState
|
||||||
import com.jetpackduba.gitnuro.git.remote_operations.FetchAllBranchesUseCase
|
import com.jetpackduba.gitnuro.git.remote_operations.FetchAllBranchesUseCase
|
||||||
import com.jetpackduba.gitnuro.git.remote_operations.PullBranchUseCase
|
import com.jetpackduba.gitnuro.git.remote_operations.PullBranchUseCase
|
||||||
|
import com.jetpackduba.gitnuro.git.remote_operations.PullType
|
||||||
import com.jetpackduba.gitnuro.git.remote_operations.PushBranchUseCase
|
import com.jetpackduba.gitnuro.git.remote_operations.PushBranchUseCase
|
||||||
import com.jetpackduba.gitnuro.git.stash.PopLastStashUseCase
|
import com.jetpackduba.gitnuro.git.stash.PopLastStashUseCase
|
||||||
import com.jetpackduba.gitnuro.git.stash.StashChangesUseCase
|
import com.jetpackduba.gitnuro.git.stash.StashChangesUseCase
|
||||||
import com.jetpackduba.gitnuro.git.workspace.StageUntrackedFileUseCase
|
import com.jetpackduba.gitnuro.git.workspace.StageUntrackedFileUseCase
|
||||||
|
import com.jetpackduba.gitnuro.preferences.AppSettings
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class MenuViewModel @Inject constructor(
|
class MenuViewModel @Inject constructor(
|
||||||
@ -18,12 +20,15 @@ class MenuViewModel @Inject constructor(
|
|||||||
private val popLastStashUseCase: PopLastStashUseCase,
|
private val popLastStashUseCase: PopLastStashUseCase,
|
||||||
private val stashChangesUseCase: StashChangesUseCase,
|
private val stashChangesUseCase: StashChangesUseCase,
|
||||||
private val stageUntrackedFileUseCase: StageUntrackedFileUseCase,
|
private val stageUntrackedFileUseCase: StageUntrackedFileUseCase,
|
||||||
|
private val settings: AppSettings,
|
||||||
) {
|
) {
|
||||||
fun pull(rebase: Boolean = false) = tabState.safeProcessing(
|
val isPullWithRebaseDefault = settings.pullRebaseFlow
|
||||||
|
|
||||||
|
fun pull(pullType: PullType) = tabState.safeProcessing(
|
||||||
refreshType = RefreshType.ALL_DATA,
|
refreshType = RefreshType.ALL_DATA,
|
||||||
refreshEvenIfCrashes = true,
|
refreshEvenIfCrashes = true,
|
||||||
) { git ->
|
) { git ->
|
||||||
pullBranchUseCase(git, rebase)
|
pullBranchUseCase(git, pullType)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fetchAll() = tabState.safeProcessing(
|
fun fetchAll() = tabState.safeProcessing(
|
||||||
|
@ -18,6 +18,7 @@ class SettingsViewModel @Inject constructor(
|
|||||||
|
|
||||||
val themeState = appSettings.themeState
|
val themeState = appSettings.themeState
|
||||||
val ffMergeFlow = appSettings.ffMergeFlow
|
val ffMergeFlow = appSettings.ffMergeFlow
|
||||||
|
val pullRebaseFlow = appSettings.pullRebaseFlow
|
||||||
val commitsLimitEnabledFlow = appSettings.commitsLimitEnabledFlow
|
val commitsLimitEnabledFlow = appSettings.commitsLimitEnabledFlow
|
||||||
|
|
||||||
var scaleUi: Float
|
var scaleUi: Float
|
||||||
@ -38,6 +39,12 @@ class SettingsViewModel @Inject constructor(
|
|||||||
appSettings.ffMerge = value
|
appSettings.ffMerge = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var pullRebase: Boolean
|
||||||
|
get() = appSettings.pullRebase
|
||||||
|
set(value) {
|
||||||
|
appSettings.pullRebase = value
|
||||||
|
}
|
||||||
|
|
||||||
var theme: Theme
|
var theme: Theme
|
||||||
get() = appSettings.theme
|
get() = appSettings.theme
|
||||||
set(value) {
|
set(value) {
|
||||||
|
Loading…
Reference in New Issue
Block a user