Example usage for org.eclipse.jgit.lib RefUpdate setForceUpdate

List of usage examples for org.eclipse.jgit.lib RefUpdate setForceUpdate

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib RefUpdate setForceUpdate.

Prototype

public void setForceUpdate(boolean b) 

Source Link

Document

Set if this update wants to forcefully change the ref.

Usage

From source file:org.kuali.student.git.model.ref.utils.GitRefUtils.java

License:Educational Community License

public static Result createTagReference(Repository repo, String simpleTagName, ObjectId tagId)
        throws IOException {

    String refName = Constants.R_TAGS + simpleTagName;
    RefUpdate tagRef = repo.updateRef(refName);
    tagRef.setNewObjectId(tagId);//  ww  w .j a v a2 s . c  om
    tagRef.setForceUpdate(true);
    tagRef.setRefLogMessage("tagged " + simpleTagName, false);
    Result updateResult = tagRef.forceUpdate();

    return updateResult;

}

From source file:org.kuali.student.git.model.ref.utils.GitRefUtils.java

License:Educational Community License

public static Result deleteRef(Repository repo, Ref ref, boolean force) throws IOException {

    RefUpdate refUpdate = repo.getRefDatabase().newUpdate(ref.getName(), false);

    refUpdate.setForceUpdate(force);

    return refUpdate.delete();
}

From source file:org.kuali.student.svn.model.AbstractGitRespositoryTestCase.java

License:Educational Community License

protected Result createBranch(ObjectId objectId, String branchName) throws IOException {

    RefUpdate update = repo.updateRef(Constants.R_HEADS + branchName);

    update.setNewObjectId(objectId);//from w ww .ja v  a2 s.c  o  m

    update.setForceUpdate(true);

    return update.update();
}

From source file:org.uberfire.java.nio.fs.jgit.util.commands.RemoveRemote.java

License:Apache License

public void execute() {
    try {/*from w w  w .j  a v  a 2 s.c om*/
        // AF-1715: Cleaning origin to prevent errors while importing the new generated repo.
        git.getRepository().getConfig().unsetSection("remote", remote);
        git.getRepository().getConfig().save();
        RefUpdate updateRef = git.getRepository().updateRef(ref, false);
        updateRef.setRefLogMessage(ref + " packed-ref deleted", false);
        updateRef.setForceUpdate(true);
        updateRef.delete();
    } catch (Exception e) {
        throw new GitException("Error when trying to remove remote", e);
    }
}

From source file:playRepository.BareCommit.java

License:Apache License

private void refUpdate(ObjectId commitId, String refName) throws IOException {
    RefUpdate ru = this.repository.updateRef(refName);
    ru.setForceUpdate(false);
    ru.setRefLogIdent(getPersonIdent());
    ru.setNewObjectId(commitId);//ww  w  .  j  av  a  2  s .  c om
    if (hasOldCommit(refName)) {
        ru.setExpectedOldObjectId(getCurrentMomentHeadObjectId());
    }
    ru.setRefLogMessage(getCommitMessage(), false);
    ru.update();
}

From source file:svnserver.repository.git.LayoutHelper.java

License:GNU General Public License

@NotNull
public static Ref initRepository(@NotNull Repository repository, String branch) throws IOException {
    Ref ref = repository.getRef(PREFIX_REF + branch);
    if (ref == null) {
        Ref old = repository.getRef(OLD_CACHE_REF);
        if (old != null) {
            final RefUpdate refUpdate = repository.updateRef(PREFIX_REF + branch);
            refUpdate.setNewObjectId(old.getObjectId());
            refUpdate.update();/*  w ww  .j av  a2s.  co  m*/
        }
    }
    if (ref == null) {
        final ObjectId revision = createFirstRevision(repository);
        final RefUpdate refUpdate = repository.updateRef(PREFIX_REF + branch);
        refUpdate.setNewObjectId(revision);
        refUpdate.update();
        ref = repository.getRef(PREFIX_REF + branch);
        if (ref == null) {
            throw new IOException("Can't initialize repository.");
        }
    }
    Ref old = repository.getRef(OLD_CACHE_REF);
    if (old != null) {
        final RefUpdate refUpdate = repository.updateRef(OLD_CACHE_REF);
        refUpdate.setForceUpdate(true);
        refUpdate.delete();
    }
    return ref;
}

