aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-11-27 12:57:18 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2022-11-27 13:28:45 +0530
commite8aabaf752c4f8ddffc8189ce84ddfa8258704cf (patch)
tree2e76ea902e3895c410c74ca29e408d5d4db8e218 /app/src/main
parent2a3f78d43e20e22686ef3fdf35fbf56f85478268 (diff)
feat: add a helper to `PasswordRepository` to retrieve the current branch
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/app/passwordstore/data/repo/PasswordRepository.kt13
1 files changed, 13 insertions, 0 deletions
diff --git a/app/src/main/java/app/passwordstore/data/repo/PasswordRepository.kt b/app/src/main/java/app/passwordstore/data/repo/PasswordRepository.kt
index b42b7892..2144cf1e 100644
--- a/app/src/main/java/app/passwordstore/data/repo/PasswordRepository.kt
+++ b/app/src/main/java/app/passwordstore/data/repo/PasswordRepository.kt
@@ -16,6 +16,7 @@ import com.github.michaelbull.result.onFailure
import com.github.michaelbull.result.runCatching
import java.io.File
import org.eclipse.jgit.api.Git
+import org.eclipse.jgit.lib.Constants
import org.eclipse.jgit.lib.Repository
import org.eclipse.jgit.storage.file.FileRepositoryBuilder
import org.eclipse.jgit.transport.RefSpec
@@ -125,6 +126,18 @@ object PasswordRepository {
return repository
}
+ /** Get the currently checked out branch. */
+ fun getCurrentBranch(): String? {
+ val repository = repository ?: return null
+ val headRef = repository.getRef(Constants.HEAD) ?: return null
+ return if (headRef.isSymbolic) {
+ val branchName = headRef.target.name
+ Repository.shortenRefName(branchName)
+ } else {
+ null
+ }
+ }
+
/**
* Gets the .gpg files in a directory
*