Example usage for org.eclipse.jgit.errors IndexWriteException IndexWriteException

List of usage examples for org.eclipse.jgit.errors IndexWriteException IndexWriteException

Introduction

In this page you can find the example usage for org.eclipse.jgit.errors IndexWriteException IndexWriteException.

Prototype

public IndexWriteException() 

Source Link

Document

Constructs an IndexWriteException with the default message.

Usage

From source file:com.bacoder.scmtools.git.internal.CloneAndProcessDirCacheCheckout.java

License:Apache License

@Override
protected boolean checkoutEntries() throws IOException {
    Map<String, ObjectId> updated = getUpdated();
    List<String> paths = Lists.newArrayList(updated.keySet());
    Collections.sort(paths);/*  w w  w .  j  av  a2 s.c  o m*/

    ObjectReader objectReader = repository.getObjectDatabase().newReader();
    try {
        for (String path : paths) {
            DirCacheEntry entry = dirCache.getEntry(path);
            if (FileMode.GITLINK.equals(entry.getRawMode()))
                continue;

            boolean isSubmoduleConfig = path.equals(Constants.DOT_GIT_MODULES);
            ObjectId objectId = updated.get(path);
            if (isSubmoduleConfig) {
                ObjectLoader loader = objectReader.open(objectId);
                byte[] data = loader.getBytes();
                submodulesConfig = data;
            }
            if (processor != null) {
                GitEntry gitEntry = new GitEntry(repository, objectId, pathPrefix, path);
                try {
                    processor.process(gitEntry);
                } catch (Exception e) {
                    throw new InternalRuntimeException(e);
                }
            }
        }
        // commit the index builder - a new index is persisted
        if (!getBuilder().commit())
            throw new IndexWriteException();
    } finally {
        objectReader.release();
    }
    return true;
}

From source file:com.itemis.maven.plugins.unleash.scm.providers.merge.UnleashGitMerger.java

License:Eclipse Distribution License

/**
 * The resolve conflict way of three way merging
 *
 * @param baseTree/*from  w  ww  .j  a  va  2s .c om*/
 * @param headTree
 * @param mergeTree
 * @param ignoreConflicts
 *          Controls what to do in case a content-merge is done and a
 *          conflict is detected. The default setting for this should be
 *          <code>false</code>. In this case the working tree file is
 *          filled with new content (containing conflict markers) and the
 *          index is filled with multiple stages containing BASE, OURS and
 *          THEIRS content. Having such non-0 stages is the sign to git
 *          tools that there are still conflicts for that path.
 *          <p>
 *          If <code>true</code> is specified the behavior is different.
 *          In case a conflict is detected the working tree file is again
 *          filled with new content (containing conflict markers). But
 *          also stage 0 of the index is filled with that content. No
 *          other stages are filled. Means: there is no conflict on that
 *          path but the new content (including conflict markers) is
 *          stored as successful merge result. This is needed in the
 *          context of {@link RecursiveMerger} where when determining
 *          merge bases we don't want to deal with content-merge
 *          conflicts.
 * @return whether the trees merged cleanly
 * @throws IOException
 * @since 3.5
 */
@Override
protected boolean mergeTrees(AbstractTreeIterator baseTree, RevTree headTree, RevTree mergeTree,
        boolean ignoreConflicts) throws IOException {

    this.builder = this.dircache.builder();
    DirCacheBuildIterator buildIt = new DirCacheBuildIterator(this.builder);

    this.tw = new NameConflictTreeWalk(this.reader);
    this.tw.addTree(baseTree);
    this.tw.addTree(headTree);
    this.tw.addTree(mergeTree);
    this.tw.addTree(buildIt);
    if (this.workingTreeIterator != null) {
        this.tw.addTree(this.workingTreeIterator);
    } else {
        this.tw.setFilter(TreeFilter.ANY_DIFF);
    }

    if (!mergeTreeWalk(this.tw, ignoreConflicts)) {
        return false;
    }

    if (!this.inCore) {
        // No problem found. The only thing left to be done is to
        // checkout all files from "theirs" which have been selected to
        // go into the new index.
        checkout();

        // All content-merges are successfully done. If we can now write the
        // new index we are on quite safe ground. Even if the checkout of
        // files coming from "theirs" fails the user can work around such
        // failures by checking out the index again.
        if (!this.builder.commit()) {
            cleanUp();
            throw new IndexWriteException();
        }
        this.builder = null;

    } else {
        this.builder.finish();
        this.builder = null;
    }

    if (getUnmergedPaths().isEmpty() && !failed()) {
        this.resultTree = this.dircache.writeTree(getObjectInserter());
        return true;
    } else {
        this.resultTree = null;
        return false;
    }
}