Added basic pull/push functionality
This commit is contained in:
parent
7ce954252e
commit
3ba7aed256
@ -1,7 +1,4 @@
|
|||||||
import git.LogManager
|
import git.*
|
||||||
import git.LogStatus
|
|
||||||
import git.StageStatus
|
|
||||||
import git.StatusManager
|
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
@ -23,6 +20,7 @@ class GitManager {
|
|||||||
private val preferences = GPreferences()
|
private val preferences = GPreferences()
|
||||||
private val statusManager = StatusManager()
|
private val statusManager = StatusManager()
|
||||||
private val logManager = LogManager()
|
private val logManager = LogManager()
|
||||||
|
private val remoteOperationsManager = RemoteOperationsManager()
|
||||||
|
|
||||||
private val managerScope = CoroutineScope(SupervisorJob())
|
private val managerScope = CoroutineScope(SupervisorJob())
|
||||||
|
|
||||||
@ -142,6 +140,14 @@ class GitManager {
|
|||||||
|
|
||||||
return byteArrayOutputStream.toString(Charsets.UTF_8)
|
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()
|
||||||
|
}
|
||||||
|
}
|
@ -45,7 +45,7 @@ fun Gitnuro(gitManager: GitManager) {
|
|||||||
onRepositoryOpen = {
|
onRepositoryOpen = {
|
||||||
val latestDirectoryOpened = gitManager.latestDirectoryOpened
|
val latestDirectoryOpened = gitManager.latestDirectoryOpened
|
||||||
|
|
||||||
val f = if(latestDirectoryOpened == null)
|
val f = if (latestDirectoryOpened == null)
|
||||||
JFileChooser()
|
JFileChooser()
|
||||||
else
|
else
|
||||||
JFileChooser(latestDirectoryOpened)
|
JFileChooser(latestDirectoryOpened)
|
||||||
@ -55,7 +55,9 @@ fun Gitnuro(gitManager: GitManager) {
|
|||||||
|
|
||||||
if (f.selectedFile != null)
|
if (f.selectedFile != null)
|
||||||
gitManager.openRepository(f.selectedFile)
|
gitManager.openRepository(f.selectedFile)
|
||||||
}
|
},
|
||||||
|
onPull = { gitManager.pull() },
|
||||||
|
onPush = { gitManager.push() }
|
||||||
)
|
)
|
||||||
|
|
||||||
Crossfade(targetState = repositorySelectionStatus) {
|
Crossfade(targetState = repositorySelectionStatus) {
|
||||||
@ -94,7 +96,11 @@ fun NoneRepository() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun GMenu(onRepositoryOpen: () -> Unit) {
|
fun GMenu(
|
||||||
|
onRepositoryOpen: () -> Unit,
|
||||||
|
onPull: () -> Unit,
|
||||||
|
onPush: () -> Unit,
|
||||||
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(vertical = 16.dp)
|
.padding(vertical = 16.dp)
|
||||||
@ -102,11 +108,19 @@ fun GMenu(onRepositoryOpen: () -> Unit) {
|
|||||||
horizontalArrangement = Arrangement.Center,
|
horizontalArrangement = Arrangement.Center,
|
||||||
) {
|
) {
|
||||||
OutlinedButton(
|
OutlinedButton(
|
||||||
// modifier = Modifier.size(64.dp),
|
|
||||||
onClick = onRepositoryOpen
|
onClick = onRepositoryOpen
|
||||||
) {
|
) {
|
||||||
Text("Open")
|
Text("Open")
|
||||||
// Icon(Icons.Default.Add, contentDescription = "Open repository")
|
}
|
||||||
|
OutlinedButton(
|
||||||
|
onClick = onPull
|
||||||
|
) {
|
||||||
|
Text("Pull")
|
||||||
|
}
|
||||||
|
OutlinedButton(
|
||||||
|
onClick = onPush
|
||||||
|
) {
|
||||||
|
Text("Push")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user