List of usage examples for org.eclipse.jgit.lib FileMode TYPE_TREE
int TYPE_TREE
To view the source code for org.eclipse.jgit.lib FileMode TYPE_TREE.
Click Source Link
From source file:com.buildautomation.jgit.api.ListFilesOfCommitAndTag.java
License:Apache License
private static List<String> readElementsAt(Repository repository, String commit, String path) throws IOException { RevCommit revCommit = buildRevCommit(repository, commit); // and using commit's tree find the path RevTree tree = revCommit.getTree();/*from w ww . j ava 2 s . c o m*/ //System.out.println("Having tree: " + tree + " for commit " + commit); List<String> items = new ArrayList<>(); // shortcut for root-path if (path.isEmpty()) { try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree); treeWalk.setRecursive(false); treeWalk.setPostOrderTraversal(false); while (treeWalk.next()) { items.add(treeWalk.getPathString()); } } } else { // now try to find a specific file try (TreeWalk treeWalk = buildTreeWalk(repository, tree, path)) { if ((treeWalk.getFileMode(0).getBits() & FileMode.TYPE_TREE) == 0) { throw new IllegalStateException("Tried to read the elements of a non-tree for commit '" + commit + "' and path '" + path + "', had filemode " + treeWalk.getFileMode(0).getBits()); } try (TreeWalk dirWalk = new TreeWalk(repository)) { dirWalk.addTree(treeWalk.getObjectId(0)); dirWalk.setRecursive(false); while (dirWalk.next()) { items.add(dirWalk.getPathString()); } } } } return items; }
From source file:com.itemis.maven.plugins.unleash.scm.providers.merge.UnleashGitMerger.java
License:Eclipse Distribution License
private boolean isWorktreeDirty(WorkingTreeIterator work, DirCacheEntry ourDce) throws IOException { if (work == null) { return false; }/* ww w . j a v a 2 s.c om*/ final int modeF = this.tw.getRawMode(T_FILE); final int modeO = this.tw.getRawMode(T_OURS); // Worktree entry has to match ours to be considered clean boolean isDirty; if (ourDce != null) { isDirty = work.isModified(ourDce, true, this.reader); } else { isDirty = work.isModeDifferent(modeO); if (!isDirty && nonTree(modeF)) { isDirty = !this.tw.idEqual(T_FILE, T_OURS); } } // Ignore existing empty directories if (isDirty && modeF == FileMode.TYPE_TREE && modeO == FileMode.TYPE_MISSING) { isDirty = false; } if (isDirty) { this.failingPaths.put(this.tw.getPathString(), MergeFailureReason.DIRTY_WORKTREE); } return isDirty; }
From source file:org.kie.commons.java.nio.fs.jgit.util.JGitUtil.java
License:Apache License
public static Pair<PathType, ObjectId> checkPath(final Git git, final String branchName, final String path) { checkNotNull("git", git); checkNotNull("path", path); checkNotEmpty("branchName", branchName); final String gitPath = fixPath(path); if (gitPath.isEmpty()) { return newPair(PathType.DIRECTORY, null); }//www . j a v a 2 s . c o m TreeWalk tw = null; try { final ObjectId tree = git.getRepository().resolve(branchName + "^{tree}"); tw = new TreeWalk(git.getRepository()); tw.setFilter(PathFilter.create(gitPath)); tw.reset(tree); while (tw.next()) { if (tw.getPathString().equals(gitPath)) { if (tw.getFileMode(0).equals(FileMode.TYPE_TREE)) { return newPair(PathType.DIRECTORY, tw.getObjectId(0)); } else if (tw.getFileMode(0).equals(FileMode.TYPE_FILE)) { return newPair(PathType.FILE, tw.getObjectId(0)); } } if (tw.isSubtree()) { tw.enterSubtree(); continue; } } } catch (final Throwable t) { } finally { if (tw != null) { tw.release(); } } return newPair(PathType.NOT_FOUND, null); }
From source file:org.kuali.student.git.model.GitRepositoryUtils.java
License:Educational Community License
/** * Return the JGit ObjectId for the blob or tree represented by the path given. * /* www.j a va 2 s. c o m*/ * The path needs to be relative to the tree provided. * @param repository * @param treeId * @param filePath * @return * @throws MissingObjectException * @throws IncorrectObjectTypeException * @throws CorruptObjectException * @throws IOException */ public static ObjectId findInTree(Repository repository, ObjectId treeId, String filePath) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException { if (treeId == null) return null; String parts[] = filePath.split("/"); int currentPartIndex = 0; TreeWalk tw = new TreeWalk(repository); tw.addTree(treeId); while (tw.next()) { // the part changes when we decend the tree path String currentPart = parts[currentPartIndex]; String pathName = tw.getNameString(); if (currentPart.equals(pathName)) { if ((currentPartIndex + 1) == parts.length) { // at the end so use the current object id. tw.release(); return tw.getObjectId(0); } else { if (tw.getFileMode(0).equals(FileMode.TYPE_TREE)) { tw.enterSubtree(); currentPartIndex++; } else { tw.release(); return null; } } } } tw.release(); return null; }
From source file:org.kuali.student.git.model.tree.utils.GitTreeProcessor.java
License:Educational Community License
public ObjectId getObjectId(ObjectId parentId, String branchSubPath) throws MissingObjectException, IncorrectObjectTypeException, IOException { ObjectId treeId = null;/*from w w w .ja va 2 s .c o m*/ RevWalk rw = new RevWalk(repo); RevCommit parentCommit = rw.parseCommit(parentId); rw.release(); String[] subPathParts = branchSubPath.split("/"); int currentPartIndex = 0; if (branchSubPath != null && !branchSubPath.isEmpty()) { TreeWalk tw = new TreeWalk(repo); tw.addTree(parentCommit.getTree().getId()); while (tw.next()) { String currentPathPart = subPathParts[currentPartIndex]; if (currentPartIndex == (subPathParts.length - 1)) { // on the last element consider blobs String name = tw.getNameString(); if (name.equals(currentPathPart)) { treeId = tw.getObjectId(0); break; } } else { if (tw.getFileMode(0).equals(FileMode.TYPE_TREE)) { String name = tw.getNameString(); if (name.equals(currentPathPart)) { currentPartIndex++; if (currentPartIndex >= subPathParts.length) { // we are done treeId = tw.getObjectId(0); break; } else { tw.enterSubtree(); } } } } } tw.release(); return treeId; } else if (branchSubPath.length() == 0) { return parentCommit.getTree().getId(); } else return null; }
From source file:org.uberfire.java.nio.fs.jgit.util.commands.GetPathInfo.java
License:Apache License
public PathInfo execute() throws IOException { final String gitPath = PathUtil.normalize(path); if (gitPath.isEmpty()) { return new PathInfo(null, gitPath, PathType.DIRECTORY); }// w w w . j a va 2 s . c o m final ObjectId tree = git.getTreeFromRef(branchName); if (tree == null) { return new PathInfo(null, gitPath, PathType.NOT_FOUND); } try (final TreeWalk tw = new TreeWalk(git.getRepository())) { tw.setFilter(PathFilter.create(gitPath)); tw.reset(tree); while (tw.next()) { if (tw.getPathString().equals(gitPath)) { if (tw.getFileMode(0).equals(FileMode.TYPE_TREE)) { return new PathInfo(tw.getObjectId(0), gitPath, PathType.DIRECTORY); } else if (tw.getFileMode(0).equals(FileMode.TYPE_FILE) || tw.getFileMode(0).equals(FileMode.EXECUTABLE_FILE) || tw.getFileMode(0).equals(FileMode.REGULAR_FILE)) { final long size = tw.getObjectReader().getObjectSize(tw.getObjectId(0), OBJ_BLOB); return new PathInfo(tw.getObjectId(0), gitPath, PathType.FILE, size); } } if (tw.isSubtree()) { tw.enterSubtree(); } } } return new PathInfo(null, gitPath, PathType.NOT_FOUND); }
From source file:org.uberfire.java.nio.fs.jgit.util.JGitUtil.java
License:Apache License
public static Pair<PathType, ObjectId> checkPath(final Git git, final String branchName, final String path) { checkNotNull("git", git); checkNotNull("path", path); checkNotEmpty("branchName", branchName); final String gitPath = fixPath(path); if (gitPath.isEmpty()) { return newPair(PathType.DIRECTORY, null); }//from ww w.ja v a 2 s.c o m TreeWalk tw = null; try { final ObjectId tree = git.getRepository().resolve(branchName + "^{tree}"); tw = new TreeWalk(git.getRepository()); tw.setFilter(PathFilter.create(gitPath)); tw.reset(tree); while (tw.next()) { if (tw.getPathString().equals(gitPath)) { if (tw.getFileMode(0).equals(FileMode.TYPE_TREE)) { return newPair(PathType.DIRECTORY, tw.getObjectId(0)); } else if (tw.getFileMode(0).equals(FileMode.TYPE_FILE) || tw.getFileMode(0).equals(FileMode.EXECUTABLE_FILE) || tw.getFileMode(0).equals(FileMode.REGULAR_FILE)) { return newPair(PathType.FILE, tw.getObjectId(0)); } } if (tw.isSubtree()) { tw.enterSubtree(); } } } catch (final Throwable ignored) { } finally { if (tw != null) { tw.release(); } } return newPair(PathType.NOT_FOUND, null); }
From source file:org.uberfire.java.nio.fs.jgit.util.model.PathInfo.java
License:Apache License
private static PathType convert(final FileMode fileMode) { if (fileMode.equals(FileMode.TYPE_TREE)) { return PathType.DIRECTORY; } else if (fileMode.equals(TYPE_FILE)) { return PathType.FILE; }/* w w w . j av a 2 s .c om*/ return null; }