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


Java RefUpdate类代码示例

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


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

示例1: run

import org.eclipse.jgit.lib.RefUpdate; //导入依赖的package包/类
@Override
protected void run () throws GitException {
    Repository repository = getRepository();
    Ref currentRef = repository.getTags().get(tagName);
    if (currentRef == null) {
        throw new GitException.MissingObjectException(tagName, GitObjectType.TAG);
    }
    String fullName = currentRef.getName();
    try {
        RefUpdate update = repository.updateRef(fullName);
        update.setRefLogMessage("tag deleted", false);
        update.setForceUpdate(true);
        Result deleteResult = update.delete();

        switch (deleteResult) {
            case IO_FAILURE:
            case LOCK_FAILURE:
            case REJECTED:
                throw new GitException.RefUpdateException("Cannot delete tag " + tagName, GitRefUpdateResult.valueOf(deleteResult.name()));
        }
    } catch (IOException ex) {
        throw new GitException(ex);
    }
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:DeleteTagCommand.java

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

示例3: testDoUpdateRef

import org.eclipse.jgit.lib.RefUpdate; //导入依赖的package包/类
private static void testDoUpdateRef(String ref, ObjectId commitId, boolean tagExists) throws Exception {
    final org.eclipse.jgit.lib.Repository jGitRepo = mock(org.eclipse.jgit.lib.Repository.class);
    final RevWalk revWalk = mock(RevWalk.class);
    final RefUpdate refUpdate = mock(RefUpdate.class);

    when(jGitRepo.exactRef(ref)).thenReturn(tagExists ? mock(Ref.class) : null);
    when(jGitRepo.updateRef(ref)).thenReturn(refUpdate);

    when(refUpdate.update(revWalk)).thenReturn(RefUpdate.Result.NEW);
    GitRepository.doRefUpdate(jGitRepo, revWalk, ref, commitId);

    when(refUpdate.update(revWalk)).thenReturn(RefUpdate.Result.FAST_FORWARD);
    GitRepository.doRefUpdate(jGitRepo, revWalk, ref, commitId);

    when(refUpdate.update(revWalk)).thenReturn(RefUpdate.Result.LOCK_FAILURE);
    assertThatThrownBy(() -> GitRepository.doRefUpdate(jGitRepo, revWalk, ref, commitId))
            .isInstanceOf(StorageException.class);
}
 
开发者ID:line,项目名称:centraldogma,代码行数:19,代码来源:GitRepositoryTest.java

示例4: deleteRef

import org.eclipse.jgit.lib.RefUpdate; //导入依赖的package包/类
public static void deleteRef(RefUpdate refUpdate) {
	try {
		refUpdate.setForceUpdate(true);
		RefUpdate.Result result = refUpdate.delete();
        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,代码行数:17,代码来源:GitUtils.java

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

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

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

示例8: tagDelete

import org.eclipse.jgit.lib.RefUpdate; //导入依赖的package包/类
@Override
public void tagDelete(String name) throws GitException {
  try {
    Ref tagRef = repository.findRef(name);
    if (tagRef == null) {
      throw new GitException("Tag " + name + " not found. ");
    }

    RefUpdate updateRef = repository.updateRef(tagRef.getName());
    updateRef.setRefLogMessage("tag deleted", false);
    updateRef.setForceUpdate(true);
    Result deleteResult = updateRef.delete();
    if (deleteResult != Result.FORCED && deleteResult != Result.FAST_FORWARD) {
      throw new GitException(format(ERROR_TAG_DELETE, name, deleteResult));
    }
  } catch (IOException exception) {
    throw new GitException(exception.getMessage(), exception);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:JGitConnection.java

示例9: deleteRef

import org.eclipse.jgit.lib.RefUpdate; //导入依赖的package包/类
private static void deleteRef(Repository repo, ChangeEdit edit) throws IOException {
  String refName = edit.getRefName();
  RefUpdate ru = repo.updateRef(refName, true);
  ru.setExpectedOldObjectId(edit.getEditCommit());
  ru.setForceUpdate(true);
  RefUpdate.Result result = ru.delete();
  switch (result) {
    case FORCED:
    case NEW:
    case NO_CHANGE:
      break;
    case FAST_FORWARD:
    case IO_FAILURE:
    case LOCK_FAILURE:
    case NOT_ATTEMPTED:
    case REJECTED:
    case REJECTED_CURRENT_BRANCH:
    case RENAMED:
    case REJECTED_MISSING_OBJECT:
    case REJECTED_OTHER_REASON:
    default:
      throw new IOException(String.format("Failed to delete ref %s: %s", refName, result));
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:25,代码来源:ChangeEditUtil.java

示例10: updateReference

import org.eclipse.jgit.lib.RefUpdate; //导入依赖的package包/类
private void updateReference(
    Repository repository,
    String refName,
    ObjectId currentObjectId,
    ObjectId targetObjectId,
    Timestamp timestamp)
    throws IOException {
  RefUpdate ru = repository.updateRef(refName);
  ru.setExpectedOldObjectId(currentObjectId);
  ru.setNewObjectId(targetObjectId);
  ru.setRefLogIdent(getRefLogIdent(timestamp));
  ru.setRefLogMessage("inline edit (amend)", false);
  ru.setForceUpdate(true);
  try (RevWalk revWalk = new RevWalk(repository)) {
    RefUpdate.Result res = ru.update(revWalk);
    if (res != RefUpdate.Result.NEW && res != RefUpdate.Result.FORCED) {
      throw new IOException(
          "cannot update "
              + ru.getName()
              + " in "
              + repository.getDirectory()
              + ": "
              + ru.getResult());
    }
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:27,代码来源:ChangeEditModifier.java

示例11: call

import org.eclipse.jgit.lib.RefUpdate; //导入依赖的package包/类
@Override
public RefUpdate.Result call() throws Exception {
  Ref ref = repo.exactRef(refName);
  afterReadRef.run();
  ObjectId oldId;
  if (ref == null) {
    oldId = ObjectId.zeroId();
  } else {
    oldId = ref.getObjectId();
    int next = parse(rw, oldId);
    if (next >= value) {
      // a concurrent write updated the ref already to this or a higher value
      return RefUpdate.Result.NO_CHANGE;
    }
  }
  return store(repo, rw, oldId, value);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:18,代码来源:RepoSequence.java

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

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

示例14: createUserBranch

import org.eclipse.jgit.lib.RefUpdate; //导入依赖的package包/类
public void createUserBranch(
    Repository repo,
    ObjectInserter oi,
    ObjectId emptyTree,
    Account.Id accountId,
    Timestamp registeredOn)
    throws IOException {
  ObjectId id = createInitialEmptyCommit(oi, emptyTree, registeredOn);

  String refName = RefNames.refsUsers(accountId);
  RefUpdate ru = repo.updateRef(refName);
  ru.setExpectedOldObjectId(ObjectId.zeroId());
  ru.setNewObjectId(id);
  ru.setRefLogIdent(serverIdent);
  ru.setRefLogMessage(CREATE_ACCOUNT_MSG, false);
  Result result = ru.update();
  if (result != Result.NEW) {
    throw new IOException(String.format("Failed to update ref %s: %s", refName, result.name()));
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:21,代码来源:Schema_146.java

示例15: create

import org.eclipse.jgit.lib.RefUpdate; //导入依赖的package包/类
public void create() throws IOException, ConfigInvalidException {
  try (Repository git = mgr.openRepository(allProjectsName)) {
    initAllProjects(git);
  } catch (RepositoryNotFoundException notFound) {
    // A repository may be missing if this project existed only to store
    // inheritable permissions. For example 'All-Projects'.
    try (Repository git = mgr.createRepository(allProjectsName)) {
      initAllProjects(git);
      RefUpdate u = git.updateRef(Constants.HEAD);
      u.link(RefNames.REFS_CONFIG);
    } catch (RepositoryNotFoundException err) {
      String name = allProjectsName.get();
      throw new IOException("Cannot create repository " + name, err);
    }
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:17,代码来源:AllProjectsCreator.java


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