summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
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
*