Package org.eclipse.jgit.dircache

Examples of org.eclipse.jgit.dircache.DirCache


    assertFalse(tw.isDirectoryFileConflict());
  }

  @Test
  public void testDF_DetectConflict() throws Exception {
    final DirCache tree0 = db.readDirCache();
    final DirCache tree1 = db.readDirCache();
    {
      final DirCacheBuilder b0 = tree0.builder();
      final DirCacheBuilder b1 = tree1.builder();

      b0.add(createEntry("0", REGULAR_FILE));
      b0.add(createEntry("a", REGULAR_FILE));
      b1.add(createEntry("0", REGULAR_FILE));
      b1.add(createEntry("a.b", REGULAR_FILE));
      b1.add(createEntry("a/b", REGULAR_FILE));
      b1.add(createEntry("a/c/e", REGULAR_FILE));

      b0.finish();
      b1.finish();
      assertEquals(2, tree0.getEntryCount());
      assertEquals(4, tree1.getEntryCount());
    }

    final NameConflictTreeWalk tw = new NameConflictTreeWalk(db);
    tw.addTree(new DirCacheIterator(tree0));
    tw.addTree(new DirCacheIterator(tree1));
View Full Code Here


    RefUpdate u = clonedRepo.updateRef(Constants.HEAD, detached);
    u.setNewObjectId(commit.getId());
    u.forceUpdate();

    if (!bare) {
      DirCache dc = clonedRepo.lockDirCache();
      DirCacheCheckout co = new DirCacheCheckout(clonedRepo, dc,
          commit.getTree());
      co.checkout();
      if (cloneSubmodules)
        cloneSubmodules(clonedRepo);
View Full Code Here

    Git git = new Git(db);
    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);
View Full Code Here

    Git git = new Git(db);
    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);
View Full Code Here

    Git git = new Git(db);
    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);
View Full Code Here

    Git git = new Git(db);
    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);
View Full Code Here

    Git git = new Git(db);
    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);
View Full Code Here

    RevCommit commit2 = git.commit().setMessage("commit2").call();
    assertNotNull(commit2);

    assertNotNull(git.checkout().setName(Constants.MASTER).call());

    DirCache cache = db.lockDirCache();
    cache.getEntry("test.txt").setFileMode(FileMode.EXECUTABLE_FILE);
    cache.write();
    assertTrue(cache.commit());
    cache.unlock();

    assertNotNull(git.commit().setMessage("commit3").call());

    db.getFS().setExecute(file, false);
    git.getRepository()
View Full Code Here

  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;

    ObjectInserter inserter = repo.newObjectInserter();
    try {
      dc = repo.lockDirCache();
      DirCacheIterator c;

      DirCacheBuilder builder = dc.builder();
      final TreeWalk tw = new TreeWalk(repo);
      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 (!(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
                && (!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 {
      inserter.release();
      if (dc != null)
        dc.unlock();
    }

    return dc;
  }
View Full Code Here

        } else {
          parents.add(0, headId);
        }

      // lock the index
      DirCache index = repo.lockDirCache();
      try {
        if (!only.isEmpty())
          index = createTemporaryIndex(headId, index, rw);

        ObjectInserter odi = repo.newObjectInserter();
        try {
          // Write the index as tree to the object database. This may
          // fail for example when the index contains unmerged paths
          // (unresolved conflicts)
          ObjectId indexTreeId = index.writeTree(odi);

          if (insertChangeId)
            insertChangeId(indexTreeId);

          // Create a Commit object, populate it and write it
          CommitBuilder commit = new CommitBuilder();
          commit.setCommitter(committer);
          commit.setAuthor(author);
          commit.setMessage(message);

          commit.setParentIds(parents);
          commit.setTreeId(indexTreeId);
          ObjectId commitId = odi.insert(commit);
          odi.flush();

          RevCommit revCommit = rw.parseCommit(commitId);
          RefUpdate ru = repo.updateRef(Constants.HEAD);
          ru.setNewObjectId(commitId);
          if (reflogComment != null) {
            ru.setRefLogMessage(reflogComment, false);
          } else {
            String prefix = amend ? "commit (amend): " //$NON-NLS-1$
                : parents.size() == 0 ? "commit (initial): " //$NON-NLS-1$
                    : "commit: "; //$NON-NLS-1$
            ru.setRefLogMessage(
                prefix + revCommit.getShortMessage(), false);
          }
          if (headId != null)
            ru.setExpectedOldObjectId(headId);
          else
            ru.setExpectedOldObjectId(ObjectId.zeroId());
          Result rc = ru.forceUpdate();
          switch (rc) {
          case NEW:
          case FORCED:
          case FAST_FORWARD: {
            setCallable(false);
            if (state == RepositoryState.MERGING_RESOLVED
                || isMergeDuringRebase(state)) {
              // Commit was successful. Now delete the files
              // used for merge commits
              repo.writeMergeCommitMsg(null);
              repo.writeMergeHeads(null);
            } else if (state == RepositoryState.CHERRY_PICKING_RESOLVED) {
              repo.writeMergeCommitMsg(null);
              repo.writeCherryPickHead(null);
            } else if (state == RepositoryState.REVERTING_RESOLVED) {
              repo.writeMergeCommitMsg(null);
              repo.writeRevertHead(null);
            }
            return revCommit;
          }
          case REJECTED:
          case LOCK_FAILURE:
            throw new ConcurrentRefUpdateException(
                JGitText.get().couldNotLockHEAD, ru.getRef(),
                rc);
          default:
            throw new JGitInternalException(MessageFormat.format(
                JGitText.get().updatingRefFailed,
                Constants.HEAD, commitId.toString(), rc));
          }
        } finally {
          odi.release();
        }
      } finally {
        index.unlock();
      }
    } catch (UnmergedPathException e) {
      throw new UnmergedPathsException(e);
    } catch (IOException e) {
      throw new JGitInternalException(
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.dircache.DirCache

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.