Added branch creaton/deletion methods and changes hasUncommitedChanges to be stateful
This commit is contained in:
parent
b2a93cd339
commit
9a76d13483
@ -52,9 +52,6 @@ class GitManager {
|
|||||||
|
|
||||||
private var git: Git? = null
|
private var git: Git? = null
|
||||||
|
|
||||||
var lastTimeStatusChanged: Long = 0 // TODO Add file watcher to the repository
|
|
||||||
private set
|
|
||||||
|
|
||||||
val safeGit: Git
|
val safeGit: Git
|
||||||
get() {
|
get() {
|
||||||
val git = this.git
|
val git = this.git
|
||||||
@ -110,11 +107,6 @@ class GitManager {
|
|||||||
statusManager.loadStatus(safeGit)
|
statusManager.loadStatus(safeGit)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateStatus() {
|
|
||||||
lastTimeStatusChanged = System.currentTimeMillis()
|
|
||||||
loadStatus()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun stage(diffEntry: DiffEntry) = managerScope.launch {
|
fun stage(diffEntry: DiffEntry) = managerScope.launch {
|
||||||
statusManager.stage(safeGit, diffEntry)
|
statusManager.stage(safeGit, diffEntry)
|
||||||
}
|
}
|
||||||
@ -168,10 +160,20 @@ class GitManager {
|
|||||||
|
|
||||||
fun stash() = managerScope.launch {
|
fun stash() = managerScope.launch {
|
||||||
stashManager.stash(safeGit)
|
stashManager.stash(safeGit)
|
||||||
|
loadStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun popStash() = managerScope.launch {
|
fun popStash() = managerScope.launch {
|
||||||
stashManager.popStash(safeGit)
|
stashManager.popStash(safeGit)
|
||||||
|
loadStatus()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createBranch(branchName: String) = managerScope.launch {
|
||||||
|
branchesManager.createBranch(safeGit, branchName)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun deleteBranch(branch: Ref) = managerScope.launch {
|
||||||
|
branchesManager.deleteBranch(safeGit, branch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +51,8 @@ fun RepositorySelected(gitManager: GitManager, repository: Repository) {
|
|||||||
onRevCommitSelected = { commit ->
|
onRevCommitSelected = { commit ->
|
||||||
uncommitedChangesSelected = false
|
uncommitedChangesSelected = false
|
||||||
|
|
||||||
|
gitManager.loadStatus()
|
||||||
|
|
||||||
val parent = if (commit.parentCount == 0) {
|
val parent = if (commit.parentCount == 0) {
|
||||||
null
|
null
|
||||||
} else
|
} else
|
||||||
@ -70,7 +72,7 @@ fun RepositorySelected(gitManager: GitManager, repository: Repository) {
|
|||||||
},
|
},
|
||||||
onUncommitedChangesSelected = {
|
onUncommitedChangesSelected = {
|
||||||
uncommitedChangesSelected = true
|
uncommitedChangesSelected = true
|
||||||
gitManager.updateStatus()
|
gitManager.loadStatus()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ private fun StashRow(stash: RevCommit) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = stash.name,
|
text = stash.shortMessage,
|
||||||
modifier = Modifier.weight(1f, fill = true),
|
modifier = Modifier.weight(1f, fill = true),
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
7
src/main/kotlin/extensions/StatusExtensions.kt
Normal file
7
src/main/kotlin/extensions/StatusExtensions.kt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package extensions
|
||||||
|
|
||||||
|
import org.eclipse.jgit.api.Status
|
||||||
|
|
||||||
|
fun Status.hasUntrackedChanges(): Boolean {
|
||||||
|
return this.untracked.isNotEmpty()
|
||||||
|
}
|
@ -19,4 +19,20 @@ class BranchesManager {
|
|||||||
|
|
||||||
_branches.value = branchList
|
_branches.value = branchList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun createBranch(git: Git, branchName: String) = withContext(Dispatchers.IO) {
|
||||||
|
git
|
||||||
|
.branchCreate()
|
||||||
|
.setName(branchName)
|
||||||
|
.call()
|
||||||
|
|
||||||
|
loadBranches(git)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun deleteBranch(git: Git, branch: Ref) = withContext(Dispatchers.IO) {
|
||||||
|
git
|
||||||
|
.branchDelete()
|
||||||
|
.setBranchNames(branch.name)
|
||||||
|
.call()
|
||||||
|
}
|
||||||
}
|
}
|
@ -6,6 +6,8 @@ import kotlinx.coroutines.flow.StateFlow
|
|||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.eclipse.jgit.revwalk.RevCommit
|
import org.eclipse.jgit.revwalk.RevCommit
|
||||||
|
import java.text.DateFormat
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
class StashManager {
|
class StashManager {
|
||||||
private val _stashStatus = MutableStateFlow<StashStatus>(StashStatus.Loaded(listOf()))
|
private val _stashStatus = MutableStateFlow<StashStatus>(StashStatus.Loaded(listOf()))
|
||||||
@ -15,16 +17,23 @@ class StashManager {
|
|||||||
suspend fun stash(git: Git) = withContext(Dispatchers.IO) {
|
suspend fun stash(git: Git) = withContext(Dispatchers.IO) {
|
||||||
git
|
git
|
||||||
.stashCreate()
|
.stashCreate()
|
||||||
|
.setIncludeUntracked(true)
|
||||||
.call()
|
.call()
|
||||||
|
|
||||||
loadStashList(git)
|
loadStashList(git)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun popStash(git: Git) = withContext(Dispatchers.IO) {
|
suspend fun popStash(git: Git) = withContext(Dispatchers.IO) {
|
||||||
|
// val firstStash = git.stashList().call().firstOrNull() ?: return@withContext
|
||||||
|
|
||||||
git
|
git
|
||||||
.stashApply()
|
.stashApply()
|
||||||
|
// .setStashRef(firstStash.)
|
||||||
.call()
|
.call()
|
||||||
|
|
||||||
|
// git.stashDrop()
|
||||||
|
// .setStashRef(firstStash.)
|
||||||
|
|
||||||
loadStashList(git)
|
loadStashList(git)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package git
|
package git
|
||||||
|
|
||||||
import extensions.filePath
|
import extensions.filePath
|
||||||
|
import extensions.hasUntrackedChanges
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.ensureActive
|
import kotlinx.coroutines.ensureActive
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
@ -20,10 +21,11 @@ class StatusManager {
|
|||||||
get() = _hasUncommitedChanges
|
get() = _hasUncommitedChanges
|
||||||
|
|
||||||
suspend fun loadHasUncommitedChanges(git: Git) = withContext(Dispatchers.IO) {
|
suspend fun loadHasUncommitedChanges(git: Git) = withContext(Dispatchers.IO) {
|
||||||
val hasUncommitedChanges = git
|
val status = git
|
||||||
.status()
|
.status()
|
||||||
.call()
|
.call()
|
||||||
.hasUncommittedChanges()
|
|
||||||
|
val hasUncommitedChanges = status.hasUncommittedChanges() || status.hasUntrackedChanges()
|
||||||
|
|
||||||
_hasUncommitedChanges.value = hasUncommitedChanges
|
_hasUncommitedChanges.value = hasUncommitedChanges
|
||||||
}
|
}
|
||||||
@ -31,6 +33,8 @@ class StatusManager {
|
|||||||
suspend fun loadStatus(git: Git) = withContext(Dispatchers.IO) {
|
suspend fun loadStatus(git: Git) = withContext(Dispatchers.IO) {
|
||||||
_stageStatus.value = StageStatus.Loading
|
_stageStatus.value = StageStatus.Loading
|
||||||
|
|
||||||
|
loadHasUncommitedChanges(git)
|
||||||
|
|
||||||
val staged = git
|
val staged = git
|
||||||
.diff()
|
.diff()
|
||||||
.setCached(true)
|
.setCached(true)
|
||||||
|
Loading…
Reference in New Issue
Block a user