Java 类org.eclipse.jgit.api.errors.ConcurrentRefUpdateException 实例源码

项目:appformer    文件:SimpleRefUpdateCommand.java   
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));
    }
}
项目:ivy-pdi-git-steps    文件:TagGitCommand.java   
public Git call(final GitOperationsStep gitOperationsStep, Git git,
    CredentialsProvider cp, String gitRepoUrl, File gitRepoFolder)
    throws IllegalArgumentException, IOException,
    ConcurrentRefUpdateException, InvalidTagNameException,
    NoHeadException, GitAPIException {
  TagCommand tc = git.tag().setAnnotated(annotated)
      .setForceUpdate(forceUpdate).setSigned(signed);
  if (!Const.isEmpty(this.message)) {
    tc = tc.setMessage(gitOperationsStep
        .environmentSubstitute(this.message));
  }
  if (!Const.isEmpty(this.name)) {
    tc = tc.setName(gitOperationsStep.environmentSubstitute(this.name));
  }
  tc.call();
  return git;
}
项目:appformer    文件:SimpleRefUpdateCommand.java   
public void execute() throws IOException, ConcurrentRefUpdateException {
    final ObjectId headId = git.getLastCommit(Constants.R_HEADS + name);
    final RefUpdate ru = git.getRepository().updateRef(Constants.R_HEADS + name);
    if (headId == null) {
        ru.setExpectedOldObjectId(ObjectId.zeroId());
    } else {
        ru.setExpectedOldObjectId(headId);
    }
    ru.setNewObjectId(commit.getId());
    ru.setRefLogMessage(commit.getShortMessage(),
                        false);
    forceUpdate(ru,
                commit.getId());
}
项目:appformer    文件:RefTreeUpdateCommand.java   
public void execute() throws java.io.IOException, ConcurrentRefUpdateException {
    update(git.getRepository(),
           Constants.R_HEADS + name,
           commit);
    //this `initialization` aims to be temporary
    // -> without this cgit can't find master when cloning repos
    if (name.equals(MASTER) && !git.isHEADInitialized()) {
        synchronized (git.getRepository()) {
            symRef(git,
                   HEAD,
                   Constants.R_HEADS + name);
            git.setHeadAsInitialized();
        }
    }
}
项目:appformer    文件:Squash.java   
public void execute() {
    final Repository repo = this.git.getRepository();

    final RevCommit latestCommit = git.getLastCommit(branch);
    final RevCommit startCommit = checkIfCommitIsPresentAtBranch(this.git,
                                                                 this.branch,
                                                                 this.startCommitString);

    RevCommit parent = startCommit;
    if (startCommit.getParentCount() > 0) {
        parent = startCommit.getParent(0);
    }

    final CommitBuilder commitBuilder = new CommitBuilder();
    commitBuilder.setParentId(parent);
    commitBuilder.setTreeId(latestCommit.getTree().getId());
    commitBuilder.setMessage(squashedCommitMessage);
    commitBuilder.setAuthor(startCommit.getAuthorIdent());
    commitBuilder.setCommitter(startCommit.getAuthorIdent());

    try (final ObjectInserter odi = repo.newObjectInserter()) {
        final RevCommit squashedCommit = git.resolveRevCommit(odi.insert(commitBuilder));
        git.refUpdate(branch,
                      squashedCommit);
    } catch (ConcurrentRefUpdateException | IOException e) {
        throw new GitException("Error on executing squash.",
                               e);
    }
}
项目:appformer    文件:GitImpl.java   
@Override
public void refUpdate(final String branch,
                      final RevCommit commit)
        throws IOException, ConcurrentRefUpdateException {
    if (getRepository().getRefDatabase() instanceof RefTreeDatabase) {
        new RefTreeUpdateCommand(this,
                                 branch,
                                 commit).execute();
    } else {
        new SimpleRefUpdateCommand(this,
                                   branch,
                                   commit).execute();
    }
}
项目:gitlab-plugin    文件:MergeRequestHookTriggerHandlerImplTest.java   
private OneShotEvent doHandle(MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler,
        MergeRequestObjectAttributesBuilder objectAttributes) throws GitAPIException, IOException, NoHeadException,
        NoMessageException, UnmergedPathsException, ConcurrentRefUpdateException, WrongRepositoryStateException,
        AmbiguousObjectException, IncorrectObjectTypeException, MissingObjectException, InterruptedException {
    Git.init().setDirectory(tmp.getRoot()).call();
       tmp.newFile("test");
       Git git = Git.open(tmp.getRoot());
       git.add().addFilepattern("test");
       RevCommit commit = git.commit().setMessage("test").call();
       ObjectId head = git.getRepository().resolve(Constants.HEAD);
       String repositoryUrl = tmp.getRoot().toURI().toString();

       final OneShotEvent buildTriggered = new OneShotEvent();
       FreeStyleProject project = jenkins.createFreeStyleProject();
       project.setScm(new GitSCM(repositoryUrl));
       project.getBuildersList().add(new TestBuilder() {
           @Override
           public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
               buildTriggered.signal();
               return true;
           }
       });
       project.setQuietPeriod(0);
    mergeRequestHookTriggerHandler.handle(project, mergeRequestHook()
               .withObjectAttributes(objectAttributes
                    .withTargetBranch("refs/heads/" + git.nameRev().add(head).call().get(head))
                    .withLastCommit(commit().withAuthor(user().withName("test").build()).withId(commit.getName()).build())
                   .build())
               .withProject(project()
                   .withWebUrl("https://gitlab.org/test.git")
                   .build()
               )
               .build(), true, BranchFilterFactory.newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
           newMergeRequestLabelFilter(null));

       buildTriggered.block(10000);
       return buildTriggered;
}
项目:ivy-pdi-git-steps    文件:CommitGitCommand.java   
public Git call(final GitOperationsStep gitOperationsStep, Git git,
    CredentialsProvider cp, String gitRepoUrl, File gitRepoFolder)
    throws IllegalArgumentException, IOException, NoHeadException,
    NoMessageException, UnmergedPathsException,
    ConcurrentRefUpdateException, WrongRepositoryStateException,
    GitAPIException {
  CommitCommand cc = git
      .commit()
      .setAuthor(
          gitOperationsStep
              .environmentSubstitute(this.authorName == null ? ""
                  : this.authorName),
          gitOperationsStep
              .environmentSubstitute(this.authorEmail == null ? ""
                  : this.authorEmail))
      .setCommitter(
          gitOperationsStep
              .environmentSubstitute(this.committerName == null ? ""
                  : this.committerName),
          gitOperationsStep
              .environmentSubstitute(this.committerEmail == null ? ""
                  : this.committerName));

  if (!Const.isEmpty(this.commitMessage)) {
    cc = cc.setMessage(gitOperationsStep
        .environmentSubstitute(this.commitMessage));
  }
  cc.setAll(all).setInsertChangeId(insertChangeId).setAmend(amend).call();
  return git;
}
项目:gradle-gitsemver    文件:TagBasedVersionFactoryTest.java   
@Before
public void createVersionFactory() throws IOException, NoHeadException,
        NoMessageException, UnmergedPathsException,
        ConcurrentRefUpdateException, WrongRepositoryStateException,
        GitAPIException {
    repo = createRepository();
    git = initializeGitFlow(repo);
    versionFactory = new TagBasedVersionFactory();
}
项目:gradle-gitsemver    文件:TagBasedVersionFactoryTest.java   
@Test
public void testHeadPointsAtStable() throws ConcurrentRefUpdateException,
        InvalidTagNameException, NoHeadException, GitAPIException,
        NoWorkTreeException, MissingObjectException,
        IncorrectObjectTypeException, IOException {
    tag("v1.0.0");
    validateStableTag("1.0.0");
}
项目:gradle-gitsemver    文件:TagBasedVersionFactoryTest.java   
@Test
public void testHeadPointsAtStableWhenUsingPrefix() throws ConcurrentRefUpdateException,
        InvalidTagNameException, NoHeadException, GitAPIException,
        NoWorkTreeException, MissingObjectException,
        IncorrectObjectTypeException, IOException {
    versionFactory = new TagBasedVersionFactory("myPrefix");
    tag("myPrefix-v1.0.0");
    validateStableTag("1.0.0");
}
项目:gradle-gitsemver    文件:TagBasedVersionFactoryTest.java   
@Test
public void testHeadPointsOneAboveStable()
        throws ConcurrentRefUpdateException, InvalidTagNameException,
        NoHeadException, GitAPIException, NoWorkTreeException,
        MissingObjectException, IncorrectObjectTypeException, IOException {
    tag("v1.0.0");
    RevCommit head = makeCommit();
    validateUnstable("1.0.0", 1, head, Dirty.NO, DOT);
}
项目:gradle-gitsemver    文件:TagBasedVersionFactoryTest.java   
@Test
public void testCommitCount() throws NoHeadException, NoMessageException,
        UnmergedPathsException, ConcurrentRefUpdateException,
        WrongRepositoryStateException, GitAPIException,
        NoWorkTreeException, IOException {
    tag("v0.1.1-rc");
    makeCommit();
    makeCommit();
    RevCommit head = makeCommit();
    validateUnstable("0.1.1-rc", 3, head, Dirty.NO, DOT);
}
项目:gradle-gitsemver    文件:TagBasedVersionFactoryTest.java   
@Test
public void testVUnnecessary() throws ConcurrentRefUpdateException,
        InvalidTagNameException, NoHeadException, GitAPIException,
        NoWorkTreeException, IOException {
    makeCommit();
    tag("0.1.0");
    validateStableTag("0.1.0");
}
项目:gradle-gitsemver    文件:TagBasedVersionFactoryTest.java   
@Test
public void testUnstableIsDirty() throws ConcurrentRefUpdateException,
        InvalidTagNameException, NoHeadException, GitAPIException,
        NoWorkTreeException, MissingObjectException,
        IncorrectObjectTypeException, IOException {
    RevCommit commit = makeCommit();
    tag("0.1.0-dev");
    dirtyRepo();
    validateUnstable("0.1.0-dev", 0, commit, Dirty.YES, DOT);
}
项目:gradle-gitsemver    文件:TagBasedVersionFactoryTest.java   
@Test
public void testOrdering() throws ConcurrentRefUpdateException,
        InvalidTagNameException, NoHeadException, GitAPIException,
        NoWorkTreeException, MissingObjectException,
        IncorrectObjectTypeException, IOException {
    tag("3.0.0");
    makeCommit();
    RevCommit head = makeCommit();
    tag("1.0.0");
    validateUnstable("3.0.0", 2, head, Dirty.NO, DASH);
}
项目:SGit    文件:CommitChangesTask.java   
public static void commit(Repo repo, boolean stageAll, boolean isAmend,
        String msg, String authorName, String authorEmail) throws Exception, NoHeadException, NoMessageException,
        UnmergedPathsException, ConcurrentRefUpdateException,
        WrongRepositoryStateException, GitAPIException, StopTaskException {
    Context context = SGitApplication.getContext();
    StoredConfig config = repo.getGit().getRepository().getConfig();
    String committerEmail = config.getString("user", null, "email");
    String committerName = config.getString("user", null, "name");

    if (committerName == null || committerName.equals("")) {
        committerName = Profile.getUsername(context);
    }
    if (committerEmail == null || committerEmail.equals("")) {
        committerEmail = Profile.getEmail(context);
    }
    if (committerName.isEmpty() || committerEmail.isEmpty()) {
        throw new Exception("Please set your name and email");
    }
    if (msg.isEmpty()) {
        throw new Exception("Please include a commit message");
    }
    CommitCommand cc = repo.getGit().commit()
            .setCommitter(committerName, committerEmail).setAll(stageAll)
            .setAmend(isAmend).setMessage(msg);
    if (authorName != null && authorEmail != null) {
        cc.setAuthor(authorName, authorEmail);
    }
    cc.call();
    repo.updateLatestCommitInfo();
}
项目:appformer    文件:Git.java   
void refUpdate(final String branch,
final RevCommit commit) throws IOException, ConcurrentRefUpdateException;
项目:IRCBlit    文件:PushLogUtils.java   
/**
 * Updates a push log.
 * 
 * @param user
 * @param repository
 * @param commands
 * @return true, if the update was successful
 */
