JGit Check if a branch is checked out

拟墨画扇 提交于 2020-01-13 11:52:44

问题


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();

回答1:


Repository::getFullBranch() returns the full name (e.g. refs/heads/master) of the currently checked out branch, if any. Otherwise the ID of the HEAD commit is returned or null, if there is no commit.



来源:https://stackoverflow.com/questions/24992843/jgit-check-if-a-branch-is-checked-out

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!