diff --git a/src/main/kotlin/GitManager.kt b/src/main/kotlin/GitManager.kt index f0e1681..0fe83a7 100644 --- a/src/main/kotlin/GitManager.kt +++ b/src/main/kotlin/GitManager.kt @@ -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) + } } diff --git a/src/main/kotlin/git/RemoteOperationsManager.kt b/src/main/kotlin/git/RemoteOperationsManager.kt new file mode 100644 index 0000000..07e9cd9 --- /dev/null +++ b/src/main/kotlin/git/RemoteOperationsManager.kt @@ -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() + } +} \ No newline at end of file diff --git a/src/main/kotlin/main.kt b/src/main/kotlin/main.kt index 9befe78..fa9fd61 100644 --- a/src/main/kotlin/main.kt +++ b/src/main/kotlin/main.kt @@ -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") } } } \ No newline at end of file