Package org.eclipse.jgit.dircache

Examples of org.eclipse.jgit.dircache.DirCacheEditor$DeleteTree


    writeTrashFile("file.txt", "content");
    git.add().addFilepattern("file.txt").call();
    final RevCommit id = git.commit().setMessage("create file").call();
    final String path = "sub";
    DirCache cache = db.lockDirCache();
    DirCacheEditor editor = cache.editor();
    editor.add(new PathEdit(path) {

      public void apply(DirCacheEntry ent) {
        ent.setFileMode(FileMode.GITLINK);
        ent.setObjectId(id);
      }
    });
    editor.commit();

    assertNotNull(Git.init().setDirectory(new File(db.getWorkTree(), path))
        .call().getRepository());

    TreeWalk walk = new TreeWalk(db);
View Full Code Here


    writeTrashFile("file.txt", "content");
    git.add().addFilepattern("file.txt").call();
    final RevCommit id = git.commit().setMessage("create file").call();
    final String path = "sub";
    DirCache cache = db.lockDirCache();
    DirCacheEditor editor = cache.editor();
    editor.add(new PathEdit(path) {

      public void apply(DirCacheEntry ent) {
        ent.setFileMode(FileMode.GITLINK);
        ent.setObjectId(id);
      }
    });
    editor.commit();

    Git.cloneRepository().setURI(db.getDirectory().toURI().toString())
        .setDirectory(new File(db.getWorkTree(), path)).call()
        .getRepository().close();
View Full Code Here

    writeTrashFile("file.txt", "content");
    git.add().addFilepattern("file.txt").call();
    final RevCommit id = git.commit().setMessage("create file").call();
    final String path = "sub/dir1/dir2";
    DirCache cache = db.lockDirCache();
    DirCacheEditor editor = cache.editor();
    editor.add(new PathEdit(path) {

      public void apply(DirCacheEntry ent) {
        ent.setFileMode(FileMode.GITLINK);
        ent.setObjectId(id);
      }
    });
    editor.commit();

    Git.cloneRepository().setURI(db.getDirectory().toURI().toString())
        .setDirectory(new File(db.getWorkTree(), path)).call()
        .getRepository().close();
View Full Code Here

  private void buildIndex(HashMap<String, String> indexEntries) throws IOException {
    dirCache = new DirCache(db.getIndexFile(), db.getFS());
    if (indexEntries != null) {
      assertTrue(dirCache.lock());
      DirCacheEditor editor = dirCache.editor();
      for (java.util.Map.Entry<String,String> e : indexEntries.entrySet()) {
        writeTrashFile(e.getKey(), e.getValue());
        ObjectInserter inserter = db.newObjectInserter();
        final ObjectId id = inserter.insert(Constants.OBJ_BLOB,
            Constants.encode(e.getValue()));
        editor.add(new DirCacheEditor.DeletePath(e.getKey()));
        editor.add(new DirCacheEditor.PathEdit(e.getKey()) {
          @Override
          public void apply(DirCacheEntry ent) {
            ent.setFileMode(FileMode.REGULAR_FILE);
            ent.setObjectId(id);
            ent.setUpdateNeeded(false);
          }
        });
      }
      assertTrue(editor.commit());
    }

  }
View Full Code Here

  private ObjectId buildTree(HashMap<String, String> headEntries)
      throws IOException {
    DirCache lockDirCache = DirCache.newInCore();
    // assertTrue(lockDirCache.lock());
    DirCacheEditor editor = lockDirCache.editor();
    if (headEntries != null) {
      for (java.util.Map.Entry<String, String> e : headEntries.entrySet()) {
        AddEdit addEdit = new AddEdit(e.getKey(),
            genSha1(e.getValue()), e.getValue().length());
        editor.add(addEdit);
      }
    }
    editor.finish();
    return lockDirCache.writeTree(db.newObjectInserter());
  }
View Full Code Here

      throws IOException {
    DirCacheIterator dci = new DirCacheIterator(dc);
    treeWalk.addTree(dci);

    final ObjectReader r = treeWalk.getObjectReader();
    DirCacheEditor editor = dc.editor();
    while (treeWalk.next()) {
      DirCacheEntry entry = dci.getDirCacheEntry();
      // Only add one edit per path
      if (entry != null && entry.getStage() > DirCacheEntry.STAGE_1)
        continue;
      editor.add(new PathEdit(treeWalk.getPathString()) {
        public void apply(DirCacheEntry ent) {
          int stage = ent.getStage();
          if (stage > DirCacheEntry.STAGE_0) {
            if (checkoutStage != null) {
              if (stage == checkoutStage.number)
                checkoutPath(ent, r);
            } else {
              UnmergedPathException e = new UnmergedPathException(
                  ent);
              throw new JGitInternalException(e.getMessage(), e);
            }
          } else {
            checkoutPath(ent, r);
          }
        }
      });
    }
    editor.commit();
  }
View Full Code Here

  private void checkoutPathsFromCommit(TreeWalk treeWalk, DirCache dc,
      RevCommit commit) throws IOException {
    treeWalk.addTree(commit.getTree());
    final ObjectReader r = treeWalk.getObjectReader();
    DirCacheEditor editor = dc.editor();
    while (treeWalk.next()) {
      final ObjectId blobId = treeWalk.getObjectId(0);
      final FileMode mode = treeWalk.getFileMode(0);
      editor.add(new PathEdit(treeWalk.getPathString()) {
        public void apply(DirCacheEntry ent) {
          ent.setObjectId(blobId);
          ent.setFileMode(mode);
          checkoutPath(ent, r);
        }
      });
    }
    editor.commit();
  }
View Full Code Here

    final ObjectId id = ObjectId
        .fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
    final String path = "sub";
    DirCache cache = db.lockDirCache();
    DirCacheEditor editor = cache.editor();
    editor.add(new PathEdit(path) {

      public void apply(DirCacheEntry ent) {
        ent.setFileMode(FileMode.GITLINK);
        ent.setObjectId(id);
      }
    });
    editor.commit();

    FileBasedConfig modulesConfig = new FileBasedConfig(new File(
        db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
    modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
        ConfigConstants.CONFIG_KEY_PATH, path);
View Full Code Here

    final ObjectId id = ObjectId
        .fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
    final String path = "sub";
    DirCache cache = db.lockDirCache();
    DirCacheEditor editor = cache.editor();
    editor.add(new PathEdit(path) {

      public void apply(DirCacheEntry ent) {
        ent.setFileMode(FileMode.GITLINK);
        ent.setObjectId(id);
      }
    });
    editor.commit();

    String base = "git://server/repo.git";
    FileBasedConfig config = db.getConfig();
    config.setString(ConfigConstants.CONFIG_REMOTE_SECTION,
        Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL,
View Full Code Here

    writeTrashFile("dir/subfile", "dir/subfile");
    Tree tree = new Tree(db);
    tree.setId(insertTree(tree));

    DirCache index = db.lockDirCache();
    DirCacheEditor editor = index.editor();
    editor.add(add(db, trash, "file1"));
    editor.add(add(db, trash, "dir/subfile"));
    editor.commit();
    FileTreeIterator iterator = new FileTreeIterator(db);
    IndexDiff diff = new IndexDiff(db, tree.getId(), iterator);
    diff.diff();
    assertEquals(2, diff.getAdded().size());
    assertTrue(diff.getAdded().contains("file1"));
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.dircache.DirCacheEditor$DeleteTree

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.