public void updateChoices(boolean reportError, Form<?> form) {
   final String repoUriStr = repositoryUriModel.getObject();
   if (REPOSITORY.sample != null && REPOSITORY.sample.equals(repoUriStr)) {
     return;
   }
   List<String> branchNames = new ArrayList<>();
   if (repoUriStr != null) {
     try {
       RepositoryManager manager = this.manager.get();
       URI repoURI = new URI(repoUriStr);
       RepositoryResolver resolver = RepositoryResolver.lookup(repoURI);
       String repoName = resolver.getName(repoURI);
       RepositoryInfo repoInfo = manager.getByRepoName(repoName);
       String repoId = repoInfo.getId();
       List<Ref> branchRefs = manager.listBranches(repoId);
       for (Ref branch : branchRefs) {
         branchNames.add(branch.localName());
       }
     } catch (IOException | URISyntaxException e) {
       if (reportError) {
         form.error("Could not list branches: " + e.getMessage());
       }
       branchNames = new ArrayList<String>();
     }
     String current = (String) choice.getModelObject();
     if (current != null && !branchNames.contains(current)) {
       branchNames.add(0, current);
     }
   }
   choice.setChoices(branchNames);
 }
Beispiel #2
0
  protected Ref _call() {
    checkState(branchName != null, "branch name was not provided");
    final String branchRefPath = Ref.append(Ref.HEADS_PREFIX, branchName);
    checkArgument(
        force || !command(RefParse.class).setName(branchRefPath).call().isPresent(),
        "A branch named '" + branchName + "' already exists.");

    command(CheckRefFormat.class).setThrowsException(true).setRef(branchRefPath).call();

    Optional<Ref> branchRef;
    if (orphan) {
      branchRef = command(UpdateRef.class).setName(branchRefPath).setNewValue(ObjectId.NULL).call();
    } else {
      final String branchOrigin = Optional.fromNullable(commit_ish).or(Ref.HEAD);

      final ObjectId branchOriginCommitId = resolveOriginCommitId(branchOrigin);

      branchRef =
          command(UpdateRef.class).setName(branchRefPath).setNewValue(branchOriginCommitId).call();
      checkState(branchRef.isPresent());
    }

    if (checkout) {
      command(CheckoutOp.class).setSource(branchRefPath).call();
    }
    return branchRef.get();
  }