Added basic pull/push functionality
This commit is contained in:
parent
7ce954252e
commit
3ba7aed256
3 changed files with 52 additions and 10 deletions
src/main/kotlin
|
@ -1,7 +1,4 @@
|
|||
import git.LogManager
|
||||
import git.LogStatus
|
||||
import git.StageStatus
|
||||
import git.StatusManager
|
||||
import git.*
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
|
@ -23,6 +20,7 @@ class GitManager {
|
|||
private val preferences = GPreferences()
|
||||
private val statusManager = StatusManager()
|
||||
private val logManager = LogManager()
|
||||
private val remoteOperationsManager = RemoteOperationsManager()
|
||||
|
||||
private val managerScope = CoroutineScope(SupervisorJob())
|
||||
|
||||
|
@ -142,6 +140,14 @@ class GitManager {
|
|||
|
||||
return byteArrayOutputStream.toString(Charsets.UTF_8)
|
||||
}
|
||||
|
||||
fun pull() = managerScope.launch {
|
||||
remoteOperationsManager.pull(safeGit)
|
||||
}
|
||||
|
||||
fun push() = managerScope.launch {
|
||||
remoteOperationsManager.push(safeGit)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
22
src/main/kotlin/git/RemoteOperationsManager.kt
Normal file
22
src/main/kotlin/git/RemoteOperationsManager.kt
Normal file
|
@ -0,0 +1,22 @@
|
|||
package git
|
||||
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.transport.CredentialsProvider
|
||||
|
||||
class RemoteOperationsManager {
|
||||
suspend fun pull(git: Git) = withContext(Dispatchers.IO) {
|
||||
git
|
||||
.pull()
|
||||
.setCredentialsProvider(CredentialsProvider.getDefault())
|
||||
.call()
|
||||
}
|
||||
|
||||
suspend fun push(git: Git) = withContext(Dispatchers.IO) {
|
||||
git
|
||||
.push()
|
||||
.setPushTags()
|
||||
.call()
|
||||
}
|
||||
}
|
|
@ -26,7 +26,7 @@ fun main() = application {
|
|||
isOpen = false
|
||||
},
|
||||
|
||||
) {
|
||||
) {
|
||||
GitnuroTheme {
|
||||
Gitnuro(gitManager)
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ fun Gitnuro(gitManager: GitManager) {
|
|||
onRepositoryOpen = {
|
||||
val latestDirectoryOpened = gitManager.latestDirectoryOpened
|
||||
|
||||
val f = if(latestDirectoryOpened == null)
|
||||
val f = if (latestDirectoryOpened == null)
|
||||
JFileChooser()
|
||||
else
|
||||
JFileChooser(latestDirectoryOpened)
|
||||
|
@ -55,7 +55,9 @@ fun Gitnuro(gitManager: GitManager) {
|
|||
|
||||
if (f.selectedFile != null)
|
||||
gitManager.openRepository(f.selectedFile)
|
||||
}
|
||||
},
|
||||
onPull = { gitManager.pull() },
|
||||
onPush = { gitManager.push() }
|
||||
)
|
||||
|
||||
Crossfade(targetState = repositorySelectionStatus) {
|
||||
|
@ -94,7 +96,11 @@ fun NoneRepository() {
|
|||
}
|
||||
|
||||
@Composable
|
||||
fun GMenu(onRepositoryOpen: () -> Unit) {
|
||||
fun GMenu(
|
||||
onRepositoryOpen: () -> Unit,
|
||||
onPull: () -> Unit,
|
||||
onPush: () -> Unit,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.padding(vertical = 16.dp)
|
||||
|
@ -102,11 +108,19 @@ fun GMenu(onRepositoryOpen: () -> Unit) {
|
|||
horizontalArrangement = Arrangement.Center,
|
||||
) {
|
||||
OutlinedButton(
|
||||
// modifier = Modifier.size(64.dp),
|
||||
onClick = onRepositoryOpen
|
||||
) {
|
||||
Text("Open")
|
||||
// Icon(Icons.Default.Add, contentDescription = "Open repository")
|
||||
}
|
||||
OutlinedButton(
|
||||
onClick = onPull
|
||||
) {
|
||||
Text("Pull")
|
||||
}
|
||||
OutlinedButton(
|
||||
onClick = onPush
|
||||
) {
|
||||
Text("Push")
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue