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


Java RefUpdate.setNewObjectId方法代码示例

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


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

示例1: doRefUpdate

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
@VisibleForTesting
static void doRefUpdate(org.eclipse.jgit.lib.Repository jGitRepository, RevWalk revWalk,
                        String ref, ObjectId commitId) throws IOException {

    if (ref.startsWith(Constants.R_TAGS)) {
        final Ref oldRef = jGitRepository.exactRef(ref);
        if (oldRef != null) {
            throw new StorageException("tag ref exists already: " + ref);
        }
    }

    final RefUpdate refUpdate = jGitRepository.updateRef(ref);
    refUpdate.setNewObjectId(commitId);

    final Result res = refUpdate.update(revWalk);
    switch (res) {
        case NEW:
        case FAST_FORWARD:
            // Expected
            break;
        default:
            throw new StorageException("unexpected refUpdate state: " + res);
    }
}
 
开发者ID:line,项目名称:centraldogma,代码行数:25,代码来源:GitRepository.java

示例2: open

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
@Transactional
@Override
public void open(PullRequest request) {
	request.setNumber(getNextNumber(request.getTargetProject()));
	dao.persist(request);
	
	RefUpdate refUpdate = GitUtils.getRefUpdate(request.getTargetProject().getRepository(), request.getBaseRef());
	refUpdate.setNewObjectId(ObjectId.fromString(request.getBaseCommitHash()));
	GitUtils.updateRef(refUpdate);
	
	refUpdate = GitUtils.getRefUpdate(request.getTargetProject().getRepository(), request.getHeadRef());
	refUpdate.setNewObjectId(ObjectId.fromString(request.getHeadCommitHash()));
	GitUtils.updateRef(refUpdate);
	
	for (PullRequestUpdate update: request.getUpdates()) {
		pullRequestUpdateManager.save(update, false);
	}
	
	for (ReviewInvitation invitation: request.getReviewInvitations())
		reviewInvitationManager.save(invitation);

	checkAsync(request);
	
	listenerRegistry.post(new PullRequestOpened(request));
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:26,代码来源:DefaultPullRequestManager.java

示例3: checkUpdate

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
private void checkUpdate(PullRequest request) {
	if (!request.getHeadCommitHash().equals(request.getSource().getObjectName())) {
		ObjectId mergeBase = GitUtils.getMergeBase(
				request.getTargetProject().getRepository(), request.getTarget().getObjectId(), 
				request.getSourceProject().getRepository(), request.getSource().getObjectId(), 
				GitUtils.branch2ref(request.getSourceBranch()));
		if (mergeBase != null) {
			PullRequestUpdate update = new PullRequestUpdate();
			update.setRequest(request);
			update.setHeadCommitHash(request.getSource().getObjectName());
			update.setMergeBaseCommitHash(mergeBase.name());
			request.addUpdate(update);
			pullRequestUpdateManager.save(update, true);
			
			RefUpdate refUpdate = GitUtils.getRefUpdate(request.getTargetProject().getRepository(), 
					request.getHeadRef());
			refUpdate.setNewObjectId(ObjectId.fromString(request.getHeadCommitHash()));
			GitUtils.updateRef(refUpdate);
		}
	}
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:22,代码来源:DefaultPullRequestManager.java

示例4: 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

示例5: afterUpdateRepos

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
@Override
public void afterUpdateRepos() throws Exception {
  // Reopen repo and update ref, to simulate a concurrent write in another
  // thread. Only do this the first time the listener is called.
  if (calledCount.getAndIncrement() > 0) {
    return;
  }
  try (Repository repo = repoManager.openRepository(project);
      RevWalk rw = new RevWalk(repo);
      ObjectInserter ins = repo.newObjectInserter()) {
    String master = "refs/heads/master";
    ObjectId oldId = repo.exactRef(master).getObjectId();
    ObjectId newId = newCommit(rw, ins, oldId, MSG_PREFIX + calledCount.get());
    ins.flush();
    RefUpdate ru = repo.updateRef(master);
    ru.setExpectedOldObjectId(oldId);
    ru.setNewObjectId(newId);
    assertThat(ru.update(rw)).isEqualTo(RefUpdate.Result.FAST_FORWARD);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:21,代码来源:NoteDbOnlyIT.java

示例6: rebuildDeletesOldDraftRefs

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
@Test
public void rebuildDeletesOldDraftRefs() throws Exception {
  PushOneCommit.Result r = createChange();
  Change.Id id = r.getPatchSetId().getParentKey();
  putDraft(user, id, 1, "comment", null);

  Account.Id otherAccountId = new Account.Id(user.getId().get() + 1234);
  String otherDraftRef = refsDraftComments(id, otherAccountId);

  try (Repository repo = repoManager.openRepository(allUsers);
      ObjectInserter ins = repo.newObjectInserter()) {
    ObjectId sha = ins.insert(OBJ_BLOB, "garbage data".getBytes(UTF_8));
    ins.flush();
    RefUpdate ru = repo.updateRef(otherDraftRef);
    ru.setExpectedOldObjectId(ObjectId.zeroId());
    ru.setNewObjectId(sha);
    assertThat(ru.update()).isEqualTo(RefUpdate.Result.NEW);
  }

  checker.rebuildAndCheckChanges(id);

  try (Repository repo = repoManager.openRepository(allUsers)) {
    assertThat(repo.exactRef(otherDraftRef)).isNull();
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:26,代码来源:ChangeRebuilderIT.java

示例7: 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

示例8: createGroupBranch

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
private void createGroupBranch(Project.NameKey project, String ref) throws IOException {
  try (Repository r = repoManager.openRepository(project);
      ObjectInserter oi = r.newObjectInserter();
      RevWalk rw = new RevWalk(r)) {
    ObjectId emptyTree = oi.insert(Constants.OBJ_TREE, new byte[] {});
    PersonIdent ident = new PersonIdent(serverIdent.get(), TimeUtil.nowTs());

    CommitBuilder cb = new CommitBuilder();
    cb.setTreeId(emptyTree);
    cb.setCommitter(ident);
    cb.setAuthor(ident);
    cb.setMessage("Create group");
    ObjectId emptyCommit = oi.insert(cb);

    oi.flush();

    RefUpdate updateRef = r.updateRef(ref);
    updateRef.setExpectedOldObjectId(ObjectId.zeroId());
    updateRef.setNewObjectId(emptyCommit);
    assertThat(updateRef.update(rw)).isEqualTo(RefUpdate.Result.NEW);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:23,代码来源:GroupsIT.java

示例9: store

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
private RefUpdate.Result store(Repository repo, RevWalk rw, @Nullable ObjectId oldId, int val)
    throws IOException {
  ObjectId newId;
  try (ObjectInserter ins = repo.newObjectInserter()) {
    newId = ins.insert(OBJ_BLOB, Integer.toString(val).getBytes(UTF_8));
    ins.flush();
  }
  RefUpdate ru = repo.updateRef(refName);
  if (oldId != null) {
    ru.setExpectedOldObjectId(oldId);
  }
  ru.disableRefLog();
  ru.setNewObjectId(newId);
  ru.setForceUpdate(true); // Required for non-commitish updates.
  RefUpdate.Result result = ru.update(rw);
  if (refUpdated(result)) {
    gitRefUpdated.fire(projectName, ru, null);
  }
  return result;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:21,代码来源:RepoSequence.java

示例10: deleteUserBranch

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
public static void deleteUserBranch(
    Repository repo,
    Project.NameKey project,
    GitReferenceUpdated gitRefUpdated,
    @Nullable IdentifiedUser user,
    PersonIdent refLogIdent,
    Account.Id accountId)
    throws IOException {
  String refName = RefNames.refsUsers(accountId);
  Ref ref = repo.exactRef(refName);
  if (ref == null) {
    return;
  }

  RefUpdate ru = repo.updateRef(refName);
  ru.setExpectedOldObjectId(ref.getObjectId());
  ru.setNewObjectId(ObjectId.zeroId());
  ru.setForceUpdate(true);
  ru.setRefLogIdent(refLogIdent);
  ru.setRefLogMessage("Delete Account", true);
  Result result = ru.delete();
  if (result != Result.FORCED) {
    throw new IOException(String.format("Failed to delete ref %s: %s", refName, result.name()));
  }
  gitRefUpdated.fire(project, ru, user != null ? user.getAccount() : null);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:27,代码来源:AccountsUpdate.java

示例11: forcePushNotAllowed

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
@Test
public void forcePushNotAllowed() throws Exception {
  ObjectId initial = repo().exactRef(HEAD).getLeaf().getObjectId();
  PushOneCommit push1 =
      pushFactory.create(db, admin.getIdent(), testRepo, "change1", "a.txt", "content");
  PushOneCommit.Result r1 = push1.to("refs/heads/master");
  r1.assertOkStatus();

  // Reset HEAD to initial so the new change is a non-fast forward
  RefUpdate ru = repo().updateRef(HEAD);
  ru.setNewObjectId(initial);
  assertThat(ru.forceUpdate()).isEqualTo(RefUpdate.Result.FORCED);

  PushOneCommit push2 =
      pushFactory.create(db, admin.getIdent(), testRepo, "change2", "b.txt", "content");
  push2.setForce(true);
  PushOneCommit.Result r2 = push2.to("refs/heads/master");
  r2.assertErrorStatus("non-fast forward");
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:20,代码来源:ForcePushIT.java

示例12: push

import org.eclipse.jgit.lib.RefUpdate; //导入方法依赖的package包/类
@Override
public boolean push(@NotNull Repository repository, @NotNull ObjectId ReceiveId, @NotNull String branch, @NotNull User userInfo) throws SVNException, IOException {
  final RefUpdate refUpdate = repository.updateRef(branch);
  refUpdate.getOldObjectId();
  refUpdate.setNewObjectId(ReceiveId);
  runReceiveHook(repository, refUpdate, preReceive, userInfo);
  runUpdateHook(repository, refUpdate, update, userInfo);
  final RefUpdate.Result result = refUpdate.update();
  switch (result) {
    case REJECTED:
      return false;
    case NEW:
    case FAST_FORWARD:
      runReceiveHook(repository, refUpdate, postReceive, userInfo);
      return true;
    default:
      log.error("Unexpected push error: {}", result);
      throw new SVNException(SVNErrorMessage.create(SVNErrorCode.IO_WRITE_ERROR, result.name()));
  }
}
 
开发者ID:bozaro,项目名称:git-as-svn,代码行数:21,代码来源:GitPushEmbedded.java

示例13: 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

示例14: 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

示例15: deleteRef

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


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