当前位置: 首页>>代码示例>>Java>>正文


Java RefUpdate.forceUpdate方法代码示例

本文整理汇总了Java中org.eclipse.jgit.lib.RefUpdate.forceUpdate方法的典型用法代码示例。如果您正苦于以下问题:Java RefUpdate.forceUpdate方法的具体用法?Java RefUpdate.forceUpdate怎么用?Java RefUpdate.forceUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jgit.lib.RefUpdate的用法示例。


在下文中一共展示了RefUpdate.forceUpdate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateMasterRecord

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
/**
 *
 * @param repo
 * @param objectId
 * @throws IOException
 */
public static void updateMasterRecord(Repository repo, ObjectId objectId) throws IOException {

    RefUpdate refUpdate = repo.updateRef(Constants.HEAD);
    refUpdate.setNewObjectId(objectId);
    final RefUpdate.Result result = refUpdate.forceUpdate();

    switch (result) {
        case NEW:
            System.out.println("New commit!\n");
            break;
        case FORCED:
            System.out.println("Forced change commit!\n");
            break;
        default: {
            System.out.println(result.name());
        }
    }
}
 
开发者ID:alexmy21,项目名称:gmds,代码行数:25,代码来源:Commands.java

示例2: setHEAD

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
private void setHEAD() throws Exception {
  try (ObjectInserter oi = repository.newObjectInserter()) {
    final CommitBuilder commit = new CommitBuilder();
    commit.setTreeId(oi.insert(Constants.OBJ_TREE, new byte[] {}));
    commit.setAuthor(author);
    commit.setCommitter(committer);
    commit.setMessage("test\n");
    ObjectId commitId = oi.insert(commit);

    final RefUpdate ref = repository.updateRef(Constants.HEAD);
    ref.setNewObjectId(commitId);
    Result result = ref.forceUpdate();
    assertWithMessage(Constants.HEAD + " did not change: " + ref.getResult())
        .that(result)
        .isAnyOf(Result.FAST_FORWARD, Result.FORCED, Result.NEW, Result.NO_CHANGE);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:18,代码来源:CommitMsgHookTest.java

示例3: forceUpdate

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
private void forceUpdate(final RefUpdate ru,
                         final ObjectId id) throws java.io.IOException, ConcurrentRefUpdateException {
    final RefUpdate.Result rc = ru.forceUpdate();
    switch (rc) {
        case NEW:
        case FORCED:
        case FAST_FORWARD:
            break;
        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,
                                                                 id.toString(),
                                                                 rc));
    }
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:21,代码来源:SimpleRefUpdateCommand.java

示例4: doCheckoutCleanBranch

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
private void doCheckoutCleanBranch(String branch, String ref) throws GitException {
    try (Repository repo = getRepository()) {
        RefUpdate refUpdate = repo.updateRef(R_HEADS + branch);
        refUpdate.setNewObjectId(repo.resolve(ref));
        switch (refUpdate.forceUpdate()) {
        case NOT_ATTEMPTED:
        case LOCK_FAILURE:
        case REJECTED:
        case REJECTED_CURRENT_BRANCH:
        case IO_FAILURE:
        case RENAMED:
            throw new GitException("Could not update " + branch + " to " + ref);
        }

        doCheckout(branch);
    } catch (IOException e) {
        throw new GitException("Could not checkout " + branch +  " with start point " + ref, e);
    }
}
 
开发者ID:jenkinsci,项目名称:git-client-plugin,代码行数:20,代码来源:JGitAPIImpl.java

示例5: ref

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
/** {@inheritDoc} */
   public void ref(String refName) throws GitException, InterruptedException {
refName = refName.replace(' ', '_');
try (Repository repo = getRepository()) {
    RefUpdate refUpdate = repo.updateRef(refName);
    refUpdate.setNewObjectId(repo.getRef(Constants.HEAD).getObjectId());
    switch (refUpdate.forceUpdate()) {
    case NOT_ATTEMPTED:
    case LOCK_FAILURE:
    case REJECTED:
    case REJECTED_CURRENT_BRANCH:
    case IO_FAILURE:
    case RENAMED:
	throw new GitException("Could not update " + refName + " to HEAD");
    }
} catch (IOException e) {
    throw new GitException("Could not update " + refName + " to HEAD", e);
}
   }
 
开发者ID:jenkinsci,项目名称:git-client-plugin,代码行数:20,代码来源:JGitAPIImpl.java

示例6: updateRef

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
public static void updateRef(RefUpdate refUpdate) {
	try {
		RefUpdate.Result result = refUpdate.forceUpdate();
        if (result == RefUpdate.Result.LOCK_FAILURE 
        		&& refUpdate.getExpectedOldObjectId() != null 
        		&& !refUpdate.getExpectedOldObjectId().equals(refUpdate.getOldObjectId())) {
        	throw new ObsoleteCommitException(refUpdate.getOldObjectId());
        } else if (result != RefUpdate.Result.FAST_FORWARD && result != RefUpdate.Result.FORCED
        		&& result != RefUpdate.Result.NEW && result != RefUpdate.Result.NO_CHANGE) {
        	throw new RefUpdateException(result);
        } 
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:16,代码来源:GitUtils.java

示例7: update

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
private void update(RevCommit rev) throws Exception {
  RefUpdate u = db.updateRef(RefNames.REFS_CONFIG);
  u.disableRefLog();
  u.setNewObjectId(rev);
  Result result = u.forceUpdate();
  assertWithMessage("Cannot update ref for test: " + result)
      .that(result)
      .isAnyOf(Result.FAST_FORWARD, Result.FORCED, Result.NEW, Result.NO_CHANGE);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:10,代码来源:ProjectConfigTest.java

示例8: setHEADtoRef

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
/**
 * Sets the symbolic ref HEAD to the specified target ref. The HEAD will be detached if the target ref is not a branch.
 * 
 * @param repository
 * @param targetRef
 * @return true if successful
 */
public static boolean setHEADtoRef(Repository repository, String targetRef) {
	try {
		// detach HEAD if target ref is not a branch
		boolean detach = !targetRef.startsWith(Constants.R_HEADS);
		RefUpdate.Result result;
		RefUpdate head = repository.updateRef(Constants.HEAD, detach);
		if (detach) { // Tag
			RevCommit commit = getCommit(repository, targetRef);
			head.setNewObjectId(commit.getId());
			result = head.forceUpdate();
		} else {
			result = head.link(targetRef);
		}
		switch (result) {
		case NEW:
		case FORCED:
		case NO_CHANGE:
		case FAST_FORWARD:
			return true;
		default:
			LOGGER.error(MessageFormat.format("{0} HEAD update to {1} returned result {2}", repository.getDirectory().getAbsolutePath(),
					targetRef, result));
		}
	} catch (Throwable t) {
		error(t, repository, "{0} failed to set HEAD to {1}", targetRef);
	}
	return false;
}
 
开发者ID:tomaswolf,项目名称:gerrit-gitblit-plugin,代码行数:36,代码来源:JGitUtils.java

示例9: setBranchRef

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
/**
 * Sets the local branch ref to point to the specified commit id.
 * 
 * @param repository
 * @param branch
 * @param commitId
 * @return true if successful
 */
public static boolean setBranchRef(Repository repository, String branch, String commitId) {
	String branchName = branch;
	if (!branchName.startsWith(Constants.R_REFS)) {
		branchName = Constants.R_HEADS + branch;
	}

	try {
		RefUpdate refUpdate = repository.updateRef(branchName, false);
		refUpdate.setNewObjectId(ObjectId.fromString(commitId));
		RefUpdate.Result result = refUpdate.forceUpdate();

		switch (result) {
		case NEW:
		case FORCED:
		case NO_CHANGE:
		case FAST_FORWARD:
			return true;
		default:
			LOGGER.error(MessageFormat.format("{0} {1} update to {2} returned result {3}", repository.getDirectory().getAbsolutePath(),
					branchName, commitId, result));
		}
	} catch (Throwable t) {
		error(t, repository, "{0} failed to set {1} to {2}", branchName, commitId);
	}
	return false;
}
 
开发者ID:tomaswolf,项目名称:gerrit-gitblit-plugin,代码行数:35,代码来源:JGitUtils.java

示例10: setHEADtoRef

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
/**
 * Sets the symbolic ref HEAD to the specified target ref. The
 * HEAD will be detached if the target ref is not a branch.
 *
 * @param repository
 * @param targetRef
 * @return true if successful
 */
public static boolean setHEADtoRef(Repository repository, String targetRef) {
	try {
		 // detach HEAD if target ref is not a branch
		boolean detach = !targetRef.startsWith(Constants.R_HEADS);
		RefUpdate.Result result;
		RefUpdate head = repository.updateRef(Constants.HEAD, detach);
		if (detach) { // Tag
			RevCommit commit = getCommit(repository, targetRef);
			head.setNewObjectId(commit.getId());
			result = head.forceUpdate();
		} else {
			result = head.link(targetRef);
		}
		switch (result) {
		case NEW:
		case FORCED:
		case NO_CHANGE:
		case FAST_FORWARD:
			return true;				
		default:
			LOGGER.error(MessageFormat.format("{0} HEAD update to {1} returned result {2}",
					repository.getDirectory().getAbsolutePath(), targetRef, result));
		}
	} catch (Throwable t) {
		error(t, repository, "{0} failed to set HEAD to {1}", targetRef);
	}
	return false;
}
 
开发者ID:warpfork,项目名称:gitblit,代码行数:37,代码来源:JGitUtils.java

示例11: setBranchRef

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
/**
 * Sets the local branch ref to point to the specified commit id.
 *
 * @param repository
 * @param branch
 * @param commitId
 * @return true if successful
 */
public static boolean setBranchRef(Repository repository, String branch, String commitId) {
	String branchName = branch;
	if (!branchName.startsWith(Constants.R_HEADS)) {
		branchName = Constants.R_HEADS + branch;
	}

	try {
		RefUpdate refUpdate = repository.updateRef(branchName, false);
		refUpdate.setNewObjectId(ObjectId.fromString(commitId));
		RefUpdate.Result result = refUpdate.forceUpdate();

		switch (result) {
		case NEW:
		case FORCED:
		case NO_CHANGE:
		case FAST_FORWARD:
			return true;				
		default:
			LOGGER.error(MessageFormat.format("{0} {1} update to {2} returned result {3}",
					repository.getDirectory().getAbsolutePath(), branchName, commitId, result));
		}
	} catch (Throwable t) {
		error(t, repository, "{0} failed to set {1} to {2}", branchName, commitId);
	}
	return false;
}
 
开发者ID:warpfork,项目名称:gitblit,代码行数:35,代码来源:JGitUtils.java

示例12: commit

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
private RevCommit commit(
    Repository repo,
    RevWalk rw,
    @Nullable InMemoryInserter tmpIns,
    ObjectInserter ins,
    String refName,
    ObjectId tree,
    RevCommit merge)
    throws IOException {
  rw.parseHeaders(merge);
  // For maximum stability, choose a single ident using the committer time of
  // the input commit, using the server name and timezone.
  PersonIdent ident =
      new PersonIdent(
          gerritIdent, merge.getCommitterIdent().getWhen(), gerritIdent.getTimeZone());
  CommitBuilder cb = new CommitBuilder();
  cb.setAuthor(ident);
  cb.setCommitter(ident);
  cb.setTreeId(tree);
  cb.setMessage("Auto-merge of " + merge.name() + '\n');
  for (RevCommit p : merge.getParents()) {
    cb.addParentId(p);
  }

  if (!save) {
    checkArgument(tmpIns != null);
    try (ObjectReader tmpReader = tmpIns.newReader();
        RevWalk tmpRw = new RevWalk(tmpReader)) {
      return tmpRw.parseCommit(tmpIns.insert(cb));
    }
  }

  checkArgument(tmpIns == null);
  checkArgument(!(ins instanceof InMemoryInserter));
  ObjectId commitId = ins.insert(cb);
  ins.flush();

  RefUpdate ru = repo.updateRef(refName);
  ru.setNewObjectId(commitId);
  ru.disableRefLog();
  ru.forceUpdate();
  return rw.parseCommit(commitId);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:44,代码来源:AutoMerger.java

示例13: commitIndex

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
private boolean commitIndex(Repository db, DirCache index, String author, String message) throws IOException, ConcurrentRefUpdateException {
	boolean success = false;

	ObjectId headId = db.resolve(BRANCH + "^{commit}");
	if (headId == null) {
		// create the branch
		createTicketsBranch(db);
		headId = db.resolve(BRANCH + "^{commit}");
	}
	try (ObjectInserter odi = db.newObjectInserter()) {
		// Create the in-memory index of the new/updated ticket
		ObjectId indexTreeId = index.writeTree(odi);

		// Create a commit object
		PersonIdent ident = new PersonIdent(author, "[email protected]");
		CommitBuilder commit = new CommitBuilder();
		commit.setAuthor(ident);
		commit.setCommitter(ident);
		commit.setEncoding(Constants.ENCODING);
		commit.setMessage(message);
		commit.setParentId(headId);
		commit.setTreeId(indexTreeId);

		// Insert the commit into the repository
		ObjectId commitId = odi.insert(commit);
		odi.flush();

		try (RevWalk revWalk = new RevWalk(db)) {
			RevCommit revCommit = revWalk.parseCommit(commitId);
			RefUpdate ru = db.updateRef(BRANCH);
			ru.setNewObjectId(commitId);
			ru.setExpectedOldObjectId(headId);
			ru.setRefLogMessage("commit: " + revCommit.getShortMessage(), false);
			Result rc = ru.forceUpdate();
			switch (rc) {
			case NEW:
			case FORCED:
			case FAST_FORWARD:
				success = true;
				break;
			case REJECTED:
			case LOCK_FAILURE:
				throw new ConcurrentRefUpdateException(JGitText.get().couldNotLockHEAD, ru.getRef(), rc);
			default:
				throw new JGitInternalException(MessageFormat.format(JGitText.get().updatingRefFailed, BRANCH, commitId.toString(), rc));
			}
		}
	}
	return success;
}
 
开发者ID:tomaswolf,项目名称:gerrit-gitblit-plugin,代码行数:51,代码来源:BranchTicketService.java

示例14: createOrphanBranch

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
/**
 * Create an orphaned branch in a repository.
 * 
 * @param repository
 * @param branchName
 * @param author
 *            if unspecified, Gitblit will be the author of this new branch
 * @return true if successful
 */
public static boolean createOrphanBranch(Repository repository, String branchName, PersonIdent author) {
	boolean success = false;
	String message = "Created branch " + branchName;
	if (author == null) {
		author = new PersonIdent("Gitblit", "[email protected]");
	}
	try (ObjectInserter odi = repository.newObjectInserter()) {
		// Create a blob object to insert into a tree
		ObjectId blobId = odi.insert(Constants.OBJ_BLOB, message.getBytes(Constants.CHARACTER_ENCODING));

		// Create a tree object to reference from a commit
		TreeFormatter tree = new TreeFormatter();
		tree.append(".branch", FileMode.REGULAR_FILE, blobId);
		ObjectId treeId = odi.insert(tree);

		// Create a commit object
		CommitBuilder commit = new CommitBuilder();
		commit.setAuthor(author);
		commit.setCommitter(author);
		commit.setEncoding(Constants.CHARACTER_ENCODING);
		commit.setMessage(message);
		commit.setTreeId(treeId);

		// Insert the commit into the repository
		ObjectId commitId = odi.insert(commit);
		odi.flush();

		try (RevWalk revWalk = new RevWalk(repository)) {
			RevCommit revCommit = revWalk.parseCommit(commitId);
			if (!branchName.startsWith("refs/")) {
				branchName = "refs/heads/" + branchName;
			}
			RefUpdate ru = repository.updateRef(branchName);
			ru.setNewObjectId(commitId);
			ru.setRefLogMessage("commit: " + revCommit.getShortMessage(), false);
			Result rc = ru.forceUpdate();
			switch (rc) {
			case NEW:
			case FORCED:
			case FAST_FORWARD:
				success = true;
				break;
			default:
				success = false;
			}
		}
	} catch (Throwable t) {
		error(t, repository, "Failed to create orphan branch {1} in repository {0}", branchName);
	}
	return success;
}
 
开发者ID:tomaswolf,项目名称:gerrit-gitblit-plugin,代码行数:61,代码来源:JGitUtils.java

示例15: createOrphanBranch

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
/**
 * Create an orphaned branch in a repository.
 * 
 * @param repository
 * @param branchName
 * @param author
 *            if unspecified, Gitblit will be the author of this new branch
 * @return true if successful
 */
public static boolean createOrphanBranch(Repository repository, String branchName,
		PersonIdent author) {
	boolean success = false;
	String message = "Created branch " + branchName;
	if (author == null) {
		author = new PersonIdent("Gitblit", "[email protected]");
	}
	try {
		ObjectInserter odi = repository.newObjectInserter();
		try {
			// Create a blob object to insert into a tree
			ObjectId blobId = odi.insert(Constants.OBJ_BLOB,
					message.getBytes(Constants.CHARACTER_ENCODING));

			// Create a tree object to reference from a commit
			TreeFormatter tree = new TreeFormatter();
			tree.append(".branch", FileMode.REGULAR_FILE, blobId);
			ObjectId treeId = odi.insert(tree);

			// Create a commit object
			CommitBuilder commit = new CommitBuilder();
			commit.setAuthor(author);
			commit.setCommitter(author);
			commit.setEncoding(Constants.CHARACTER_ENCODING);
			commit.setMessage(message);
			commit.setTreeId(treeId);

			// Insert the commit into the repository
			ObjectId commitId = odi.insert(commit);
			odi.flush();

			RevWalk revWalk = new RevWalk(repository);
			try {
				RevCommit revCommit = revWalk.parseCommit(commitId);
				if (!branchName.startsWith("refs/")) {
					branchName = "refs/heads/" + branchName;
				}
				RefUpdate ru = repository.updateRef(branchName);
				ru.setNewObjectId(commitId);
				ru.setRefLogMessage("commit: " + revCommit.getShortMessage(), false);
				Result rc = ru.forceUpdate();
				switch (rc) {
				case NEW:
				case FORCED:
				case FAST_FORWARD:
					success = true;
					break;
				default:
					success = false;
				}
			} finally {
				revWalk.release();
			}
		} finally {
			odi.release();
		}
	} catch (Throwable t) {
		error(t, repository, "Failed to create orphan branch {1} in repository {0}", branchName);
	}
	return success;
}
 
开发者ID:warpfork,项目名称:gitblit,代码行数:71,代码来源:JGitUtils.java


注:本文中的org.eclipse.jgit.lib.RefUpdate.forceUpdate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。