• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java RefNames类的典型用法和代码示例

java 1次浏览

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

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

示例1: createProjectWithInitialBranches

点赞 3

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
@Test
public void createProjectWithInitialBranches() throws Exception {
  String name = name("foo");
  ProjectInput input = new ProjectInput();
  input.name = name;
  input.createEmptyCommit = true;
  input.branches = ImmutableList.of("master", "foo");
  assertThat(gApi.projects().create(input).get().name).isEqualTo(name);
  assertThat(
          gApi.projects().name(name).branches().get().stream().map(b -> b.ref).collect(toSet()))
      .containsExactly("refs/heads/foo", "refs/heads/master", "HEAD", RefNames.REFS_CONFIG);

  RevCommit head = getRemoteHead(name, RefNames.REFS_CONFIG);
  eventRecorder.assertRefUpdatedEvents(name, RefNames.REFS_CONFIG, null, head);

  head = getRemoteHead(name, "refs/heads/foo");
  eventRecorder.assertRefUpdatedEvents(name, "refs/heads/foo", null, head);

  head = getRemoteHead(name, "refs/heads/master");
  eventRecorder.assertRefUpdatedEvents(name, "refs/heads/master", null, head);

  projectIndexedCounter.assertReindexOf(name);
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:24,
代码来源:ProjectIT.java

示例2: reindexIfStale

点赞 3

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
@Test
public void reindexIfStale() throws Exception {
  Account.Id user = createAccount("user");
  Project.NameKey project = new Project.NameKey("repo");
  TestRepository<Repo> repo = createProject(project.get());
  Change change = insert(repo, newChange(repo));
  String changeId = change.getKey().get();
  ChangeNotes notes = notesFactory.create(db, change.getProject(), change.getId());
  PatchSet ps = psUtil.get(db, notes, change.currentPatchSetId());

  requestContext.setContext(newRequestContext(user));
  gApi.changes().id(changeId).edit().create();
  assertQuery("has:edit", change);
  assertThat(indexer.reindexIfStale(project, change.getId()).get()).isFalse();

  // Delete edit ref behind index's back.
  RefUpdate ru =
      repo.getRepository().updateRef(RefNames.refsEdit(user, change.getId(), ps.getId()));
  ru.setForceUpdate(true);
  assertThat(ru.delete()).isEqualTo(RefUpdate.Result.FORCED);

  // Index is stale.
  assertQuery("has:edit", change);
  assertThat(indexer.reindexIfStale(project, change.getId()).get()).isTrue();
  assertQuery("has:edit");
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:27,
代码来源:AbstractQueryChangesTest.java

示例3: pushAccountConfigToUserBranchIsRejectedIfPreferredEmailIsInvalid

点赞 3

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
@Test
public void pushAccountConfigToUserBranchIsRejectedIfPreferredEmailIsInvalid() throws Exception {
  TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
  fetch(allUsersRepo, RefNames.refsUsers(admin.id) + ":userRef");
  allUsersRepo.reset("userRef");

  String noEmail = "no.email";
  Config ac = getAccountConfig(allUsersRepo);
  ac.setString(AccountConfig.ACCOUNT, null, AccountConfig.KEY_PREFERRED_EMAIL, noEmail);

  PushOneCommit.Result r =
      pushFactory
          .create(
              db,
              admin.getIdent(),
              allUsersRepo,
              "Update account config",
              AccountConfig.ACCOUNT_CONFIG,
              ac.toText())
          .to(RefNames.REFS_USERS_SELF);
  r.assertErrorStatus("invalid account configuration");
  r.assertMessage(
      String.format("invalid preferred email '%s' for account '%s'", noEmail, admin.id));
  accountIndexedCounter.assertNoReindex();
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:26,
代码来源:AccountIT.java

示例4: updateProjectConfig

点赞 3

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
@Override
protected ProjectAccess updateProjectConfig(
    ProjectConfig config, MetaDataUpdate md, boolean parentProjectUpdate)
    throws IOException, NoSuchProjectException, ConfigInvalidException,
        PermissionBackendException {
  RevCommit commit = config.commit(md);

  gitRefUpdated.fire(
      config.getProject().getNameKey(),
      RefNames.REFS_CONFIG,
      base,
      commit.getId(),
      user.asIdentifiedUser().getAccount());

  projectCache.evict(config.getProject());
  createGroupPermissionSyncer.syncIfNeeded();
  return projectAccessFactory.create(projectName).call();
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:19,
代码来源:ChangeProjectAccess.java

示例5: parse

点赞 3

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
@Override
public BranchResource parse(ProjectResource parent, IdString id)
    throws ResourceNotFoundException, IOException, PermissionBackendException {
  Project.NameKey project = parent.getNameKey();
  try (Repository repo = repoManager.openRepository(project)) {
    Ref ref = repo.exactRef(RefNames.fullName(id.get()));
    if (ref == null) {
      throw new ResourceNotFoundException(id);
    }

    // ListBranches checks the target of a symbolic reference to determine access
    // rights on the symbolic reference itself. This check prevents seeing a hidden
    // branch simply because the symbolic reference name was visible.
    permissionBackend
        .user(user)
        .project(project)
        .ref(ref.isSymbolic() ? ref.getTarget().getName() : ref.getName())
        .check(RefPermission.READ);
    return new BranchResource(parent.getProjectState(), parent.getUser(), ref);
  } catch (AuthException notAllowed) {
    throw new ResourceNotFoundException(id);
  } catch (RepositoryNotFoundException noRepo) {
    throw new ResourceNotFoundException();
  }
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:26,
代码来源:BranchesCollection.java

示例6: allBranches

点赞 3

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
private List<BranchInfo> allBranches(ProjectResource rsrc)
    throws IOException, ResourceNotFoundException, PermissionBackendException {
  List<Ref> refs;
  try (Repository db = repoManager.openRepository(rsrc.getNameKey())) {
    Collection<Ref> heads = db.getRefDatabase().getRefs(Constants.R_HEADS).values();
    refs = new ArrayList<>(heads.size() + 3);
    refs.addAll(heads);
    refs.addAll(
        db.getRefDatabase()
            .exactRef(Constants.HEAD, RefNames.REFS_CONFIG, RefNames.REFS_USERS_DEFAULT)
            .values());
  } catch (RepositoryNotFoundException noGitRepository) {
    throw new ResourceNotFoundException();
  }
  return toBranchInfo(rsrc, refs);
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:17,
代码来源:ListBranches.java

示例7: byChange

点赞 3

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
/**
 * Retrieve edit for a change and the given user.
 *
 * <p>At most one change edit can exist per user and change.
 *
 * @param notes change notes of change to retrieve change edits for.
 * @param user user to retrieve edits as.
 * @return edit for this change for this user, if present.
 * @throws AuthException if this is not a logged-in user.
 * @throws IOException if an error occurs.
 */
public Optional<ChangeEdit> byChange(ChangeNotes notes, CurrentUser user)
    throws AuthException, IOException {
  if (!user.isIdentifiedUser()) {
    throw new AuthException("Authentication required");
  }
  IdentifiedUser u = user.asIdentifiedUser();
  Change change = notes.getChange();
  try (Repository repo = gitManager.openRepository(change.getProject())) {
    int n = change.currentPatchSetId().get();
    String[] refNames = new String[n];
    for (int i = n; i > 0; i--) {
      refNames[i - 1] =
          RefNames.refsEdit(u.getAccountId(), change.getId(), new PatchSet.Id(change.getId(), i));
    }
    Ref ref = repo.getRefDatabase().firstExactRef(refNames);
    if (ref == null) {
      return Optional.empty();
    }
    try (RevWalk rw = new RevWalk(repo)) {
      RevCommit commit = rw.parseCommit(ref.getObjectId());
      PatchSet basePs = getBasePatchSet(notes, ref);
      return Optional.of(new ChangeEdit(change, ref.getName(), commit, basePs));
    }
  }
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:37,
代码来源:ChangeEditUtil.java

示例8: testUpdateProjectConfig

点赞 3

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
private String testUpdateProjectConfig() throws Exception {
  Config cfg = readProjectConfig();
  assertThat(cfg.getString("project", null, "description")).isNull();
  String desc = "new project description";
  cfg.setString("project", null, "description", desc);

  PushOneCommit.Result r = createConfigChange(cfg);
  String id = r.getChangeId();

  gApi.changes().id(id).current().review(ReviewInput.approve());
  gApi.changes().id(id).current().submit();

  assertThat(gApi.changes().id(id).info().status).isEqualTo(ChangeStatus.MERGED);
  assertThat(gApi.projects().name(project.get()).get().description).isEqualTo(desc);
  fetchRefsMetaConfig();
  assertThat(readProjectConfig().getString("project", null, "description")).isEqualTo(desc);
  String changeRev = gApi.changes().id(id).get().currentRevision;
  String branchRev =
      gApi.projects().name(project.get()).branch(RefNames.REFS_CONFIG).get().revision;
  assertThat(changeRev).isEqualTo(branchRev);
  return id;
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:23,
代码来源:ConfigChangeIT.java

示例9: accessProjectSpecificConfig

点赞 3

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
@Test
public void accessProjectSpecificConfig() throws Exception {
  String configName = "test.config";
  Config cfg = new Config();
  cfg.setString("s1", null, "k1", "v1");
  cfg.setString("s2", "ss", "k2", "v2");
  PushOneCommit push =
      pushFactory.create(
          db,
          admin.getIdent(),
          testRepo,
          "Create Project Level Config",
          configName,
          cfg.toText());
  push.to(RefNames.REFS_CONFIG);

  ProjectState state = projectCache.get(project);
  assertThat(state.getConfig(configName).get().toText()).isEqualTo(cfg.toText());
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:20,
代码来源:ProjectLevelConfigIT.java

示例10: byChange

点赞 3

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
public ImmutableMap<Account.Id, StarRef> byChange(Change.Id changeId) throws OrmException {
  try (Repository repo = repoManager.openRepository(allUsers)) {
    ImmutableMap.Builder<Account.Id, StarRef> builder = ImmutableMap.builder();
    for (String refPart : getRefNames(repo, RefNames.refsStarredChangesPrefix(changeId))) {
      Integer id = Ints.tryParse(refPart);
      if (id == null) {
        continue;
      }
      Account.Id accountId = new Account.Id(id);
      builder.put(accountId, readLabels(repo, RefNames.refsStarredChanges(changeId, accountId)));
    }
    return builder.build();
  } catch (IOException e) {
    throw new OrmException(
        String.format("Get accounts that starred change %d failed", changeId.get()), e);
  }
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:18,
代码来源:StarredChangesUtil.java

示例11: advertiseRefs

点赞 3

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
@VisibleForTesting
public Result advertiseRefs(Map<String, Ref> oldRefs) {
  Map<String, Ref> r = Maps.newHashMapWithExpectedSize(oldRefs.size());
  Set<ObjectId> allPatchSets = Sets.newHashSetWithExpectedSize(oldRefs.size());
  for (Map.Entry<String, Ref> e : oldRefs.entrySet()) {
    String name = e.getKey();
    if (!skip(name)) {
      r.put(name, e.getValue());
    }
    if (name.startsWith(RefNames.REFS_CHANGES)) {
      allPatchSets.add(e.getValue().getObjectId());
    }
  }
  return new AutoValue_ReceiveCommitsAdvertiseRefsHook_Result(
      r, advertiseOpenChanges(allPatchSets));
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:17,
代码来源:ReceiveCommitsAdvertiseRefsHook.java

示例12: uploadPackAllRefsVisibleNoRefsMetaConfig

点赞 3

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
@Test
public void uploadPackAllRefsVisibleNoRefsMetaConfig() throws Exception {
  ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
  Util.allow(cfg, Permission.READ, REGISTERED_USERS, "refs/*");
  Util.allow(cfg, Permission.READ, admins, RefNames.REFS_CONFIG);
  Util.doNotInherit(cfg, Permission.READ, RefNames.REFS_CONFIG);
  saveProjectConfig(project, cfg);

  setApiUser(user);
  assertUploadPackRefs(
      "HEAD",
      r1 + "1",
      r1 + "meta",
      r2 + "1",
      r2 + "meta",
      r3 + "1",
      r3 + "meta",
      r4 + "1",
      r4 + "meta",
      "refs/heads/branch",
      "refs/heads/master",
      "refs/tags/branch-tag",
      "refs/tags/master-tag");
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:25,
代码来源:RefAdvertisementIT.java

示例13: parseDelete

点赞 3

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
private void parseDelete(ReceiveCommand cmd) throws PermissionBackendException {
  logDebug("Deleting {}", cmd);
  if (cmd.getRefName().startsWith(REFS_CHANGES)) {
    errors.put(ReceiveError.DELETE_CHANGES, cmd.getRefName());
    reject(cmd, "cannot delete changes");
  } else if (canDelete(cmd)) {
    if (!validRefOperation(cmd)) {
      return;
    }
    actualCommands.add(cmd);
  } else if (RefNames.REFS_CONFIG.equals(cmd.getRefName())) {
    reject(cmd, "cannot delete project configuration");
  } else {
    errors.put(ReceiveError.DELETE, cmd.getRefName());
    reject(cmd, "cannot delete references");
  }
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:18,
代码来源:ReceiveCommits.java

示例14: OpenBranch

点赞 3

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
OpenBranch(OpenRepo or, Branch.NameKey name) throws IntegrationException {
  try {
    update = or.repo.updateRef(name.get());
    if (update.getOldObjectId() != null) {
      oldTip = or.rw.parseCommit(update.getOldObjectId());
    } else if (Objects.equals(or.repo.getFullBranch(), name.get())
        || Objects.equals(RefNames.REFS_CONFIG, name.get())) {
      oldTip = null;
      update.setExpectedOldObjectId(ObjectId.zeroId());
    } else {
      throw new IntegrationException(
          "The destination branch " + name + " does not exist anymore.");
    }
  } catch (IOException e) {
    throw new IntegrationException("Cannot open branch " + name, e);
  }
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:18,
代码来源:MergeOpRepoManager.java

示例15: onPreMerge

点赞 3

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
@Override
public void onPreMerge(
    Repository repo,
    CodeReviewCommit commit,
    ProjectState destProject,
    Branch.NameKey destBranch,
    PatchSet.Id patchSetId,
    IdentifiedUser caller)
    throws MergeValidationException {
  // Groups are stored inside 'refs/groups/' refs inside the 'All-Users' repository.
  if (!allUsersName.equals(destProject.getNameKey())
      || !destBranch.get().startsWith(RefNames.REFS_GROUPS)) {
    return;
  }

  throw new MergeValidationException("group update not allowed");
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:18,
代码来源:MergeValidators.java

示例16: onCommitReceived

点赞 3

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
@Override
public List<CommitValidationMessage> onCommitReceived(CommitReceivedEvent receiveEvent)
    throws CommitValidationException {
  // Groups are stored inside 'refs/groups/' refs inside the 'All-Users' repository.
  if (!allUsers.equals(receiveEvent.project.getNameKey())) {
    return Collections.emptyList();
  }

  if (receiveEvent.command.getRefName().startsWith(MagicBranch.NEW_CHANGE)) {
    // no validation on push for review, will be checked on submit by
    // MergeValidators.GroupMergeValidator
    return Collections.emptyList();
  }

  if (receiveEvent.command.getRefName().startsWith(RefNames.REFS_GROUPS)) {
    throw new CommitValidationException("group update not allowed");
  }
  return Collections.emptyList();
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:20,
代码来源:CommitValidators.java

示例17: checkProjectConfig

点赞 3

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
private void checkProjectConfig(RepoContext ctx, CodeReviewCommit commit)
    throws IntegrationException {
  String refName = getDest().get();
  if (RefNames.REFS_CONFIG.equals(refName)) {
    logDebug("Loading new configuration from {}", RefNames.REFS_CONFIG);
    try {
      ProjectConfig cfg = new ProjectConfig(getProject());
      cfg.load(ctx.getRevWalk(), commit);
    } catch (Exception e) {
      throw new IntegrationException(
          "Submit would store invalid"
              + " project configuration "
              + commit.name()
              + " for "
              + getProject(),
          e);
    }
  }
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:20,
代码来源:SubmitStrategyOp.java

示例18: cannotCreateUserBranch

点赞 3

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
@Test
@Sandboxed
public void cannotCreateUserBranch() throws Exception {
  grant(allUsers, RefNames.REFS_USERS + "*", Permission.CREATE);
  grant(allUsers, RefNames.REFS_USERS + "*", Permission.PUSH);

  String userRef = RefNames.refsUsers(new Account.Id(seq.nextAccountId()));
  TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
  PushOneCommit.Result r = pushFactory.create(db, admin.getIdent(), allUsersRepo).to(userRef);
  r.assertErrorStatus();
  assertThat(r.getMessage()).contains("Not allowed to create user branch.");

  try (Repository repo = repoManager.openRepository(allUsers)) {
    assertThat(repo.exactRef(userRef)).isNull();
  }
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:17,
代码来源:AccountIT.java

示例19: deleteUserBranch

点赞 3

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的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

示例20: uploadPackAllRefsVisibleWithRefsMetaConfig

点赞 3

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
@Test
public void uploadPackAllRefsVisibleWithRefsMetaConfig() throws Exception {
  allow("refs/*", Permission.READ, REGISTERED_USERS);
  allow(RefNames.REFS_CONFIG, Permission.READ, REGISTERED_USERS);

  assertUploadPackRefs(
      "HEAD",
      r1 + "1",
      r1 + "meta",
      r2 + "1",
      r2 + "meta",
      r3 + "1",
      r3 + "meta",
      r4 + "1",
      r4 + "meta",
      "refs/heads/branch",
      "refs/heads/master",
      RefNames.REFS_CONFIG,
      "refs/tags/branch-tag",
      "refs/tags/master-tag");
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:22,
代码来源:RefAdvertisementIT.java

示例21: submitWithValidation

点赞 3

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
@Test
public void submitWithValidation() throws Exception {
  AtomicBoolean called = new AtomicBoolean(false);
  this.addOnSubmitValidationListener(
      new OnSubmitValidationListener() {
        @Override
        public void preBranchUpdate(Arguments args) throws ValidationException {
          called.set(true);
          HashSet<String> refs = Sets.newHashSet(args.getCommands().keySet());
          assertThat(refs).contains("refs/heads/master");
          refs.remove("refs/heads/master");
          if (!refs.isEmpty()) {
            // Some submit strategies need to insert new patchset.
            assertThat(refs).hasSize(1);
            assertThat(refs.iterator().next()).startsWith(RefNames.REFS_CHANGES);
          }
        }
      });

  PushOneCommit.Result change = createChange();
  approve(change.getChangeId());
  submit(change.getChangeId());
  assertThat(called.get()).isTrue();
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:25,
代码来源:AbstractSubmit.java

示例22: trim

点赞 2

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
private static String trim(String ref) {
  if (ref.startsWith(RefNames.REFS_CHANGES)) {
    int s1 = ref.lastIndexOf('/');
    if (s1 > 0) {
      int s2 = ref.lastIndexOf('/', s1 - 1);
      if (s2 > 0) {
        return ref.substring(s2 + 1);
      }
    }
  }
  return null;
}
 

开发者ID:GerritCodeReview,
项目名称:plugins_download-commands,
代码行数:13,
代码来源:RepoCommand.java

示例23: wouldPushRef

点赞 2

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
boolean wouldPushRef(String ref) {
  if (!config.replicatePermissions() && RefNames.REFS_CONFIG.equals(ref)) {
    return false;
  }
  for (RefSpec s : config.getRemoteConfig().getPushRefSpecs()) {
    if (s.matchSource(ref)) {
      return true;
    }
  }
  return false;
}
 

开发者ID:GerritCodeReview,
项目名称:plugins_replication,
代码行数:12,
代码来源:Destination.java

示例24: pushGroupsAccessSectionChangeToCustomProjectSucceeds

点赞 2

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
@Test
public void pushGroupsAccessSectionChangeToCustomProjectSucceeds() throws Exception {
  TestRepository<InMemoryRepository> repo = cloneProject(project, RefNames.REFS_CONFIG);

  String config =
      gApi.projects()
          .name(project.get())
          .branch(RefNames.REFS_CONFIG)
          .file(ProjectConfig.PROJECT_CONFIG)
          .asString();

  Config cfg = new Config();
  cfg.fromText(config);
  cfg.setString("access", RefNames.REFS_GROUPS + "foo", "push", "group Registered Users");
  config = cfg.toText();

  PushOneCommit.Result r =
      pushFactory
          .create(
              db,
              admin.getIdent(),
              repo,
              "Subject",
              ImmutableMap.of(
                  "groups",
                  "global:Registered-Users\tRegistered Users",
                  ProjectConfig.PROJECT_CONFIG,
                  config))
          .to(RefNames.REFS_CONFIG);
  r.assertOkStatus();
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:32,
代码来源:GroupsIT.java

示例25: pushToExternalIdsBranchRejectsExternalIdWithoutAccountId

点赞 2

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
@Test
public void pushToExternalIdsBranchRejectsExternalIdWithoutAccountId() throws Exception {
  TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
  fetch(allUsersRepo, RefNames.REFS_EXTERNAL_IDS + ":" + RefNames.REFS_EXTERNAL_IDS);
  allUsersRepo.reset(RefNames.REFS_EXTERNAL_IDS);

  insertExternalIdWithoutAccountId(
      allUsersRepo.getRepository(), allUsersRepo.getRevWalk(), "foo:bar");
  allUsersRepo.reset(RefNames.REFS_EXTERNAL_IDS);

  allowPushOfExternalIds();
  PushResult r = pushHead(allUsersRepo, RefNames.REFS_EXTERNAL_IDS);
  assertRefUpdateFailure(r.getRemoteUpdate(RefNames.REFS_EXTERNAL_IDS), "invalid external IDs");
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:15,
代码来源:ExternalIdIT.java

示例26: matches

点赞 2

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
@Override
boolean matches(Repository git) throws IOException {
  Ref head = git.getRefDatabase().exactRef(Constants.HEAD);
  return head != null
      && head.isSymbolic()
      && RefNames.REFS_CONFIG.equals(head.getLeaf().getName());
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:8,
代码来源:ListProjects.java

示例27: pushToExternalIdsBranchRejectsExternalIdWithEmptyNote

点赞 2

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
@Test
public void pushToExternalIdsBranchRejectsExternalIdWithEmptyNote() throws Exception {
  TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
  fetch(allUsersRepo, RefNames.REFS_EXTERNAL_IDS + ":" + RefNames.REFS_EXTERNAL_IDS);
  allUsersRepo.reset(RefNames.REFS_EXTERNAL_IDS);

  insertExternalIdWithEmptyNote(
      allUsersRepo.getRepository(), allUsersRepo.getRevWalk(), "foo:bar");
  allUsersRepo.reset(RefNames.REFS_EXTERNAL_IDS);

  allowPushOfExternalIds();
  PushResult r = pushHead(allUsersRepo, RefNames.REFS_EXTERNAL_IDS);
  assertRefUpdateFailure(r.getRemoteUpdate(RefNames.REFS_EXTERNAL_IDS), "invalid external IDs");
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:15,
代码来源:ExternalIdIT.java

示例28: canSubmit

点赞 2

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
/** @return true if this user can submit patch sets to this ref */
boolean canSubmit(boolean isChangeOwner) {
  if (RefNames.REFS_CONFIG.equals(refName)) {
    // Always allow project owners to submit configuration changes.
    // Submitting configuration changes modifies the access control
    // rules. Allowing this to be done by a non-project-owner opens
    // a security hole enabling editing of access rules, and thus
    // granting of powers beyond submitting to the configuration.
    return projectControl.isOwner();
  }
  return canPerform(Permission.SUBMIT, isChangeOwner) && isProjectStatePermittingWrite();
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:13,
代码来源:RefControl.java

示例29: createProject

点赞 2

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
@Test
public void createProject() throws Exception {
  String name = name("foo");
  assertThat(gApi.projects().create(name).get().name).isEqualTo(name);

  RevCommit head = getRemoteHead(name, RefNames.REFS_CONFIG);
  eventRecorder.assertRefUpdatedEvents(name, RefNames.REFS_CONFIG, null, head);

  eventRecorder.assertRefUpdatedEvents(name, "refs/heads/master", new String[] {});
  projectIndexedCounter.assertReindexOf(name);
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:12,
代码来源:ProjectIT.java

示例30: canPushWithForce

点赞 2

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
private boolean canPushWithForce() {
  if (!isProjectStatePermittingWrite()
      || (RefNames.REFS_CONFIG.equals(refName) && !projectControl.isOwner())) {
    // Pushing requires being at least project owner, in addition to push.
    // Pushing configuration changes modifies the access control
    // rules. Allowing this to be done by a non-project-owner opens
    // a security hole enabling editing of access rules, and thus
    // granting of powers beyond pushing to the configuration.
    return false;
  }
  return canForcePerform(Permission.PUSH);
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:13,
代码来源:RefControl.java

示例31: canDelete

点赞 2

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
/**
 * Determines whether the user can delete the Git ref controlled by this object.
 *
 * @return {@code true} if the user specified can delete a Git ref.
 */
private boolean canDelete() {
  if (!isProjectStatePermittingWrite() || (RefNames.REFS_CONFIG.equals(refName))) {
    // Never allow removal of the refs/meta/config branch.
    // Deleting the branch would destroy all Gerrit specific
    // metadata about the project, including its access rules.
    // If a project is to be removed from Gerrit, its repository
    // should be removed first.
    return false;
  }

  switch (getUser().getAccessPath()) {
    case GIT:
      return canPushWithForce() || canPerform(Permission.DELETE);

    case JSON_RPC:
    case REST_API:
    case SSH_COMMAND:
    case UNKNOWN:
    case WEB_BROWSER:
    default:
      return (isOwner() && !isForceBlocked(Permission.PUSH))
          || canPushWithForce()
          || canPerform(Permission.DELETE)
          || projectControl.isAdmin();
  }
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:32,
代码来源:RefControl.java

示例32: setHeadToSameBranch

点赞 2

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
@Test
public void setHeadToSameBranch() throws Exception {
  gApi.projects().name(project.get()).branch("test").create(new BranchInput());
  for (String head : new String[] {"test", "refs/heads/test"}) {
    gApi.projects().name(project.get()).head(head);
    assertThat(gApi.projects().name(project.get()).head()).isEqualTo(RefNames.fullName(head));
  }
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:9,
代码来源:ProjectIT.java

示例33: expand

点赞 2

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
private String expand(
    ParameterizedString parameterizedRef, String userName, Account.Id accountId) {
  Map<String, String> params = new HashMap<>();
  params.put(RefPattern.USERNAME, userName);
  if (accountId != null) {
    params.put(RefPattern.USERID_SHARDED, RefNames.shard(accountId.get()));
  }
  return parameterizedRef.replace(params);
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:10,
代码来源:RefPatternMatcher.java

示例34: isRevisionOutOfDate

点赞 2

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
private boolean isRevisionOutOfDate() {
  try (Repository git = gitMgr.openRepository(getNameKey())) {
    Ref ref = git.getRefDatabase().exactRef(RefNames.REFS_CONFIG);
    if (ref == null || ref.getObjectId() == null) {
      return true;
    }
    return !ref.getObjectId().equals(config.getRevision());
  } catch (IOException gone) {
    return true;
  }
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:12,
代码来源:ProjectState.java

示例35: can

点赞 2

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
private boolean can(ProjectPermission perm) throws PermissionBackendException {
  switch (perm) {
    case ACCESS:
      return (!isHidden() && (user.isInternalUser() || canPerformOnAnyRef(Permission.READ)))
          || isOwner();

    case READ:
      return !isHidden() && allRefsAreVisible(Collections.emptySet());

    case READ_NO_CONFIG:
      return !isHidden() && allRefsAreVisible(ImmutableSet.of(RefNames.REFS_CONFIG));

    case CREATE_REF:
      return canAddRefs();
    case CREATE_CHANGE:
      return canCreateChanges();

    case RUN_RECEIVE_PACK:
      return canRunReceivePack();
    case RUN_UPLOAD_PACK:
      return canRunUploadPack();

    case PUSH_AT_LEAST_ONE_REF:
      return canPushToAtLeastOneRef();

    case BAN_COMMIT:
    case READ_REFLOG:
    case READ_CONFIG:
    case WRITE_CONFIG:
      return isOwner();
  }
  throw new PermissionBackendException(perm + " unsupported");
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:34,
代码来源:ProjectControl.java

示例36: migrateData

点赞 2

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException {
  try (Repository git = repoManager.openRepository(allProjectsName);
      MetaDataUpdate md =
          new MetaDataUpdate(GitReferenceUpdated.DISABLED, allProjectsName, git)) {
    ProjectConfig config = ProjectConfig.read(md);

    AccessSection meta = config.getAccessSection(RefNames.REFS_CONFIG, true);
    Permission createRefsMetaConfigPermission = meta.getPermission(Permission.CREATE, true);

    Set<GroupReference> groups =
        Stream.concat(
                config
                    .getAccessSection(AccessSection.GLOBAL_CAPABILITIES, true)
                    .getPermission(GlobalCapability.ADMINISTRATE_SERVER, true)
                    .getRules()
                    .stream()
                    .map(PermissionRule::getGroup),
                Stream.of(systemGroupBackend.getGroup(PROJECT_OWNERS)))
            .filter(g -> createRefsMetaConfigPermission.getRule(g) == null)
            .collect(toSet());

    for (GroupReference group : groups) {
      createRefsMetaConfigPermission.add(new PermissionRule(config.resolve(group)));
    }

    md.getCommitBuilder().setAuthor(serverUser);
    md.getCommitBuilder().setCommitter(serverUser);
    md.setMessage(COMMIT_MSG);
    config.commit(md);
  } catch (ConfigInvalidException | IOException ex) {
    throw new OrmException(ex);
  }
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:35,
代码来源:Schema_135.java

示例37: getObjectId

点赞 2

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
public ObjectId getObjectId(Account.Id accountId, Change.Id changeId) {
  try (Repository repo = repoManager.openRepository(allUsers)) {
    Ref ref = repo.exactRef(RefNames.refsStarredChanges(changeId, accountId));
    return ref != null ? ref.getObjectId() : ObjectId.zeroId();
  } catch (IOException e) {
    log.error(
        String.format(
            "Getting star object ID for account %d on change %d failed",
            accountId.get(), changeId.get()),
        e);
    return ObjectId.zeroId();
  }
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:14,
代码来源:StarredChangesUtil.java

示例38: pushAccountConfigToUserBranchForReviewIsRejectedOnSubmitIfPreferredEmailIsInvalid

点赞 2

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
@Test
public void pushAccountConfigToUserBranchForReviewIsRejectedOnSubmitIfPreferredEmailIsInvalid()
    throws Exception {
  String userRef = RefNames.refsUsers(admin.id);
  TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
  fetch(allUsersRepo, userRef + ":userRef");
  allUsersRepo.reset("userRef");

  String noEmail = "no.email";
  Config ac = getAccountConfig(allUsersRepo);
  ac.setString(AccountConfig.ACCOUNT, null, AccountConfig.KEY_PREFERRED_EMAIL, noEmail);

  PushOneCommit.Result r =
      pushFactory
          .create(
              db,
              admin.getIdent(),
              allUsersRepo,
              "Update account config",
              AccountConfig.ACCOUNT_CONFIG,
              ac.toText())
          .to(MagicBranch.NEW_CHANGE + userRef);
  r.assertOkStatus();
  accountIndexedCounter.assertNoReindex();
  assertThat(r.getChange().change().getDest().get()).isEqualTo(userRef);

  gApi.changes().id(r.getChangeId()).current().review(ReviewInput.approve());
  exception.expect(ResourceConflictException.class);
  exception.expectMessage(
      String.format(
          "invalid account configuration: invalid preferred email '%s' for account '%s'",
          noEmail, admin.id));
  gApi.changes().id(r.getChangeId()).current().submit();
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:35,
代码来源:AccountIT.java

示例39: parseUpdate

点赞 2

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
private void parseUpdate(ReceiveCommand cmd) throws PermissionBackendException {
  logDebug("Updating {}", cmd);
  boolean ok;
  try {
    permissions.ref(cmd.getRefName()).check(RefPermission.UPDATE);
    ok = true;
  } catch (AuthException err) {
    ok = false;
  }
  if (ok) {
    if (isHead(cmd) && !isCommit(cmd)) {
      return;
    }
    if (!validRefOperation(cmd)) {
      return;
    }
    validateNewCommits(new Branch.NameKey(project.getNameKey(), cmd.getRefName()), cmd);
    actualCommands.add(cmd);
  } else {
    if (RefNames.REFS_CONFIG.equals(cmd.getRefName())) {
      errors.put(ReceiveError.CONFIG_UPDATE, RefNames.REFS_CONFIG);
    } else {
      errors.put(ReceiveError.UPDATE, cmd.getRefName());
    }
    reject(cmd, "prohibited by Gerrit: ref update access denied");
  }
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:28,
代码来源:ReceiveCommits.java

示例40: rejectDoubleInheritance

点赞 2

import com.google.gerrit.reviewdb.client.RefNames; //导入依赖的package包/类
@Test
public void rejectDoubleInheritance() throws Exception {
  setApiUser(admin);
  // Create separate projects to test the config
  Project.NameKey parent = createProject("projectToInheritFrom");
  Project.NameKey child = createProject("projectWithMalformedConfig");

  String config =
      gApi.projects()
          .name(child.get())
          .branch(RefNames.REFS_CONFIG)
          .file("project.config")
          .asString();

  // Append and push malformed project config
  String pattern = "[access]\n\tinheritFrom = " + allProjects.get() + "\n";
  String doubleInherit = pattern + "\tinheritFrom = " + parent.get() + "\n";
  config = config.replace(pattern, doubleInherit);

  TestRepository<InMemoryRepository> childRepo = cloneProject(child, admin);
  // Fetch meta ref
  GitUtil.fetch(childRepo, RefNames.REFS_CONFIG + ":cfg");
  childRepo.reset("cfg");
  PushOneCommit push =
      pushFactory.create(db, admin.getIdent(), childRepo, "Subject", "project.config", config);
  PushOneCommit.Result res = push.to(RefNames.REFS_CONFIG);
  res.assertErrorStatus();
  res.assertMessage("cannot inherit from multiple projects");
}
 

开发者ID:gerrit-review,
项目名称:gerrit,
代码行数:30,
代码来源:ConfigChangeIT.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)