From bbea101acd498326eaa380af28809b14a86f5f19 Mon Sep 17 00:00:00 2001 From: Matthieu Bessat Date: Mon, 1 Jan 2024 17:45:25 +0100 Subject: [PATCH] fix(git): init clone --- app/src/main/java/net/mbess/popequer/GitActions.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/net/mbess/popequer/GitActions.kt b/app/src/main/java/net/mbess/popequer/GitActions.kt index 8450228..f0b5770 100644 --- a/app/src/main/java/net/mbess/popequer/GitActions.kt +++ b/app/src/main/java/net/mbess/popequer/GitActions.kt @@ -11,13 +11,15 @@ class GitActions( private val context: Context ) { private val cloneFolder = context.filesDir.resolve("popequer") - private val myCommitter = "sos" to "example@example.org" + private val myCommitter = "Mobile Sandbox" to "example@example.org" private val credentials = UsernamePasswordCredentialsProvider( "popequer-mobile-sandbox", "armament opals stupidest proud classmates" ) - private val git by lazy { - runCatching { + private lateinit var git: Git + + fun cloneOrInit() { + git = runCatching { Git.open(cloneFolder) }.getOrElse { cloneFolder.deleteRecursively() @@ -29,8 +31,9 @@ class GitActions( .call() } ?: throw IllegalStateException("Failed to open git repository") } - fun trigger() { + cloneOrInit() + val hash = System.currentTimeMillis().hashCode().absoluteValue.toString(16) val myFile = cloneFolder.resolve("my_file_$hash.txt").also { it.writeText("$hash ! ")