@Signature public Memory findRef(String name) throws IOException { Ref ref = getWrappedObject().getRepository().findRef(name); return ref == null ? Memory.NULL : GitUtils.valueOf(ref); }
private MergeResult merge(Git git, String label) { try { MergeCommand merge = git.merge(); merge.include(git.getRepository().findRef("origin/" + label)); MergeResult result = merge.call(); if (!result.getMergeStatus().isSuccessful()) { this.logger.warn("Merged from remote " + label + " with result " + result.getMergeStatus()); } return result; } catch (Exception ex) { String message = "Could not merge remote for " + label + " remote: " + git .getRepository().getConfig().getString("remote", "origin", "url"); warn(message, ex); return null; } }
return git.getRepository().findRef("HEAD").getObjectId().getName();
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { Ref head = repository.findRef("refs/heads/master"); System.out.println("Found head: " + head); // a RevWalk allows to walk over commits based on some filtering that is defined try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); System.out.println("\nCommit-Message: " + commit.getFullMessage()); walk.dispose(); } } } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { Ref head = repository.findRef("refs/heads/master"); System.out.println("Found head: " + head); // a RevWalk allows to walk over commits based on some filtering that is defined try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); System.out.println("\nCommit-Message: " + commit.getFullMessage()); walk.dispose(); } } } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { // a RevWalk allows to retrieve information from the repository try (RevWalk walk = new RevWalk(repository)) { // a simple tag that is not annotated Ref simpleTag = repository.findRef("initialtag"); RevObject any = walk.parseAny(simpleTag.getObjectId()); System.out.println("Commit: " + any); // an annotated tag Ref annotatedTag = repository.findRef("secondtag"); any = walk.parseAny(annotatedTag.getObjectId()); System.out.println("Tag: " + any); // finally try to print out the tag-content System.out.println("\nTag-Content: \n"); ObjectLoader loader = repository.open(annotatedTag.getObjectId()); loader.copyTo(System.out); walk.dispose(); } } } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { // a RevWalk allows to retrieve information from the repository try (RevWalk walk = new RevWalk(repository)) { // a simple tag that is not annotated Ref simpleTag = repository.findRef("initialtag"); RevObject any = walk.parseAny(simpleTag.getObjectId()); System.out.println("Commit: " + any); // an annotated tag Ref annotatedTag = repository.findRef("secondtag"); any = walk.parseAny(annotatedTag.getObjectId()); System.out.println("Tag: " + any); // finally try to print out the tag-content System.out.println("\nTag-Content: \n"); ObjectLoader loader = repository.open(annotatedTag.getObjectId()); loader.copyTo(System.out); walk.dispose(); } } } }
/** {@inheritDoc} */ @Override public List<Note> call() throws GitAPIException { checkCallable(); List<Note> notes = new ArrayList<>(); NoteMap map = NoteMap.newEmptyMap(); try (RevWalk walk = new RevWalk(repo)) { Ref ref = repo.findRef(notesRef); // if we have a notes ref, use it if (ref != null) { RevCommit notesCommit = walk.parseCommit(ref.getObjectId()); map = NoteMap.read(walk.getObjectReader(), notesCommit); } Iterator<Note> i = map.iterator(); while (i.hasNext()) notes.add(i.next()); } catch (IOException e) { throw new JGitInternalException(e.getMessage(), e); } return notes; }
public static void main(String[] args) throws IOException, GitAPIException { final File localPath; try (Repository repository = cloneRepository()) { localPath = repository.getWorkTree(); System.out.println("Having repository: " + repository.getDirectory() + " with head: " + repository.findRef(Constants.HEAD) + "/" + repository.resolve("HEAD") + "/" + repository.resolve("refs/heads/master")); // TODO: why do we get null here for HEAD?!? See also // http://stackoverflow.com/questions/17979660/jgit-pull-noheadexception try (Git git = new Git(repository)) { PullResult call = git.pull().call(); System.out.println("Pulled from the remote repository: " + call); } } // clean up here to not keep using more and more disk-space for these samples FileUtils.deleteDirectory(localPath); }
public static void main(String[] args) throws IOException, GitAPIException { final File localPath; try (Repository repository = cloneRepository()) { localPath = repository.getWorkTree(); System.out.println("Having repository: " + repository.getDirectory() + " with head: " + repository.findRef(Constants.HEAD) + "/" + repository.resolve("HEAD") + "/" + repository.resolve("refs/heads/master")); // TODO: why do we get null here for HEAD?!? See also // http://stackoverflow.com/questions/17979660/jgit-pull-noheadexception try (Git git = new Git(repository)) { PullResult call = git.pull().call(); System.out.println("Pulled from the remote repository: " + call); } } // clean up here to not keep using more and more disk-space for these samples FileUtils.deleteDirectory(localPath); }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { // See e.g. GetRevCommitFromObjectId for how to use a SHA-1 directly Ref head = repository.findRef("HEAD"); System.out.println("Ref of HEAD: " + head + ": " + head.getName() + " - " + head.getObjectId().getName()); // a RevWalk allows to walk over commits based on some filtering that is defined try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); System.out.println("Commit: " + commit); // a commit points to a tree RevTree tree = walk.parseTree(commit.getTree().getId()); System.out.println("Found Tree: " + tree); walk.dispose(); } } } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { // See e.g. GetRevCommitFromObjectId for how to use a SHA-1 directly Ref head = repository.findRef("HEAD"); System.out.println("Ref of HEAD: " + head + ": " + head.getName() + " - " + head.getObjectId().getName()); // a RevWalk allows to walk over commits based on some filtering that is defined try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); System.out.println("Commit: " + commit); // a commit points to a tree RevTree tree = walk.parseTree(commit.getTree().getId()); System.out.println("Found Tree: " + tree); walk.dispose(); } } } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { Ref head = repository.findRef("HEAD"); // a RevWalk allows to walk over commits based on some filtering that is defined try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); RevTree tree = commit.getTree(); System.out.println("Having tree: " + tree); // now use a TreeWalk to iterate over all files in the Tree recursively // you can set Filters to narrow down the results if needed try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree); treeWalk.setRecursive(true); while (treeWalk.next()) { System.out.println("found: " + treeWalk.getPathString()); } } } } } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { Ref head = repository.findRef("HEAD"); // a RevWalk allows to walk over commits based on some filtering that is defined try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); RevTree tree = commit.getTree(); System.out.println("Having tree: " + tree); // now use a TreeWalk to iterate over all files in the Tree // you can set Filters to narrow down the results if needed try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree); // not walk the tree recursively so we only get the elements in the top-level directory treeWalk.setRecursive(false); while (treeWalk.next()) { System.out.println("found: " + treeWalk.getPathString()); } } } } } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { Ref head = repository.findRef("HEAD"); // a RevWalk allows to walk over commits based on some filtering that is defined try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); RevTree tree = commit.getTree(); System.out.println("Having tree: " + tree); // now use a TreeWalk to iterate over all files in the Tree recursively // you can set Filters to narrow down the results if needed try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree); treeWalk.setRecursive(true); while (treeWalk.next()) { System.out.println("found: " + treeWalk.getPathString()); } } } } } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { Ref head = repository.findRef("HEAD"); // a RevWalk allows to walk over commits based on some filtering that is defined try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); RevTree tree = commit.getTree(); System.out.println("Having tree: " + tree); // now use a TreeWalk to iterate over all files in the Tree // you can set Filters to narrow down the results if needed try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree); // not walk the tree recursively so we only get the elements in the top-level directory treeWalk.setRecursive(false); while (treeWalk.next()) { System.out.println("found: " + treeWalk.getPathString()); } } } } } }
@Override public void prepareGitToExtractMoreDetailedRepoInformation() throws GitCommitIdExecutionException { try { // more details parsed out bellow Ref evaluateOnCommitReference = git.findRef(evaluateOnCommit); ObjectId evaluateOnCommitResolvedObjectId = git.resolve(evaluateOnCommit); if ((evaluateOnCommitReference == null) && (evaluateOnCommitResolvedObjectId == null)) { throw new GitCommitIdExecutionException("Could not get " + evaluateOnCommit + " Ref, are you sure you have set the dotGitDirectory property of this plugin to a valid path?"); } revWalk = new RevWalk(git); ObjectId headObjectId; if (evaluateOnCommitReference != null) { headObjectId = evaluateOnCommitReference.getObjectId(); } else { headObjectId = evaluateOnCommitResolvedObjectId; } if (headObjectId == null) { throw new GitCommitIdExecutionException("Could not get " + evaluateOnCommit + " Ref, are you sure you have some commits in the dotGitDirectory?"); } evalCommit = revWalk.parseCommit(headObjectId); revWalk.markStart(evalCommit); } catch (Exception e) { throw new GitCommitIdExecutionException("Error", e); } }
/** {@inheritDoc} */ @Override public Note call() throws GitAPIException { checkCallable(); NoteMap map = NoteMap.newEmptyMap(); RevCommit notesCommit = null; try (RevWalk walk = new RevWalk(repo); ObjectInserter inserter = repo.newObjectInserter()) { Ref ref = repo.findRef(notesRef); // if we have a notes ref, use it if (ref != null) { notesCommit = walk.parseCommit(ref.getObjectId()); map = NoteMap.read(walk.getObjectReader(), notesCommit); } map.set(id, message, inserter); commitNoteMap(repo, notesRef, walk, map, notesCommit, inserter, "Notes added by 'git notes add'"); //$NON-NLS-1$ return map.getNote(id); } catch (IOException e) { throw new JGitInternalException(e.getMessage(), e); } }
private void updateStashRef(ObjectId commitId, PersonIdent refLogIdent, String refLogMessage) throws IOException { if (ref == null) return; Ref currentRef = repo.findRef(ref); RefUpdate refUpdate = repo.updateRef(ref); refUpdate.setNewObjectId(commitId); refUpdate.setRefLogIdent(refLogIdent); refUpdate.setRefLogMessage(refLogMessage, false); refUpdate.setForceRefLog(true); if (currentRef != null) refUpdate.setExpectedOldObjectId(currentRef.getObjectId()); else refUpdate.setExpectedOldObjectId(ObjectId.zeroId()); refUpdate.forceUpdate(); }
/** * Get latest commit by ref name from local .git */ @Override public GitCommit commit(String refName) throws GitException { try (Git git = gitOpen()) { Repository repo = git.getRepository(); Ref head = repo.findRef(refName); if (head == null) { return null; } try (RevWalk walk = new RevWalk(repo)) { RevCommit commit = walk.parseCommit(head.getObjectId()); walk.dispose(); String id = commit.getId().getName(); String message = commit.getFullMessage(); String author = commit.getAuthorIdent().getName(); return new GitCommit(id, message, author); } } catch (IOException e) { throw new GitException("Fail to get commit message", e); } }