Implemented basic local git init
This commit is contained in:
parent
54a1ab4436
commit
558f02fca4
@ -8,6 +8,8 @@ import org.eclipse.jgit.storage.file.FileRepositoryBuilder
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
private const val INITIAL_BRANCH_NAME = "main"
|
||||
|
||||
class RepositoryManager @Inject constructor() {
|
||||
suspend fun getRepositoryState(git: Git) = withContext(Dispatchers.IO) {
|
||||
return@withContext git.repository.repositoryState
|
||||
@ -30,4 +32,11 @@ class RepositoryManager @Inject constructor() {
|
||||
.findGitDir() // scan up the file system tree
|
||||
.build()
|
||||
}
|
||||
|
||||
suspend fun initLocalRepo(repoDir: File): Unit = withContext(Dispatchers.IO) {
|
||||
Git.init()
|
||||
.setInitialBranch(INITIAL_BRANCH_NAME)
|
||||
.setDirectory(repoDir)
|
||||
.call()
|
||||
}
|
||||
}
|
@ -1,14 +1,38 @@
|
||||
import app.extensions.runCommand
|
||||
import app.viewmodels.TabViewModel
|
||||
import java.io.File
|
||||
import javax.swing.JFileChooser
|
||||
import javax.swing.UIManager
|
||||
|
||||
|
||||
fun openDirectoryDialog(): String? {
|
||||
val os = System.getProperty("os.name")
|
||||
var dirToOpen: String? = null
|
||||
|
||||
if (os.lowercase() == "linux") {
|
||||
val checkZenityInstalled = runCommand("which zenity 2>/dev/null")
|
||||
val isZenityInstalled = !checkZenityInstalled.isNullOrEmpty()
|
||||
|
||||
if (isZenityInstalled) {
|
||||
val openDirectory = runCommand(
|
||||
"zenity --file-selection --title=Open --directory"
|
||||
)?.replace("\n", "")
|
||||
|
||||
if (!openDirectory.isNullOrEmpty())
|
||||
dirToOpen = openDirectory
|
||||
} else
|
||||
dirToOpen = openJvmDialog("", true)
|
||||
} else {
|
||||
dirToOpen = openJvmDialog("", false)
|
||||
}
|
||||
|
||||
return dirToOpen
|
||||
}
|
||||
fun openRepositoryDialog(tabViewModel: TabViewModel) {
|
||||
val os = System.getProperty("os.name")
|
||||
val appStateManager = tabViewModel.appStateManager
|
||||
val latestDirectoryOpened = appStateManager.latestOpenedRepositoryPath
|
||||
|
||||
var dirToOpen: String? = null
|
||||
|
||||
if (os.lowercase() == "linux") {
|
||||
val checkZenityInstalled = runCommand("which zenity 2>/dev/null")
|
||||
@ -20,20 +44,21 @@ fun openRepositoryDialog(tabViewModel: TabViewModel) {
|
||||
)?.replace("\n", "")
|
||||
|
||||
if (!openDirectory.isNullOrEmpty())
|
||||
tabViewModel.openRepository(openDirectory)
|
||||
dirToOpen = openDirectory
|
||||
} else
|
||||
openRepositoryDialog(tabViewModel, latestDirectoryOpened, true)
|
||||
dirToOpen = openJvmDialog(latestDirectoryOpened, true)
|
||||
} else {
|
||||
openRepositoryDialog(tabViewModel, latestDirectoryOpened, false)
|
||||
dirToOpen = openJvmDialog(latestDirectoryOpened, false)
|
||||
}
|
||||
|
||||
if(dirToOpen != null)
|
||||
tabViewModel.openRepository(dirToOpen)
|
||||
}
|
||||
|
||||
private fun openRepositoryDialog(
|
||||
tabViewModel: TabViewModel,
|
||||
private fun openJvmDialog(
|
||||
latestDirectoryOpened: String,
|
||||
isLinux: Boolean,
|
||||
) {
|
||||
) : String? {
|
||||
if (!isLinux) {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
|
||||
}
|
||||
@ -46,6 +71,8 @@ private fun openRepositoryDialog(
|
||||
fileChooser.fileSelectionMode = JFileChooser.DIRECTORIES_ONLY
|
||||
fileChooser.showSaveDialog(null)
|
||||
|
||||
if (fileChooser.selectedFile != null)
|
||||
tabViewModel.openRepository(fileChooser.selectedFile)
|
||||
return if (fileChooser.selectedFile != null)
|
||||
fileChooser.selectedFile.absolutePath
|
||||
else
|
||||
null
|
||||
}
|
@ -25,6 +25,7 @@ import app.theme.secondaryTextColor
|
||||
import app.ui.dialogs.CloneDialog
|
||||
import app.ui.dialogs.MaterialDialog
|
||||
import app.viewmodels.TabViewModel
|
||||
import openDirectoryDialog
|
||||
import openRepositoryDialog
|
||||
import java.awt.Desktop
|
||||
import java.net.URI
|
||||
@ -87,7 +88,11 @@ fun WelcomePage(
|
||||
.padding(bottom = 8.dp),
|
||||
title = "Start a local repository",
|
||||
painter = painterResource("open.svg"),
|
||||
onClick = { }
|
||||
onClick = {
|
||||
val dir = openDirectoryDialog()
|
||||
if(dir != null)
|
||||
tabViewModel.initLocalRepository(dir)
|
||||
}
|
||||
)
|
||||
|
||||
Text(
|
||||
|
@ -254,6 +254,12 @@ class TabViewModel @Inject constructor(
|
||||
diffViewModel.updateDiff(diffSelected)
|
||||
}
|
||||
}
|
||||
|
||||
fun initLocalRepository(dir: String) = tabState.managerScope.launch(Dispatchers.IO){
|
||||
val repoDir = File(dir)
|
||||
repositoryManager.initLocalRepo(repoDir)
|
||||
openRepository(repoDir)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user