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:com.rimerosolutions.ant.git.tasks.UpToDateTask.java
License:Apache License
@Override protected void doExecute() throws BuildException { Repository repo = git.getRepository(); FileTreeIterator workingTreeIterator = new FileTreeIterator(repo); try {//from w w w. j av a 2s .c o m IndexDiff diff = new IndexDiff(repo, Constants.HEAD, workingTreeIterator); diff.diff(); Status status = new Status(diff); if (!status.isClean()) { if (modificationExistProperty != null) { getProject().setProperty(modificationExistProperty, "true"); } if (isFailOnError()) { StringBuilder msg = new StringBuilder(); msg.append("The Git tree was modified."); msg.append("\n").append("Changed:").append(status.getChanged()); msg.append("\n").append("Added:").append(status.getAdded()); msg.append("\n").append("Modified:").append(status.getModified()); msg.append("\n").append("Missing:").append(status.getMissing()); msg.append("\n").append("Removed:").append(status.getRemoved()); msg.append("\n").append("Untracked:").append(status.getUntracked()); throw new GitBuildException(String.format(STATUS_NOT_CLEAN_TEMPLATE, msg.toString())); } } else { log(MESSAGE_UPTODATE_SUCCESS); } } catch (IOException ioe) { throw new GitBuildException(MESSAGE_UPTODATE_FAILED, ioe); } }
From source file:com.smartitengineering.version.impl.jgit.JGitImpl.java
License:Open Source License
protected Tree getHeadTree(Repository repository) throws IOException { Tree head;//from www .j av a 2s .c o m org.eclipse.jgit.lib.Commit headCommit = repository.mapCommit(Constants.HEAD); if (headCommit == null) { head = new Tree(repository); } else { head = headCommit.getTree(); } return head; }
From source file:com.smartitengineering.version.impl.jgit.JGitImpl.java
License:Open Source License
protected void performCommit(final Commit newCommit, final Tree head) throws IOException { ObjectId[] parentIds;//from w ww . jav a 2 s. c o m ObjectId currentHeadId = getWriteRepository().resolve(Constants.HEAD); if (currentHeadId != null) { parentIds = new ObjectId[] { currentHeadId }; } else { parentIds = new ObjectId[0]; } org.eclipse.jgit.lib.Commit commit = new org.eclipse.jgit.lib.Commit(getWriteRepository(), parentIds); commit.setTree(head); commit.setTreeId(head.getId()); PersonIdent person = new PersonIdent(newCommit.getAuthor().getName(), newCommit.getAuthor().getEmail()); commit.setAuthor(person); commit.setCommitter(person); commit.setMessage(newCommit.getCommitMessage()); ObjectId newCommitId = getObjectWriter().writeCommit(commit); if (newCommit instanceof MutableCommit) { MutableCommit mutableCommit = (MutableCommit) newCommit; mutableCommit.setCommitId(ObjectId.toString(newCommitId)); mutableCommit.setCommitTime(commit.getCommitter().getWhen()); commit.setCommitId(newCommitId); if (commit.getParentIds().length > 0) { mutableCommit.setParentCommitId(ObjectId.toString(commit.getParentIds()[0])); } else { mutableCommit.setParentCommitId(ObjectId.toString(ObjectId.zeroId())); } } else { throw new IllegalArgumentException("SPI not implemented by API!"); } RefUpdate refUpdate = getWriteRepository().updateRef(Constants.HEAD); refUpdate.setNewObjectId(commit.getCommitId()); refUpdate.setRefLogMessage(commit.getMessage(), false); refUpdate.forceUpdate(); }
From source file:com.smartitengineering.version.impl.jgit.JGitImpl.java
License:Open Source License
protected void prepareCommit(final Tree head, final Commit commit) throws IOException, IOException { ObjectId currentHeadId = getWriteRepository().resolve(Constants.HEAD); boolean commitAvailable = true; if (currentHeadId != null) { org.eclipse.jgit.lib.Commit headCommit = writeRepository.mapCommit(currentHeadId); if (headCommit != null) { Tree headTree = headCommit.getTree(); if (headTree != null && head.getId().equals(headTree.getId())) { commitAvailable = false; }/*from ww w . j ava 2s. c o m*/ } } if (commitAvailable || getConfig().isAllowNoChangeCommit()) { performCommit(commit, head); } }
From source file:com.smartitengineering.version.impl.jgit.JGitImpl.java
License:Open Source License
protected Set<ObjectId> getGraphForResourceId(String resourceId) throws MissingObjectException, IncorrectObjectTypeException, IOException { final Set<ObjectId> versions = new LinkedHashSet<ObjectId>(); final RevWalk rw = new RevWalk(getReadRepository()); final TreeWalk tw = new TreeWalk(getReadRepository()); rw.markStart(rw.parseCommit(getReadRepository().resolve(Constants.HEAD))); tw.setFilter(TreeFilter.ANY_DIFF);/*w ww.java2s .co m*/ RevCommit c; while ((c = rw.next()) != null) { final ObjectId[] p = new ObjectId[c.getParentCount() + 1]; for (int i = 0; i < c.getParentCount(); i++) { rw.parseAny(c.getParent(i)); p[i] = c.getParent(i).getTree(); } final int me = p.length - 1; p[me] = c.getTree(); tw.reset(p); while (tw.next()) { if (tw.getFileMode(me).getObjectType() == Constants.OBJ_BLOB) { // This path was modified relative to the ancestor(s) String s = tw.getPathString(); if (s != null && s.equals(resourceId)) { versions.add(tw.getObjectId(me)); } } if (tw.isSubtree()) { // make sure we recurse into modified directories tw.enterSubtree(); } } } return versions; }
From source file:com.stormcloud.ide.api.git.GitManager.java
License:Open Source License
@Override public void log(String repo) throws GitManagerException { try {//www . j a v a2s .c om File gitDir = new File(repo + "/.git"); LOG.info("gitDir:" + gitDir); Repository repository = new FileRepository(gitDir); WorkingTreeIterator fileTreeIterator = new FileTreeIterator(repository); IndexDiff indexDiff = new IndexDiff(repository, Constants.HEAD, fileTreeIterator); boolean hasDiff = indexDiff.diff(); LOG.info("hasDiff " + hasDiff); if (hasDiff) { for (String file : indexDiff.getAdded()) { LOG.info("Added " + file); } for (String file : indexDiff.getAssumeUnchanged()) { LOG.info("Assume Unchanged " + file); } for (String file : indexDiff.getChanged()) { LOG.info("Changed " + file); } for (String file : indexDiff.getConflicting()) { LOG.info("Conflicting " + file); } for (String file : indexDiff.getIgnoredNotInIndex()) { LOG.info("Ignored not in index " + file); } for (String file : indexDiff.getMissing()) { LOG.info("Missing " + file); } for (String file : indexDiff.getModified()) { LOG.info("Modified " + file); } for (String file : indexDiff.getRemoved()) { LOG.info("Removed " + file); } for (String file : indexDiff.getUntracked()) { LOG.info("Untracked " + file); } for (String file : indexDiff.getUntrackedFolders()) { LOG.info("Untracked Folders " + file); } } } catch (IOException e) { LOG.error(e); throw new GitManagerException(e); } }
From source file:com.tnd.eso.integration.scm.scripts.repository.GitParser.java
License:Open Source License
protected GitParser() { try {//from w ww .jav a 2s . c o m gitWorkDir = new File(dir); git = Git.open(gitWorkDir); repo = git.getRepository(); // get head commit hash ObjectId lastCommitId = repo.resolve(Constants.HEAD); RevWalk revWalk = new RevWalk(repo); RevCommit commit = revWalk.parseCommit(lastCommitId); head = commit.getName().substring(0, 7); revWalk.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.tnd.eso.integration.scm.scripts.repository.GitParser.java
License:Open Source License
public String getLastCommitRevision(String fileName) { try {// w w w .j av a 2 s . co m LogCommand logCommand = git.log().add(repo.resolve(Constants.HEAD)).addPath(fileName); for (RevCommit revCommit : logCommand.call()) { return head + "-" + revCommit.getName().substring(0, 7); } return null; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.verigreen.collector.decision.CheckinDecisionHandler.java
License:Apache License
private Pair<Boolean, String> createBranchAndMergeWithParent(String mergedBranchName, SourceControlOperator sourceControlOperator) { String parent = _commitItem.getParent() == null ? Constants.HEAD : _commitItem.getParent().getMergedBranchName(); sourceControlOperator.createBranch(parent, mergedBranchName); // switch to the new branch and merge latest commit sourceControlOperator.checkout(mergedBranchName, false, false); // false return sourceControlOperator.merge(mergedBranchName, _commitItem.getBranchDescriptor().getNewBranch()); }
From source file:controller.ReadmeWindowController.java
@Override public void setParentController(Initializable parent) { super.setParentController(parent); //To change body of generated methods, choose Tools | Templates. MainWindowController controller = (MainWindowController) parentController; try {/*from ww w . j av a2 s. co m*/ readmeArea.setText(GitFacade.getReadmeFromCommit(controller.repository, controller.repository.resolve(Constants.HEAD))); } catch (Exception ex) { Logger.getLogger(ReadmeWindowController.class.getName()).log(Level.SEVERE, null, ex); } }