org.eclipse.jgit.lib.Repository.getRemoteNames()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(140)

本文整理了Java中org.eclipse.jgit.lib.Repository.getRemoteNames方法的一些代码示例,展示了Repository.getRemoteNames的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Repository.getRemoteNames方法的具体详情如下:
包路径:org.eclipse.jgit.lib.Repository
类名称:Repository
方法名:getRemoteNames

Repository.getRemoteNames介绍

[英]Get the names of all known remotes
[中]获取所有已知遥控器的名称

代码示例

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Get remote name
 *
 * @param refName
 *            a {@link java.lang.String} object.
 * @return the remote name part of <code>refName</code>, i.e. without the
 *         <code>refs/remotes/&lt;remote&gt;</code> prefix, if
 *         <code>refName</code> represents a remote tracking branch;
 *         otherwise {@code null}.
 * @since 3.4
 */
@Nullable
public String getRemoteName(String refName) {
  for (String remote : getRemoteNames()) {
    String remotePrefix = Constants.R_REMOTES + remote + "/"; //$NON-NLS-1$
    if (refName.startsWith(remotePrefix))
      return remote;
  }
  return null;
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Get a shortened more user friendly remote tracking branch name
 *
 * @param refName
 *            a {@link java.lang.String} object.
 * @return the remote branch name part of <code>refName</code>, i.e. without
 *         the <code>refs/remotes/&lt;remote&gt;</code> prefix, if
 *         <code>refName</code> represents a remote tracking branch;
 *         otherwise {@code null}.
 * @since 3.4
 */
@Nullable
public String shortenRemoteBranchName(String refName) {
  for (String remote : getRemoteNames()) {
    String remotePrefix = Constants.R_REMOTES + remote + "/"; //$NON-NLS-1$
    if (refName.startsWith(remotePrefix))
      return refName.substring(remotePrefix.length());
  }
  return null;
}

代码示例来源:origin: org.wildfly.core/wildfly-server

public final boolean isValidRemoteName(String remoteName) {
  return repository.getRemoteNames().contains(remoteName);
}

代码示例来源:origin: wildfly/wildfly-core

public final boolean isValidRemoteName(String remoteName) {
  return repository.getRemoteNames().contains(remoteName);
}

代码示例来源:origin: sonia.jgit/org.eclipse.jgit

/**
 * @param refName
 * @return the remote branch name part of <code>refName</code>, i.e. without
 *         the <code>refs/remotes/&lt;remote&gt;</code> prefix, if
 *         <code>refName</code> represents a remote tracking branch;
 *         otherwise {@code null}.
 * @since 3.4
 */
@Nullable
public String shortenRemoteBranchName(String refName) {
  for (String remote : getRemoteNames()) {
    String remotePrefix = Constants.R_REMOTES + remote + "/"; //$NON-NLS-1$
    if (refName.startsWith(remotePrefix))
      return refName.substring(remotePrefix.length());
  }
  return null;
}

代码示例来源:origin: sonia.jgit/org.eclipse.jgit

/**
 * @param refName
 * @return the remote name part of <code>refName</code>, i.e. without the
 *         <code>refs/remotes/&lt;remote&gt;</code> prefix, if
 *         <code>refName</code> represents a remote tracking branch;
 *         otherwise {@code null}.
 * @since 3.4
 */
@Nullable
public String getRemoteName(String refName) {
  for (String remote : getRemoteNames()) {
    String remotePrefix = Constants.R_REMOTES + remote + "/"; //$NON-NLS-1$
    if (refName.startsWith(remotePrefix))
      return remote;
  }
  return null;
}

代码示例来源:origin: com.g2forge.gearbox/gb-git

public static String getMyRemote(final Git git) {
  final Set<String> remotes = git.getRepository().getRemoteNames();
  if (remotes.size() == 1) return HCollection.getOne(remotes);
  if (remotes.size() == 2) {
    if (remotes.contains(Constants.DEFAULT_REMOTE_NAME)) {
      final Set<String> modify = new HashSet<>(remotes);
      modify.remove(Constants.DEFAULT_REMOTE_NAME);
      return HCollection.getOne(modify);
    }
  }
  throw new IllegalStateException(String.format("Cannot automatically guess your git remote from among %1$s!", remotes));
}

代码示例来源:origin: berlam/github-bucket

/**
 * Get a shortened more user friendly remote tracking branch name
 *
 * @param refName
 *            a {@link java.lang.String} object.
 * @return the remote branch name part of <code>refName</code>, i.e. without
 *         the <code>refs/remotes/&lt;remote&gt;</code> prefix, if
 *         <code>refName</code> represents a remote tracking branch;
 *         otherwise {@code null}.
 * @since 3.4
 */
@Nullable
public String shortenRemoteBranchName(String refName) {
  for (String remote : getRemoteNames()) {
    String remotePrefix = Constants.R_REMOTES + remote + "/"; //$NON-NLS-1$
    if (refName.startsWith(remotePrefix))
      return refName.substring(remotePrefix.length());
  }
  return null;
}

代码示例来源:origin: berlam/github-bucket

/**
 * Get remote name
 *
 * @param refName
 *            a {@link java.lang.String} object.
 * @return the remote name part of <code>refName</code>, i.e. without the
 *         <code>refs/remotes/&lt;remote&gt;</code> prefix, if
 *         <code>refName</code> represents a remote tracking branch;
 *         otherwise {@code null}.
 * @since 3.4
 */
@Nullable
public String getRemoteName(String refName) {
  for (String remote : getRemoteNames()) {
    String remotePrefix = Constants.R_REMOTES + remote + "/"; //$NON-NLS-1$
    if (refName.startsWith(remotePrefix))
      return remote;
  }
  return null;
}

代码示例来源:origin: wildfly/wildfly-core

private String findRemoteName(String gitRepository) {
  if (isValidRemoteName(gitRepository)) {
    return gitRepository;
  }
  StoredConfig config = repository.getConfig();
  for (String remoteName : repository.getRemoteNames()) {
    if (gitRepository.equals(config.getString("remote", remoteName, "url"))) {
      return remoteName;
    }
  }
  return null;
}

代码示例来源:origin: org.wildfly.core/wildfly-server

private String findRemoteName(String gitRepository) {
  if (isValidRemoteName(gitRepository)) {
    return gitRepository;
  }
  StoredConfig config = repository.getConfig();
  for (String remoteName : repository.getRemoteNames()) {
    if (gitRepository.equals(config.getString("remote", remoteName, "url"))) {
      return remoteName;
    }
  }
  return null;
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-contract-stub-runner

private Git cloneToBasedir(URI projectUrl, File destinationFolder) {
  String url = projectUrl.toString();
  String projectGitUrl = url.endsWith(".git") ? url : url + ".git";
  if (log.isDebugEnabled()) {
    log.debug("Project git url [" + projectGitUrl + "]");
  }
  CloneCommand command = this.gitFactory.getCloneCommandByCloneRepository()
      .setURI(projectGitUrl).setDirectory(destinationFolder);
  try {
    Git git = command.call();
    if (git.getRepository().getRemoteNames().isEmpty()) {
      log.info("No remote added. Will add remote of the cloned project");
      git.remoteSetUrl().setUri(new URIish(projectGitUrl));
      git.remoteSetUrl().setName("origin");
      git.remoteSetUrl().setPush(true);
    }
    return git;
  }
  catch (GitAPIException | URISyntaxException e) {
    deleteBaseDirIfExists();
    throw new IllegalStateException(e);
  }
}

代码示例来源:origin: alien4cloud/alien4cloud

/**
 * Git push to a remote.
 *
 * @param git The git repository.
 * @param username The username to use for the repository connection.
 * @param password The password to use for the repository connection.
 * @param localBranch The name of the local branch to push.
 * @param remoteBranch The name of the remote branch to push to.
 * @return <code>true</code> pushed, <code>false</code> otherwise.
 */
public static boolean push(Git git, String username, String password, String localBranch, String remoteBranch) {
  try {
    if (git.getRepository().getRemoteNames().isEmpty()) {
      throw new GitException("No remote found for the repository");
    }
    PushCommand pushCommand = git.push();
    setCredentials(pushCommand, username, password);
    RefSpec refSpec = new RefSpec(String.format("refs/heads/%s:refs/heads/%s", localBranch, remoteBranch));
    pushCommand.setRefSpecs(refSpec);
    Iterable<PushResult> call = pushCommand.call();
    return isPushed(call);
  } catch (GitAPIException e) {
    throw new GitException(String.format("Error when trying to git push: %s", e.getMessage()), e);
  }
}

代码示例来源:origin: alien4cloud/alien4cloud

String remoteName = repository.getRemoteNames().iterator().next(); // Only handle one remote (default: 'origin')
log.debug(String.format("Couldn't push git repository=%s to remote=%s on the branch=%s", git.getRepository().getDirectory(), remoteName,
    repository.getBranch()));

代码示例来源:origin: alien4cloud/alien4cloud

try {
  git = Git.open(repositoryDirectory.resolve(".git").toFile());
  if (git.getRepository().getRemoteNames().isEmpty()) {
    throw new GitException("No remote found for the repository");

代码示例来源:origin: org.uberfire/uberfire-nio2-jgit

hooksDir).execute();
assertThat(origin.getRepository().getRemoteNames()).isEmpty();

代码示例来源:origin: org.uberfire/uberfire-nio2-jgit

@Test
public void cloneSubdirectorySingleBranch() throws Exception {
  final File parentFolder = createTempDirectory();
  final File sourceDir = new File(parentFolder,
                  SOURCE_GIT + ".git");
  final File targetDir = new File(parentFolder,
                  TARGET_GIT + ".git");
  final Git origin = gitRepo(sourceDir);
  commit(origin, "master", "first", content("dir1/file.txt", "foo"));
  commit(origin, "master", "second", content("dir2/file2.txt", "bar"));
  commit(origin, "master", "third", content("file3.txt", "moogah"));
  final Git cloned = new SubdirectoryClone(targetDir,
                       sourceDir.getAbsoluteFile().toURI().toString(),
                       "dir1",
                       singletonList("master"),
                       CredentialsProvider.getDefault(),
                       null,
                       null).execute();
  assertThat(origin.getRepository().getRemoteNames()).isEmpty();
  assertThat(cloned).isNotNull();
  assertThat(listRefs(cloned)).hasSize(1);
  final List<RevCommit> cloneCommits = getCommits(cloned, "master");
  assertThat(cloneCommits).hasSize(1);
  final RevCommit clonedCommit = cloneCommits.get(0);
  final RevCommit originCommit = getCommits(origin, "master").get(2); // Ordered children first
  assertClonedCommitData(origin, "dir1", clonedCommit, originCommit);
}

代码示例来源:origin: kiegroup/appformer

@Test
public void cloneSubdirectorySingleBranch() throws Exception {
  final File parentFolder = createTempDirectory();
  final File sourceDir = new File(parentFolder,
                  SOURCE_GIT + ".git");
  final File targetDir = new File(parentFolder,
                  TARGET_GIT + ".git");
  final Git origin = gitRepo(sourceDir);
  commit(origin, "master", "first", content("dir1/file.txt", "foo"));
  commit(origin, "master", "second", content("dir2/file2.txt", "bar"));
  commit(origin, "master", "third", content("file3.txt", "moogah"));
  final Git cloned = new SubdirectoryClone(targetDir,
                       sourceDir.getAbsoluteFile().toURI().toString(),
                       "dir1",
                       singletonList("master"),
                       CredentialsProvider.getDefault(),
                       null,
                       null).execute();
  assertThat(origin.getRepository().getRemoteNames()).isEmpty();
  assertThat(cloned).isNotNull();
  assertThat(listRefs(cloned)).hasSize(1);
  final List<RevCommit> cloneCommits = getCommits(cloned, "master");
  assertThat(cloneCommits).hasSize(1);
  final RevCommit clonedCommit = cloneCommits.get(0);
  final RevCommit originCommit = getCommits(origin, "master").get(2); // Ordered children first
  assertClonedCommitData(origin, "dir1", clonedCommit, originCommit);
}

代码示例来源:origin: kiegroup/appformer

hooksDir).execute();
assertThat(origin.getRepository().getRemoteNames()).isEmpty();

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit.lfs

if (lfsUrl == null) {
  String remoteUrl = null;
  for (String remote : db.getRemoteNames()) {
    lfsUrl = config.getString(ConfigConstants.CONFIG_SECTION_LFS,
        remote,

相关文章

Repository类方法