I am working on a project using JGit. I managed to delete a branch, but I also want to check if that branch is checked out or not. I found a variable in CheckoutCommand but it is private:
private boolean isCheckoutIndex() {
return startCommit == null && startPoint == null;
}
No public method returns what I want. When I use the command below on a checked out branch it returns an error that the branch cannot be deleted, so I want to check first if is checked out or not.
git.branchDelete().setForce(true).setBranchNames(branchName).call();
Repository::getFullBranch() returns the full name (e.g. refs/heads/main) of the currently checked out branch, if any. Otherwise the ID of the HEAD commit is returned or null, if there is no commit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With