From source file:util.ChkoutCmd.java

License:Eclipse Distribution License

/**
 * @throws RefAlreadyExistsException//www .j  av a  2 s.  c o  m
 *             when trying to create (without force) a branch with a name
 *             that already exists
 * @throws RefNotFoundException
 *             if the start point or branch can not be found
 * @throws InvalidRefNameException
 *             if the provided name is <code>null</code> or otherwise
 *             invalid
 * @throws CheckoutConflictException
 *             if the checkout results in a conflict
 * @return the newly created branch
 */
public Ref call() throws GitAPIException, RefAlreadyExistsException, RefNotFoundException,
        InvalidRefNameException, CheckoutConflictException {
    checkCallable();
    processOptions();
    try {
        if (checkoutAllPaths || !paths.isEmpty()) {
            checkoutPaths();
            status = new CheckoutResult(Status.OK, paths);
            setCallable(false);
            return null;
        }

        if (createBranch) {
            Git git = new Git(repo);
            CreateBranchCommand command = git.branchCreate();
            command.setName(name);
            command.setStartPoint(getStartPoint().name());
            if (upstreamMode != null)
                command.setUpstreamMode(upstreamMode);
            command.call();
        }

        Ref headRef = repo.getRef(Constants.HEAD);
        String shortHeadRef = getShortBranchName(headRef);
        String refLogMessage = "checkout: moving from " + shortHeadRef; //$NON-NLS-1$
        ObjectId branch = repo.resolve(name);
        if (branch == null)
            throw new RefNotFoundException(MessageFormat.format(JGitText.get().refNotResolved, name));

        RevWalk revWalk = new RevWalk(repo);
        AnyObjectId headId = headRef.getObjectId();
        RevCommit headCommit = headId == null ? null : revWalk.parseCommit(headId);
        RevCommit newCommit = revWalk.parseCommit(branch);
        RevTree headTree = headCommit == null ? null : headCommit.getTree();
        DirCacheCheckout dco;
        DirCache dc = repo.lockDirCache();
        try {
            dco = new DirCacheCheckout(repo, headTree, dc, newCommit.getTree());
            dco.setFailOnConflict(false);
            try {
                dco.checkout();
            } catch (org.eclipse.jgit.errors.CheckoutConflictException e) {
                status = new CheckoutResult(Status.CONFLICTS, dco.getConflicts());
                throw new CheckoutConflictException(dco.getConflicts(), e);
            }
        } finally {
            dc.unlock();
        }
        Ref ref = repo.getRef(name);
        if (ref != null && !ref.getName().startsWith(Constants.R_HEADS))
            ref = null;
        String toName = Repository.shortenRefName(name);
        RefUpdate refUpdate = repo.updateRef(Constants.HEAD, ref == null);
        refUpdate.setForceUpdate(force);
        refUpdate.setRefLogMessage(refLogMessage + " to " + toName, false); //$NON-NLS-1$
        Result updateResult;
        if (ref != null)
            updateResult = refUpdate.link(ref.getName());
        else {
            refUpdate.setNewObjectId(newCommit);
            updateResult = refUpdate.forceUpdate();
        }

        setCallable(false);

        boolean ok = false;
        switch (updateResult) {
        case NEW:
            ok = true;
            break;
        case NO_CHANGE:
        case FAST_FORWARD:
        case FORCED:
            ok = true;
            break;
        default:
            break;
        }

        if (!ok)
            throw new JGitInternalException(
                    MessageFormat.format(JGitText.get().checkoutUnexpectedResult, updateResult.name()));

        if (!dco.getToBeDeleted().isEmpty()) {
            status = new CheckoutResult(Status.NONDELETED, dco.getToBeDeleted());
        } else
            status = new CheckoutResult(new ArrayList<String>(dco.getUpdated().keySet()), dco.getRemoved());

        return ref;
    } catch (IOException ioe) {
        throw new JGitInternalException(ioe.getMessage(), ioe);
    } finally {
        if (status == null)
            status = CheckoutResult.ERROR_RESULT;
    }
}