feat: add a helper to PasswordRepository
to retrieve the current branch
This commit is contained in:
parent
2a3f78d43e
commit
e8aabaf752
1 changed files with 13 additions and 0 deletions
|
@ -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
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue