List of usage examples for org.eclipse.jgit.api.errors DetachedHeadException DetachedHeadException
public DetachedHeadException()
From source file:org.flowerplatform.web.git.GitUtils.java
License:Open Source License
@SuppressWarnings("restriction") public Object[] getFetchPushUpstreamDataRefSpecAndRemote(Repository repository) throws InvalidConfigurationException, NoHeadException, DetachedHeadException { String branchName;/* ww w .j a v a 2 s . co m*/ String fullBranch; try { fullBranch = repository.getFullBranch(); if (fullBranch == null) { throw new NoHeadException(JGitText.get().pullOnRepoWithoutHEADCurrentlyNotSupported); } if (!fullBranch.startsWith(Constants.R_HEADS)) { // we can not pull if HEAD is detached and branch is not // specified explicitly throw new DetachedHeadException(); } branchName = fullBranch.substring(Constants.R_HEADS.length()); } catch (IOException e) { throw new JGitInternalException(JGitText.get().exceptionCaughtDuringExecutionOfPullCommand, e); } // get the configured remote for the currently checked out branch // stored in configuration key branch.<branch name>.remote Config repoConfig = repository.getConfig(); String remote = repoConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REMOTE); if (remote == null) { // fall back to default remote remote = Constants.DEFAULT_REMOTE_NAME; } // get the name of the branch in the remote repository // stored in configuration key branch.<branch name>.merge String remoteBranchName = repoConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_MERGE); if (remoteBranchName == null) { String missingKey = ConfigConstants.CONFIG_BRANCH_SECTION + "." + branchName + "." + ConfigConstants.CONFIG_KEY_MERGE; throw new InvalidConfigurationException( MessageFormat.format(JGitText.get().missingConfigurationForKey, missingKey)); } // check if the branch is configured for pull-rebase boolean doRebase = repoConfig.getBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REBASE, false); final boolean isRemote = !remote.equals("."); //$NON-NLS-1$ String remoteUri; if (isRemote) { remoteUri = repoConfig.getString(ConfigConstants.CONFIG_REMOTE_SECTION, remote, ConfigConstants.CONFIG_KEY_URL); if (remoteUri == null) { String missingKey = ConfigConstants.CONFIG_REMOTE_SECTION + "." + remote + "." + ConfigConstants.CONFIG_KEY_URL; throw new InvalidConfigurationException( MessageFormat.format(JGitText.get().missingConfigurationForKey, missingKey)); } return new Object[] { fullBranch, remoteBranchName, remoteUri, doRebase }; } return null; }