List of usage examples for org.eclipse.jgit.lib Constants HEAD
String HEAD
To view the source code for org.eclipse.jgit.lib Constants HEAD.
Click Source Link
From source file:org.eclipse.egit.ui.internal.actions.CommitAction.java
License:Open Source License
private void buildIndexHeadDiffList() throws IOException, CoreException { HashMap<Repository, HashSet<IProject>> repositories = new HashMap<Repository, HashSet<IProject>>(); for (IProject project : getProjectsInRepositoryOfSelectedResources()) { RepositoryMapping repositoryMapping = RepositoryMapping.getMapping(project); assert repositoryMapping != null; Repository repository = repositoryMapping.getRepository(); HashSet<IProject> projects = repositories.get(repository); if (projects == null) { projects = new HashSet<IProject>(); repositories.put(repository, projects); }// ww w. j a v a 2 s . c o m projects.add(project); } for (Map.Entry<Repository, HashSet<IProject>> entry : repositories.entrySet()) { Repository repository = entry.getKey(); HashSet<IProject> projects = entry.getValue(); Tree head = repository.mapTree(Constants.HEAD); GitIndex index = repository.getIndex(); IndexDiff indexDiff = new IndexDiff(head, index); indexDiff.diff(); for (IProject project : projects) { includeList(project, indexDiff.getAdded(), indexChanges); includeList(project, indexDiff.getChanged(), indexChanges); includeList(project, indexDiff.getRemoved(), indexChanges); includeList(project, indexDiff.getMissing(), notIndexed); includeList(project, indexDiff.getModified(), notIndexed); addUntrackedFiles(repository, project); } } }
From source file:org.eclipse.egit.ui.internal.actions.CommitAction.java
License:Open Source License
private void addUntrackedFiles(final Repository repository, final IProject project) throws CoreException, IOException { final GitIndex index = repository.getIndex(); final Tree headTree = repository.mapTree(Constants.HEAD); project.accept(new IResourceVisitor() { public boolean visit(IResource resource) throws CoreException { if (Team.isIgnoredHint(resource)) return false; if (resource.getType() == IResource.FILE) { String repoRelativePath = RepositoryMapping.getMapping(project).getRepoRelativePath(resource); try { TreeEntry headEntry = (headTree == null ? null : headTree.findBlobMember(repoRelativePath)); if (headEntry == null) { Entry indexEntry = null; indexEntry = index.getEntry(repoRelativePath); if (indexEntry == null) { notTracked.add((IFile) resource); files.add((IFile) resource); }/* w w w . j a v a 2s .co m*/ } } catch (IOException e) { throw new TeamException(UIText.CommitAction_InternalError, e); } } return true; } }); }
From source file:org.eclipse.egit.ui.internal.actions.CommitActionHandler.java
License:Open Source License
private void loadPreviousCommit(ExecutionEvent event) throws ExecutionException { IProject project = getProjectsForSelectedResources(event)[0]; Repository repo = RepositoryMapping.getMapping(project).getRepository(); try {//from w w w. ja v a2s . co m ObjectId parentId = repo.resolve(Constants.HEAD); if (parentId != null) previousCommit = new RevWalk(repo).parseCommit(parentId); } catch (IOException e) { Activator.handleError(UIText.CommitAction_errorRetrievingCommit, e, true); } }
From source file:org.eclipse.egit.ui.internal.actions.CommitActionHandler.java
License:Open Source License
private void buildIndexHeadDiffList(IProject[] selectedProjects, IProgressMonitor monitor) throws IOException, OperationCanceledException { HashMap<Repository, HashSet<IProject>> repositories = new HashMap<Repository, HashSet<IProject>>(); for (IProject project : selectedProjects) { RepositoryMapping repositoryMapping = RepositoryMapping.getMapping(project); assert repositoryMapping != null; Repository repository = repositoryMapping.getRepository(); HashSet<IProject> projects = repositories.get(repository); if (projects == null) { projects = new HashSet<IProject>(); repositories.put(repository, projects); }/*from w w w . j ava 2s .c om*/ projects.add(project); } monitor.beginTask(UIText.CommitActionHandler_caculatingChanges, repositories.size()); for (Map.Entry<Repository, HashSet<IProject>> entry : repositories.entrySet()) { Repository repository = entry.getKey(); monitor.subTask(NLS.bind(UIText.CommitActionHandler_repository, repository.getDirectory().getPath())); HashSet<IProject> projects = entry.getValue(); IndexDiff indexDiff = new IndexDiff(repository, Constants.HEAD, IteratorService.createInitialIterator(repository)); indexDiff.diff(); indexDiffs.put(repository, indexDiff); for (IProject project : projects) { includeList(project, indexDiff.getAdded(), indexChanges); includeList(project, indexDiff.getChanged(), indexChanges); includeList(project, indexDiff.getRemoved(), indexChanges); includeList(project, indexDiff.getMissing(), notIndexed); includeList(project, indexDiff.getModified(), notIndexed); includeList(project, indexDiff.getUntracked(), notTracked); } if (monitor.isCanceled()) throw new OperationCanceledException(); monitor.worked(1); } monitor.done(); }
From source file:org.eclipse.egit.ui.internal.actions.CompareIndexWithHeadActionHandler.java
License:Open Source License
private boolean isStaged(Repository repository, IPath location) { String resRelPath = RepositoryMapping.getMapping(location).getRepoRelativePath(location); // This action at the moment only works for files anyway if (resRelPath == null || resRelPath.length() == 0) { return false; }//from w w w. ja v a 2 s. c o m try { FileTreeIterator fileTreeIterator = new FileTreeIterator(repository); IndexDiff indexDiff = new IndexDiff(repository, Constants.HEAD, fileTreeIterator); indexDiff.setFilter(PathFilterGroup.createFromStrings(Collections.singletonList(resRelPath))); indexDiff.diff(); return indexDiff.getAdded().contains(resRelPath) || indexDiff.getChanged().contains(resRelPath) || indexDiff.getRemoved().contains(resRelPath); } catch (IOException e) { Activator.error(NLS.bind(UIText.GitHistoryPage_errorLookingUpPath, location.toString()), e); return false; } }
From source file:org.eclipse.egit.ui.internal.actions.CompareWithHeadAction.java
License:Open Source License
public void execute(IAction action) throws InvocationTargetException { final IResource resource = getSelectedResources()[0]; final RepositoryMapping mapping = RepositoryMapping.getMapping(resource.getProject()); final Repository repository = mapping.getRepository(); final String gitPath = mapping.getRepoRelativePath(resource); final IFile baseFile = (IFile) resource; final ITypedElement base = SaveableCompareEditorInput.createFileElement(baseFile); ITypedElement next;// ww w. j a v a 2 s . c om try { Ref head = repository.getRef(Constants.HEAD); RevWalk rw = new RevWalk(repository); RevCommit commit = rw.parseCommit(head.getObjectId()); next = CompareUtils.getFileRevisionTypedElement(gitPath, commit, repository); } catch (IOException e) { // this exception is handled by TeamAction.run throw new InvocationTargetException(e); } final GitCompareFileRevisionEditorInput in = new GitCompareFileRevisionEditorInput(base, next, null); CompareUI.openCompareEditor(in); }
From source file:org.eclipse.egit.ui.internal.actions.CompareWithHeadActionHandler.java
License:Open Source License
public Object execute(ExecutionEvent event) throws ExecutionException { final IResource resource = getSelectedResources(event)[0]; final RepositoryMapping mapping = RepositoryMapping.getMapping(resource.getProject()); final Repository repository = mapping.getRepository(); final String gitPath = mapping.getRepoRelativePath(resource); final IFile baseFile = (IFile) resource; final ITypedElement base = SaveableCompareEditorInput.createFileElement(baseFile); ITypedElement next;/* w ww . j a v a 2s. co m*/ try { Ref head = repository.getRef(Constants.HEAD); RevWalk rw = new RevWalk(repository); RevCommit commit = rw.parseCommit(head.getObjectId()); next = CompareUtils.getFileRevisionTypedElement(gitPath, commit, repository); } catch (IOException e) { Activator.handleError(e.getMessage(), e, true); return null; } final GitCompareFileRevisionEditorInput in = new GitCompareFileRevisionEditorInput(base, next, null); CompareUI.openCompareEditor(in); return null; }
From source file:org.eclipse.egit.ui.internal.actions.MergeAction.java
License:Open Source License
private boolean canMerge(final Repository repository) { String message = null;/*from w ww . ja v a2 s.c o m*/ try { Ref head = repository.getRef(Constants.HEAD); if (head == null || !head.isSymbolic()) message = UIText.MergeAction_HeadIsNoBranch; else if (!repository.getRepositoryState().equals(RepositoryState.SAFE)) message = NLS.bind(UIText.MergeAction_WrongRepositoryState, repository.getRepositoryState()); } catch (IOException e) { Activator.logError(e.getMessage(), e); message = e.getMessage(); } if (message != null) { MessageDialog.openError(getShell(), UIText.MergeAction_CannotMerge, message); } return (message == null); }
From source file:org.eclipse.egit.ui.internal.actions.PushBranchActionHandler.java
License:Open Source License
@Override public boolean isEnabled() { Repository repository = getRepository(); if (repository == null) { return false; }/* w w w .j a v a 2s . co m*/ try { Ref head = repository.exactRef(Constants.HEAD); if (head != null && head.getObjectId() != null) { return true; } } catch (IOException e) { Activator.logError(e.getMessage(), e); } return false; }
From source file:org.eclipse.egit.ui.internal.actions.PushUpstreamOrBranchActionHandler.java
License:Open Source License
private static Ref getHeadIfSymbolic(Repository repository) { try {//from w w w . ja v a 2 s .c o m Ref head = repository.exactRef(Constants.HEAD); if (head != null && head.isSymbolic()) return head; else return null; } catch (IOException e) { return null; } }