use of org.eclipse.jgit.lib.RefUpdate in project gerrit by GerritCodeReview.
the class RepoSequence method storeNew.
public void storeNew(int value) {
counterLock.lock();
try (Repository repo = repoManager.openRepository(projectName);
RevWalk rw = new RevWalk(repo)) {
Optional<IntBlob> blob = IntBlob.parse(repo, refName, rw);
afterReadRef.run();
ObjectId oldId;
if (!blob.isPresent()) {
oldId = ObjectId.zeroId();
} else {
oldId = blob.get().id();
}
RefUpdate refUpdate = IntBlob.tryStore(repo, rw, projectName, refName, oldId, value, gitRefUpdated);
RefUpdateUtil.checkResult(refUpdate);
counter = value;
limit = counter + batchSize;
acquireCount++;
} catch (IOException e) {
throw new StorageException(e);
} finally {
counterLock.unlock();
}
}
use of org.eclipse.jgit.lib.RefUpdate in project gerrit by GerritCodeReview.
the class BaseCommitUtil method updateRef.
private static RevCommit updateRef(Repository repo, RevWalk rw, String refName, ObjectId autoMergeId, RevCommit merge) throws IOException {
RefUpdate ru = repo.updateRef(refName);
ru.setNewObjectId(autoMergeId);
ru.disableRefLog();
switch(ru.update()) {
case FAST_FORWARD:
case FORCED:
case NEW:
case NO_CHANGE:
return rw.parseCommit(autoMergeId);
case LOCK_FAILURE:
throw new LockFailureException(String.format("Failed to create auto-merge of %s", merge.name()), ru);
case IO_FAILURE:
case NOT_ATTEMPTED:
case REJECTED:
case REJECTED_CURRENT_BRANCH:
case REJECTED_MISSING_OBJECT:
case REJECTED_OTHER_REASON:
case RENAMED:
default:
throw new IOException(String.format("Failed to create auto-merge of %s: Cannot write %s (%s)", merge.name(), refName, ru.getResult()));
}
}
use of org.eclipse.jgit.lib.RefUpdate in project gerrit by GerritCodeReview.
the class GroupsConsistencyIT method missingGroupRef.
@Test
public void missingGroupRef() throws Exception {
try (Repository repo = repoManager.openRepository(allUsers)) {
RefUpdate ru = repo.updateRef(RefNames.refsGroups(AccountGroup.uuid(g1.id)));
ru.setForceUpdate(true);
RefUpdate.Result result = ru.delete();
assertThat(result).isEqualTo(Result.FORCED);
}
assertError("missing as group ref");
}
use of org.eclipse.jgit.lib.RefUpdate in project gerrit by GerritCodeReview.
the class GroupsConsistencyIT method missingGroupNameRef.
@Test
public void missingGroupNameRef() throws Exception {
try (Repository repo = repoManager.openRepository(allUsers)) {
RefUpdate ru = repo.updateRef(RefNames.REFS_GROUPNAMES);
ru.setForceUpdate(true);
RefUpdate.Result result = ru.delete();
assertThat(result).isEqualTo(Result.FORCED);
}
assertError("refs/meta/group-names does not exist");
}
use of org.eclipse.jgit.lib.RefUpdate in project gerrit by GerritCodeReview.
the class CreateChangeIT method addNonCommitHead.
@Before
public void addNonCommitHead() throws Exception {
try (Repository repo = repoManager.openRepository(project);
ObjectInserter ins = repo.newObjectInserter()) {
ObjectId answer = ins.insert(Constants.OBJ_BLOB, new byte[] { 42 });
ins.flush();
ins.close();
RefUpdate update = repo.getRefDatabase().newUpdate("refs/heads/answer", false);
update.setNewObjectId(answer);
assertThat(update.forceUpdate()).isEqualTo(RefUpdate.Result.NEW);
}
}
Aggregations