public static boolean updatePushLog(UserModel user, Repository repository,
        Collection<ReceiveCommand> commands) {
    RefModel pushlogBranch = getPushLogBranch(repository);
    if (pushlogBranch == null) {
        JGitUtils.createOrphanBranch(repository, GB_PUSHES, null);
    }

    boolean success = false;
    String message = "push";

    try {
        ObjectId headId = repository.resolve(GB_PUSHES + "^{commit}");
        ObjectInserter odi = repository.newObjectInserter();
        try {
            // Create the in-memory index of the push log entry
            DirCache index = createIndex(repository, headId, commands);
            ObjectId indexTreeId = index.writeTree(odi);

            PersonIdent ident = new PersonIdent(user.getDisplayName(), 
                    user.emailAddress == null ? user.username:user.emailAddress);

            // Create a commit object
            CommitBuilder commit = new CommitBuilder();
            commit.setAuthor(ident);
            commit.setCommitter(ident);
            commit.setEncoding(Constants.CHARACTER_ENCODING);
            commit.setMessage(message);
            commit.setParentId(headId);
            commit.setTreeId(indexTreeId);

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

            RevWalk revWalk = new RevWalk(repository);
            try {
                RevCommit revCommit = revWalk.parseCommit(commitId);
                RefUpdate ru = repository.updateRef(GB_PUSHES);
                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, GB_PUSHES, commitId.toString(),
                            rc));
                }
            } finally {
                revWalk.release();
            }
        } finally {
            odi.release();
        }
    } catch (Throwable t) {
        error(t, repository, "Failed to commit pushlog entry to {0}");
    }
    return success;
}
项目:gradle-gitsemver    文件:TagBasedVersionFactoryTest.java   
private Ref tag(String tagName) throws ConcurrentRefUpdateException,
        InvalidTagNameException, NoHeadException, GitAPIException {
    return git.tag().setMessage("blah").setName(tagName).call();
}
项目:gradle-gitsemver    文件:TagBasedVersionFactoryTest.java   
private RevCommit makeCommit() throws NoHeadException, NoMessageException,
        UnmergedPathsException, ConcurrentRefUpdateException,
        WrongRepositoryStateException, GitAPIException {
    return git.commit().setCommitter(COMMITTER).setMessage("some commit").call();
}