List of usage examples for org.eclipse.jgit.api.errors CheckoutConflictException getConflictingPaths
public List<String> getConflictingPaths()
From source file:org.apache.stratos.cartridge.agent.artifact.deployment.synchronizer.git.impl.GitBasedArtifactRepository.java
License:Apache License
private boolean pullAndHandleErrors(RepositoryContext gitRepoCtx) { try {/*ww w . jav a 2s .c o m*/ return pullArtifacts(gitRepoCtx); } catch (CheckoutConflictException e) { // checkout from remote HEAD return checkoutFromRemoteHead(gitRepoCtx, e.getConflictingPaths()); // pull again /*try { return pullArtifacts(gitRepoCtx); } catch (GitAPIException e1) { //cannot happen here log.error("Git pull failed for tenant " + gitRepoCtx.getTenantId(), e1); return false; }*/ } }
From source file:org.eclipse.che.git.impl.jgit.JGitConnection.java
License:Open Source License
@Override public MergeResult merge(MergeRequest request) throws GitException { org.eclipse.jgit.api.MergeResult jGitMergeResult; MergeResult.MergeStatus status;/*www .j a va 2s .co m*/ try { Ref ref = repository.findRef(request.getCommit()); if (ref == null) { throw new IllegalArgumentException("Invalid reference to commit for merge " + request.getCommit()); } // Shorten local branch names by removing '/refs/heads/' from the beginning String name = ref.getName(); if (name.startsWith(Constants.R_HEADS)) { name = name.substring(Constants.R_HEADS.length()); } jGitMergeResult = getGit().merge().include(name, ref.getObjectId()).call(); } catch (CheckoutConflictException exception) { jGitMergeResult = new org.eclipse.jgit.api.MergeResult(exception.getConflictingPaths()); } catch (IOException | GitAPIException exception) { throw new GitException(exception.getMessage(), exception); } switch (jGitMergeResult.getMergeStatus()) { case ALREADY_UP_TO_DATE: status = MergeResult.MergeStatus.ALREADY_UP_TO_DATE; break; case CONFLICTING: status = MergeResult.MergeStatus.CONFLICTING; break; case FAILED: status = MergeResult.MergeStatus.FAILED; break; case FAST_FORWARD: status = MergeResult.MergeStatus.FAST_FORWARD; break; case MERGED: status = MergeResult.MergeStatus.MERGED; break; case NOT_SUPPORTED: status = MergeResult.MergeStatus.NOT_SUPPORTED; break; case CHECKOUT_CONFLICT: status = MergeResult.MergeStatus.CONFLICTING; break; default: throw new IllegalStateException("Unknown merge status " + jGitMergeResult.getMergeStatus()); } ObjectId[] jGitMergedCommits = jGitMergeResult.getMergedCommits(); List<String> mergedCommits = new ArrayList<>(); if (jGitMergedCommits != null) { for (ObjectId commit : jGitMergedCommits) { mergedCommits.add(commit.getName()); } } List<String> conflicts; if (org.eclipse.jgit.api.MergeResult.MergeStatus.CHECKOUT_CONFLICT .equals(jGitMergeResult.getMergeStatus())) { conflicts = jGitMergeResult.getCheckoutConflicts(); } else { Map<String, int[][]> jGitConflicts = jGitMergeResult.getConflicts(); conflicts = jGitConflicts != null ? new ArrayList<>(jGitConflicts.keySet()) : Collections.emptyList(); } Map<String, ResolveMerger.MergeFailureReason> jGitFailing = jGitMergeResult.getFailingPaths(); ObjectId newHead = jGitMergeResult.getNewHead(); return newDto(MergeResult.class) .withFailed(jGitFailing != null ? new ArrayList<>(jGitFailing.keySet()) : Collections.emptyList()) .withNewHead(newHead != null ? newHead.getName() : null).withMergeStatus(status) .withConflicts(conflicts).withMergedCommits(mergedCommits); }
From source file:org.eclipse.che.git.impl.jgit.JGitConnection.java
License:Open Source License
@Override public PullResponse pull(PullRequest request) throws GitException, UnauthorizedException { String remoteName = request.getRemote(); String remoteUri;// w w w. j a va2 s.com try { if (repository.getRepositoryState().equals(RepositoryState.MERGING)) { throw new GitException(ERROR_PULL_MERGING); } String fullBranch = repository.getFullBranch(); if (!fullBranch.startsWith(Constants.R_HEADS)) { throw new DetachedHeadException(ERROR_PULL_HEAD_DETACHED); } String branch = fullBranch.substring(Constants.R_HEADS.length()); StoredConfig config = repository.getConfig(); if (remoteName == null) { remoteName = config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_KEY_REMOTE); if (remoteName == null) { remoteName = Constants.DEFAULT_REMOTE_NAME; } } remoteUri = config.getString(ConfigConstants.CONFIG_REMOTE_SECTION, remoteName, ConfigConstants.CONFIG_KEY_URL); String remoteBranch; RefSpec fetchRefSpecs = null; String refSpec = request.getRefSpec(); if (refSpec != null) { fetchRefSpecs = (refSpec.indexOf(':') < 0) // ? new RefSpec(Constants.R_HEADS + refSpec + ":" + fullBranch) // : new RefSpec(refSpec); remoteBranch = fetchRefSpecs.getSource(); } else { remoteBranch = config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_KEY_MERGE); } if (remoteBranch == null) { remoteBranch = fullBranch; } FetchCommand fetchCommand = getGit().fetch(); fetchCommand.setRemote(remoteName); if (fetchRefSpecs != null) { fetchCommand.setRefSpecs(fetchRefSpecs); } int timeout = request.getTimeout(); if (timeout > 0) { fetchCommand.setTimeout(timeout); } FetchResult fetchResult = (FetchResult) executeRemoteCommand(remoteUri, fetchCommand); Ref remoteBranchRef = fetchResult.getAdvertisedRef(remoteBranch); if (remoteBranchRef == null) { remoteBranchRef = fetchResult.getAdvertisedRef(Constants.R_HEADS + remoteBranch); } if (remoteBranchRef == null) { throw new GitException(String.format(ERROR_PULL_REF_MISSING, remoteBranch)); } org.eclipse.jgit.api.MergeResult mergeResult = getGit().merge().include(remoteBranchRef).call(); if (mergeResult.getMergeStatus() .equals(org.eclipse.jgit.api.MergeResult.MergeStatus.ALREADY_UP_TO_DATE)) { return newDto(PullResponse.class).withCommandOutput("Already up-to-date"); } if (mergeResult.getConflicts() != null) { StringBuilder message = new StringBuilder(ERROR_PULL_MERGE_CONFLICT_IN_FILES); message.append(lineSeparator()); Map<String, int[][]> allConflicts = mergeResult.getConflicts(); for (String path : allConflicts.keySet()) { message.append(path).append(lineSeparator()); } message.append(ERROR_PULL_AUTO_MERGE_FAILED); throw new GitException(message.toString()); } } catch (CheckoutConflictException exception) { StringBuilder message = new StringBuilder(ERROR_CHECKOUT_CONFLICT); message.append(lineSeparator()); for (String path : exception.getConflictingPaths()) { message.append(path).append(lineSeparator()); } message.append(ERROR_PULL_COMMIT_BEFORE_MERGE); throw new GitException(message.toString(), exception); } catch (IOException | GitAPIException exception) { String errorMessage; if (exception.getMessage().equals("Invalid remote: " + remoteName)) { errorMessage = ERROR_NO_REMOTE_REPOSITORY; } else { errorMessage = exception.getMessage(); } throw new GitException(errorMessage, exception); } return newDto(PullResponse.class).withCommandOutput("Successfully pulled from " + remoteUri); }
From source file:org.enterprisedomain.classmaker.impl.StateImpl.java
License:Apache License
/** * <!-- begin-user-doc --> <!-- end-user-doc --> * //from w ww.j a v a 2s. c om * @generated NOT */ public void checkout(String commitId) { try { @SuppressWarnings("unchecked") SCMOperator<Git> operator = (SCMOperator<Git>) getProject().getWorkspace().getSCMRegistry() .get(getProjectName()); setCommitId(commitId); operator.checkout(getProject().getVersion().toString(), getCommitId()); copyModel(getParent()); load(false); } catch (CheckoutConflictException e) { e.getConflictingPaths().clear(); } catch (CoreException e) { ClassMakerPlugin.getInstance().getLog().log(e.getStatus()); } catch (Exception e) { ClassMakerPlugin.getInstance().getLog().log(ClassMakerPlugin.createErrorStatus(e)); } }
From source file:org.wso2.carbon.deployment.synchronizer.git.GitBasedArtifactRepository.java
License:Open Source License
/** * Method inherited from ArtifactRepository for initializing checkout * * @param localRepoPath local repository path of the tenant * @return true if success, else false//from ww w. j av a 2s .co m * @throws DeploymentSynchronizerException if an error occurs */ public boolean checkout(int tenantId, String localRepoPath) throws DeploymentSynchronizerException { String gitRepoUrl = repositoryManager.getUrlInformation(tenantId).getUrl(); if (gitRepoUrl == null) { //url not available log.warn("Remote repository URL not available for tenant " + tenantId + ", aborting checkout"); return false; } TenantGitRepositoryContext gitRepoCtx = TenantGitRepositoryContextCache.getTenantRepositoryContextCache() .retrieveCachedTenantGitContext(tenantId); File gitRepoDir = new File(gitRepoCtx.getLocalRepoPath()); if (!gitRepoDir.exists()) { return cloneRepository(gitRepoCtx); } else { if (GitUtilities.isValidGitRepo(gitRepoCtx.getLocalRepo())) { log.info("Existing git repository detected for tenant " + gitRepoCtx.getTenantId() + ", no clone required"); try { return pullArtifacts(gitRepoCtx); } catch (CheckoutConflictException e) { //conflict(s) detected, try to checkout from local index if (checkoutFromLocalIndex(gitRepoCtx, e.getConflictingPaths())) { try { //now pull the changes from remote repository return pullArtifacts(gitRepoCtx); } catch (CheckoutConflictException e1) { //cannot happen here log.error("Git pull for the path " + e1.getConflictingPaths().toString() + " failed due to conflicts", e1); } } return false; } } else { if (behaviour.requireInitialLocalArtifactSync()) { return syncInitialLocalArtifacts(gitRepoCtx); } else { if (log.isDebugEnabled()) { log.debug("Repository for tenant " + gitRepoCtx.getTenantId() + " is not a valid git repo, will try to delete"); } FileUtilities.deleteFolderStructure(gitRepoDir); return cloneRepository(gitRepoCtx); } } } /*if(behaviour.requireInitialLocalArtifactSync() && !gitRepoCtx.initialArtifactsSynced()) { return syncInitialLocalArtifacts(gitRepoCtx); } else if(!gitRepoCtx.cloneExists()) { return cloneRepository(gitRepoCtx); } else { return pullArtifacts(gitRepoCtx); }*/ }