mirror of
https://github.com/android-password-store/Android-Password-Store
synced 2025-09-01 14:55:19 +00:00
feat: add a helper to PasswordRepository
to retrieve the current branch
This commit is contained in:
@@ -16,6 +16,7 @@ import com.github.michaelbull.result.onFailure
|
|||||||
import com.github.michaelbull.result.runCatching
|
import com.github.michaelbull.result.runCatching
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
|
import org.eclipse.jgit.lib.Constants
|
||||||
import org.eclipse.jgit.lib.Repository
|
import org.eclipse.jgit.lib.Repository
|
||||||
import org.eclipse.jgit.storage.file.FileRepositoryBuilder
|
import org.eclipse.jgit.storage.file.FileRepositoryBuilder
|
||||||
import org.eclipse.jgit.transport.RefSpec
|
import org.eclipse.jgit.transport.RefSpec
|
||||||
@@ -125,6 +126,18 @@ object PasswordRepository {
|
|||||||
return repository
|
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
|
* Gets the .gpg files in a directory
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user