List of usage examples for org.eclipse.jgit.api.errors NoFilepatternException NoFilepatternException
public NoFilepatternException(String message)
From source file:com.mangosolutions.rcloud.rawgist.repository.git.BareAddCommand.java
@Override public DirCache call() throws GitAPIException { if (filepatterns.isEmpty()) { throw new NoFilepatternException(JGitText.get().atLeastOnePatternIsRequired); }/*from ww w . java 2s. c o m*/ checkCallable(); boolean addAll = filepatterns.contains("."); //$NON-NLS-1$ try (ObjectInserter inserter = repo.newObjectInserter(); NameConflictTreeWalk tw = new NameConflictTreeWalk(repo)) { tw.setOperationType(OperationType.CHECKIN_OP); dirCache.lock(); DirCacheBuilder builder = dirCache.builder(); tw.addTree(new DirCacheBuildIterator(builder)); if (workingTreeIterator == null) workingTreeIterator = new FileTreeIterator(repo); workingTreeIterator.setDirCacheIterator(tw, 0); tw.addTree(workingTreeIterator); if (!addAll) { tw.setFilter(PathFilterGroup.createFromStrings(filepatterns)); } byte[] lastAdded = null; while (tw.next()) { DirCacheIterator c = tw.getTree(0, DirCacheIterator.class); WorkingTreeIterator f = tw.getTree(1, WorkingTreeIterator.class); if (c == null && f != null && f.isEntryIgnored()) { // file is not in index but is ignored, do nothing continue; } else if (c == null && update) { // Only update of existing entries was requested. continue; } DirCacheEntry entry = c != null ? c.getDirCacheEntry() : null; if (entry != null && entry.getStage() > 0 && lastAdded != null && lastAdded.length == tw.getPathLength() && tw.isPathPrefix(lastAdded, lastAdded.length) == 0) { // In case of an existing merge conflict the // DirCacheBuildIterator iterates over all stages of // this path, we however want to add only one // new DirCacheEntry per path. continue; } if (tw.isSubtree() && !tw.isDirectoryFileConflict()) { tw.enterSubtree(); continue; } if (f == null) { // working tree file does not exist if (entry != null && (!update || GITLINK == entry.getFileMode())) { builder.add(entry); } continue; } if (entry != null && entry.isAssumeValid()) { // Index entry is marked assume valid. Even though // the user specified the file to be added JGit does // not consider the file for addition. builder.add(entry); continue; } if ((f.getEntryRawMode() == TYPE_TREE && f.getIndexFileMode(c) != FileMode.GITLINK) || (f.getEntryRawMode() == TYPE_GITLINK && f.getIndexFileMode(c) == FileMode.TREE)) { // Index entry exists and is symlink, gitlink or file, // otherwise the tree would have been entered above. // Replace the index entry by diving into tree of files. tw.enterSubtree(); continue; } byte[] path = tw.getRawPath(); if (entry == null || entry.getStage() > 0) { entry = new DirCacheEntry(path); } FileMode mode = f.getIndexFileMode(c); entry.setFileMode(mode); if (GITLINK != mode) { entry.setLength(f.getEntryLength()); entry.setLastModified(f.getEntryLastModified()); long len = f.getEntryContentLength(); try (InputStream in = f.openEntryStream()) { ObjectId id = inserter.insert(OBJ_BLOB, len, in); entry.setObjectId(id); } } else { entry.setLength(0); entry.setLastModified(0); entry.setObjectId(f.getEntryObjectId()); } builder.add(entry); lastAdded = path; } inserter.flush(); builder.commit(); setCallable(false); } catch (IOException e) { Throwable cause = e.getCause(); if (cause != null && cause instanceof FilterFailedException) throw (FilterFailedException) cause; throw new JGitInternalException(JGitText.get().exceptionCaughtDuringExecutionOfAddCommand, e); } finally { if (dirCache != null) { dirCache.unlock(); } } return dirCache; }
From source file:com.mangosolutions.rcloud.rawgist.repository.git.BareRmCommand.java
/** * Executes the {@code Rm} command. Each instance of this class should only * be used for one invocation of the command. Don't call this method twice * on an instance.//from w w w . j av a2 s . co m * * @return the DirCache after Rm */ public DirCache call() throws GitAPIException, NoFilepatternException { if (filepatterns.isEmpty()) { throw new NoFilepatternException(JGitText.get().atLeastOnePatternIsRequired); } checkCallable(); try (final TreeWalk tw = new TreeWalk(repo)) { index.lock(); DirCacheBuilder builder = index.builder(); tw.reset(); // drop the first empty tree, which we do not need here tw.setRecursive(true); tw.setFilter(PathFilterGroup.createFromStrings(filepatterns)); tw.addTree(new DirCacheBuildIterator(builder)); while (tw.next()) { if (!cached) { final FileMode mode = tw.getFileMode(0); if (mode.getObjectType() == Constants.OBJ_BLOB) { final File path = new File(repo.getWorkTree(), tw.getPathString()); // Deleting a blob is simply a matter of removing // the file or symlink named by the tree entry. delete(path); } } } builder.commit(); setCallable(false); } catch (IOException e) { throw new JGitInternalException(JGitText.get().exceptionCaughtDuringExecutionOfRmCommand, e); } finally { if (index != null) { index.unlock(); } } return index; }
From source file:org.oecd.ant.git.custom.CustomAddCommand.java
License:Eclipse Distribution License
/** * Executes the {@code Add} command. Each instance of this class should only be used for one invocation of the command. Don't call this method twice on an * instance./* ww w .java 2s .c om*/ * * @return the DirCache after Add */ @Override public DirCache call() throws GitAPIException, NoFilepatternException { if (filepatterns.isEmpty()) throw new NoFilepatternException(JGitText.get().atLeastOnePatternIsRequired); checkCallable(); DirCache dc = null; boolean addAll = false; if (filepatterns.contains(".")) //$NON-NLS-1$ addAll = true; try (ObjectInserter inserter = repo.newObjectInserter(); final TreeWalk tw = new TreeWalk(repo)) { dc = repo.lockDirCache(); DirCacheIterator c; DirCacheBuilder builder = dc.builder(); tw.addTree(new DirCacheBuildIterator(builder)); if (workingTreeIterator == null) workingTreeIterator = new FileTreeIterator(repo); tw.addTree(workingTreeIterator); tw.setRecursive(true); if (!addAll) tw.setFilter(PathFilterGroup.createFromStrings(filepatterns)); String lastAddedFile = null; while (tw.next()) { String path = tw.getPathString(); WorkingTreeIterator f = tw.getTree(1, WorkingTreeIterator.class); if (tw.getTree(0, DirCacheIterator.class) == null && f != null && f.isEntryIgnored()) { // file is not in index but is ignored, do nothing } // In case of an existing merge conflict the // DirCacheBuildIterator iterates over all stages of // this path, we however want to add only one // new DirCacheEntry per path. else if (!(path.equals(lastAddedFile))) { if (all || !(update && tw.getTree(0, DirCacheIterator.class) == null)) { c = tw.getTree(0, DirCacheIterator.class); if (f != null) { // the file exists long sz = f.getEntryLength(); DirCacheEntry entry = new DirCacheEntry(path); if (c == null || c.getDirCacheEntry() == null || !c.getDirCacheEntry().isAssumeValid()) { FileMode mode = f.getIndexFileMode(c); entry.setFileMode(mode); if (FileMode.GITLINK != mode) { entry.setLength(sz); entry.setLastModified(f.getEntryLastModified()); long contentSize = f.getEntryContentLength(); InputStream in = f.openEntryStream(); try { entry.setObjectId(inserter.insert(Constants.OBJ_BLOB, contentSize, in)); } finally { in.close(); } } else entry.setObjectId(f.getEntryObjectId()); builder.add(entry); lastAddedFile = path; } else { builder.add(c.getDirCacheEntry()); } } else if (c != null && (!(all || update) || FileMode.GITLINK == c.getEntryFileMode())) builder.add(c.getDirCacheEntry()); } } } inserter.flush(); builder.commit(); setCallable(false); } catch (IOException e) { throw new JGitInternalException(JGitText.get().exceptionCaughtDuringExecutionOfAddCommand, e); } finally { if (dc != null) dc.unlock(); } return dc; }