List of usage examples for org.eclipse.jgit.lib Constants MERGE_HEAD
String MERGE_HEAD
To view the source code for org.eclipse.jgit.lib Constants MERGE_HEAD.
Click Source Link
From source file:com.mangosolutions.rcloud.rawgist.repository.git.BareCommitCommand.java
/** * Sets default values for not explicitly specified options. Then validates * that all required data has been provided. * * @param state/* w w w . j av a2 s .c o m*/ * the state of the repository we are working on * @param rw * the RevWalk to use * * @throws NoMessageException * if the commit message has not been specified */ private void processOptions(RepositoryState state, RevWalk rw) throws NoMessageException { if (committer == null) { committer = new PersonIdent(repo); } if (author == null && !amend) { author = committer; } if (allowEmpty == null) { // JGit allows empty commits by default. Only when pathes are // specified the commit should not be empty. This behaviour differs // from native git but can only be adapted in the next release. // TODO(ch) align the defaults with native git allowEmpty = (only.isEmpty()) ? Boolean.TRUE : Boolean.FALSE; } // when doing a merge commit parse MERGE_HEAD and MERGE_MSG files if (state == RepositoryState.MERGING_RESOLVED || isMergeDuringRebase(state)) { try { parents = repo.readMergeHeads(); if (parents != null) { for (int i = 0; i < parents.size(); i++) { RevObject ro = rw.parseAny(parents.get(i)); if (ro instanceof RevTag) parents.set(i, rw.peel(ro)); } } } catch (IOException e) { throw new JGitInternalException(MessageFormat.format( JGitText.get().exceptionOccurredDuringReadingOfGIT_DIR, Constants.MERGE_HEAD, e), e); } if (message == null) { try { message = repo.readMergeCommitMsg(); } catch (IOException e) { throw new JGitInternalException(MessageFormat.format( JGitText.get().exceptionOccurredDuringReadingOfGIT_DIR, Constants.MERGE_MSG, e), e); } } } else if (state == RepositoryState.SAFE && message == null) { try { message = repo.readSquashCommitMsg(); if (message != null) { repo.writeSquashCommitMsg(null /* delete */); } } catch (IOException e) { throw new JGitInternalException(MessageFormat .format(JGitText.get().exceptionOccurredDuringReadingOfGIT_DIR, Constants.MERGE_MSG, e), e); } } if (message == null) { // as long as we don't support -C option we have to have // an explicit message throw new NoMessageException(JGitText.get().commitMessageNotSpecified); } }
From source file:com.mangosolutions.rcloud.rawgist.repository.git.BareCommitCommand.java
private boolean isMergeDuringRebase(RepositoryState state) { if (state != RepositoryState.REBASING_INTERACTIVE && state != RepositoryState.REBASING_MERGE) { return false; }/*from ww w . j av a 2s . c om*/ try { return repo.readMergeHeads() != null; } catch (IOException e) { throw new JGitInternalException(MessageFormat .format(JGitText.get().exceptionOccurredDuringReadingOfGIT_DIR, Constants.MERGE_HEAD, e), e); } }
From source file:org.eclipse.egit.ui.internal.merge.GitMergeEditorInput.java
License:Open Source License
@Override protected Object prepareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { final Set<IFile> files = new HashSet<IFile>(); List<IContainer> folders = new ArrayList<IContainer>(); Set<IProject> projects = new HashSet<IProject>(); // collect all projects and sort the selected // resources into files and folders; skip // ignored resources for (IResource res : resources) { projects.add(res.getProject());//from w w w . j a va 2s . c om if (Team.isIgnoredHint(res)) continue; if (res.getType() == IResource.FILE) files.add((IFile) res); else folders.add((IContainer) res); } if (monitor.isCanceled()) throw new InterruptedException(); // make sure all resources belong to the same repository Repository repo = null; for (IProject project : projects) { RepositoryMapping map = RepositoryMapping.getMapping(project); if (repo != null && repo != map.getRepository()) throw new InvocationTargetException( new IllegalStateException(UIText.AbstractHistoryCommanndHandler_NoUniqueRepository)); repo = map.getRepository(); } if (repo == null) throw new InvocationTargetException( new IllegalStateException(UIText.AbstractHistoryCommanndHandler_NoUniqueRepository)); if (monitor.isCanceled()) throw new InterruptedException(); // collect all file children of the selected folders IResourceVisitor fileCollector = new IResourceVisitor() { public boolean visit(IResource resource) throws CoreException { if (Team.isIgnoredHint(resource)) return false; if (resource.getType() == IResource.FILE) { files.add((IFile) resource); } return true; } }; for (IContainer cont : folders) { try { cont.accept(fileCollector); } catch (CoreException e) { // ignore here } } if (monitor.isCanceled()) throw new InterruptedException(); // our root node this.compareResult = new DiffNode(Differencer.CONFLICTING); final RevWalk rw = new RevWalk(repo); // get the "right" side (MERGE_HEAD for merge, ORIG_HEAD for rebase) final RevCommit rightCommit; try { String target; if (repo.getRepositoryState().equals(RepositoryState.MERGING)) target = Constants.MERGE_HEAD; else if (repo.getRepositoryState().equals(RepositoryState.REBASING_INTERACTIVE)) target = readFile(repo.getDirectory(), RebaseCommand.REBASE_MERGE + File.separatorChar + RebaseCommand.STOPPED_SHA); else target = Constants.ORIG_HEAD; ObjectId mergeHead = repo.resolve(target); if (mergeHead == null) throw new IOException(NLS.bind(UIText.ValidationUtils_CanNotResolveRefMessage, target)); rightCommit = rw.parseCommit(mergeHead); } catch (IOException e) { throw new InvocationTargetException(e); } // we need the HEAD, also to determine the common // ancestor final RevCommit headCommit; try { ObjectId head = repo.resolve(Constants.HEAD); if (head == null) throw new IOException(NLS.bind(UIText.ValidationUtils_CanNotResolveRefMessage, Constants.HEAD)); headCommit = rw.parseCommit(head); } catch (IOException e) { throw new InvocationTargetException(e); } final String fullBranch; try { fullBranch = repo.getFullBranch(); } catch (IOException e) { throw new InvocationTargetException(e); } // try to obtain the common ancestor List<RevCommit> startPoints = new ArrayList<RevCommit>(); rw.setRevFilter(RevFilter.MERGE_BASE); startPoints.add(rightCommit); startPoints.add(headCommit); RevCommit ancestorCommit; try { rw.markStart(startPoints); ancestorCommit = rw.next(); } catch (Exception e) { ancestorCommit = null; } if (monitor.isCanceled()) throw new InterruptedException(); // set the labels CompareConfiguration config = getCompareConfiguration(); config.setRightLabel(NLS.bind(LABELPATTERN, rightCommit.getShortMessage(), rightCommit.name())); if (!useWorkspace) config.setLeftLabel(NLS.bind(LABELPATTERN, headCommit.getShortMessage(), headCommit.name())); else config.setLeftLabel(UIText.GitMergeEditorInput_WorkspaceHeader); if (ancestorCommit != null) config.setAncestorLabel( NLS.bind(LABELPATTERN, ancestorCommit.getShortMessage(), ancestorCommit.name())); // set title and icon setTitle(NLS.bind(UIText.GitMergeEditorInput_MergeEditorTitle, new Object[] { Activator.getDefault().getRepositoryUtil().getRepositoryName(repo), rightCommit.getShortMessage(), fullBranch })); // now we calculate the nodes containing the compare information try { for (IFile file : files) { if (monitor.isCanceled()) throw new InterruptedException(); monitor.setTaskName(file.getFullPath().toString()); RepositoryMapping map = RepositoryMapping.getMapping(file); String gitPath = map.getRepoRelativePath(file); if (gitPath == null) continue; // ignore everything in .git if (gitPath.startsWith(Constants.DOT_GIT)) continue; fileToDiffNode(file, gitPath, map, this.compareResult, rightCommit, headCommit, ancestorCommit, rw, monitor); } } catch (IOException e) { throw new InvocationTargetException(e); } return compareResult; }
From source file:org.eclipse.emf.compare.egit.ui.internal.merge.ModelGitMergeEditorInput.java
License:Open Source License
private RevCommit getRightCommit(RevWalk revWalk, Repository repository) throws InvocationTargetException { try {/*w w w .j av a2s . com*/ String target; if (repository.getRepositoryState().equals(RepositoryState.MERGING)) { target = Constants.MERGE_HEAD; } else if (repository.getRepositoryState().equals(RepositoryState.CHERRY_PICKING)) { target = Constants.CHERRY_PICK_HEAD; } else if (repository.getRepositoryState().equals(RepositoryState.REBASING_INTERACTIVE)) { target = readFile(repository.getDirectory(), RebaseCommand.REBASE_MERGE + File.separatorChar + RebaseCommand.STOPPED_SHA); } else { target = Constants.ORIG_HEAD; } ObjectId mergeHead = repository.resolve(target); if (mergeHead == null) { throw new IOException(NLS.bind(UIText.ValidationUtils_CanNotResolveRefMessage, target)); } return revWalk.parseCommit(mergeHead); } catch (IOException e) { throw new InvocationTargetException(e); } }