diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2022-11-27 12:57:18 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2022-11-27 13:28:45 +0530 |
commit | e8aabaf752c4f8ddffc8189ce84ddfa8258704cf (patch) | |
tree | 2e76ea902e3895c410c74ca29e408d5d4db8e218 /app/src/main | |
parent | 2a3f78d43e20e22686ef3fdf35fbf56f85478268 (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.kt | 13 |
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 * |