org.eclipse.jgit.api.Git.open()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(166)

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

Git.open介绍

[英]Open repository
[中]开放存储库

代码示例

代码示例来源:origin: spring-cloud/spring-cloud-config

public Git getGitByOpen(File file) throws IOException {
  Git git = Git.open(file);
  return git;
}

代码示例来源:origin: jphp-group/jphp

@Signature
public void __construct(File directory, boolean create) throws IOException, GitAPIException {
  try {
    __wrappedObject = Git.open(directory, FS.DETECTED);
  } catch (RepositoryNotFoundException e) {
    if (create) {
      Git.init().setBare(false).setDirectory(directory).call();
      __wrappedObject = Git.open(directory, FS.DETECTED);
    }
  }
}

代码示例来源:origin: oracle/helidon

if (dirStream.iterator().hasNext()) {
  try {
    recordGit(Git.open(directory.toFile()));
  } catch (IOException e) {
    throw new ConfigException(

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

/**
 * Open repository
 *
 * @param dir
 *            the repository to open. May be either the GIT_DIR, or the
 *            working tree directory that contains {@code .git}.
 * @return a {@link org.eclipse.jgit.api.Git} object for the existing git
 *         repository
 * @throws java.io.IOException
 */
public static Git open(File dir) throws IOException {
  return open(dir, FS.DETECTED);
}

代码示例来源:origin: apache/incubator-gobblin

this.git = Git.open(repoDirFile);

代码示例来源:origin: FlowCI/flow-platform

private boolean checkExistBranchOrNot(Path path) {
    try (Git git = Git.open(path.toFile())) {
      if (git.branchList().call().isEmpty()) {
        return false;
      }
    } catch (Throwable e) {
      log.error("Method: checkExistBranchOrNot Exception", e);
    }
    return true;
  }
}

代码示例来源:origin: FlowCI/flow-platform

public static Repository getRepo(Path path) throws GitException {
  try (Git git = Git.open(path.toFile())) {
    return git.getRepository();
  } catch (IOException e) {
    throw new GitException(e.getMessage());
  }
}

代码示例来源:origin: FlowCI/flow-platform

private Git gitOpen() throws GitException {
  try {
    return Git.open(getGitPath().toFile());
  } catch (IOException e) {
    throw new GitException("Fail to open .git folder", e);
  }
}

代码示例来源:origin: FlowCI/flow-platform

/**
 * List branch commits
 * @param path
 * @return
 * @throws GitException
 */
public static List<RevCommit> listCommits(Path path) throws GitException {
  try (Git git = Git.open(path.toFile())) {
    Iterable<RevCommit> iterable = git.log().call();
    List<RevCommit> commits = stream(iterable.spliterator(), false).collect(toList());
    return commits;
  } catch (Throwable throwable) {
    throw new GitException("get commits error", throwable);
  }
}

代码示例来源:origin: FlowCI/flow-platform

public static List<String> tags(Path gitPath) throws GitException {
  try (Git git = Git.open(gitPath.toFile())) {
    try (Repository repo = git.getRepository()) {
      return tags(repo);
    }
  } catch (IOException e) {
    throw new GitException(e.getMessage());
  }
}

代码示例来源:origin: FlowCI/flow-platform

public static Path checkout(Path path, String branch) throws GitException {
  try (Git git = Git.open(path.toFile())) {
    git
      .checkout()
      .setName(branch)
      .call();
  } catch (Throwable throwable) {
    throw new GitException("fetch tags error", throwable);
  }
  return path;
}

代码示例来源:origin: FlowCI/flow-platform

private void commitSomething(Path path) {
  try (Git git = Git.open(path.toFile())) {
    Path emptyFilePath = Paths.get(path.toString(), EMPTY_FILE);
    try {
      Files.createFile(emptyFilePath);
    } catch (FileAlreadyExistsException ignore) {
    }
    git.add()
      .addFilepattern(".")
      .call();
    git.commit()
      .setMessage("add test branch")
      .call();
  } catch (Throwable e) {
    log.error("Method: commitSomething Exception", e);
  }
}

代码示例来源:origin: yacy/yacy_grid_mcp

public GitTool() {
  File gitWorkDir = new File(".");
  try {
    Git git = Git.open(gitWorkDir);
    Iterable<RevCommit> commits = git.log().all().call();
    Repository repo = git.getRepository();
    branch = repo.getBranch();
    RevCommit latestCommit = commits.iterator().next();
    name = latestCommit.getName();
    message = latestCommit.getFullMessage();
  } catch (Throwable e) {
    name = "";
    message = "";
    branch = "";
  }
}

代码示例来源:origin: FlowCI/flow-platform

/**
 * Setting remote url to local repo
 *
 * @param path
 * @param remoteName
 * @param remoteUrl
 * @return
 * @throws GitException
 */
public static Path remoteSet(Path path, String remoteName, String remoteUrl) throws GitException {
  try (Git git = Git.open(path.toFile())) {
    StoredConfig config = git.getRepository().getConfig();
    config.setString("remote", remoteName, "url", remoteUrl);
    config.save();
  } catch (IOException e) {
    throw new GitException("set remote url exception", e);
  }
  return path;
}

代码示例来源:origin: FlowCI/flow-platform

Git git = Git.open(actPath.toFile());

代码示例来源:origin: FlowCI/flow-platform

/**
 * Push code to remote repo
 *
 * @param path
 * @param remote
 * @param branchOrTag
 * @return
 * @throws GitException
 */
public static Path push(Path path, String remote, String branchOrTag) throws GitException {
  try (Git git = Git.open(path.toFile())) {
    git.push()
      .setRemote(remote)
      .setRefSpecs(new RefSpec(branchOrTag))
      .call();
  } catch (Throwable throwable) {
    throw new GitException("Fail to Push ", throwable);
  }
  return path;
}

代码示例来源:origin: FlowCI/flow-platform

/**
 * fetch tags from remote
 * @param path
 * @param remoteName
 * @return
 * @throws GitException
 */
public static Path fetchTags(Path path, String remoteName) throws GitException {
  try (Git git = Git.open(path.toFile())) {
    git.fetch()
      .setRemote(remoteName)
      .setRefSpecs(new RefSpec("refs/tags/*:refs/tags/*"))
      .setTagOpt(TagOpt.FETCH_TAGS)
      .call();
  } catch (Throwable throwable) {
    throw new GitException("fetch tags error", throwable);
  }
  return path;
}

代码示例来源:origin: pridkett/gitminer

static private Git updateRepository(final String name) {
  try {
    Git repo = Git.open( new File( LOCAL_STORE, name ) );
    //TODO i'm unsure about this...
    //repo.fetch();
    return repo;
  } catch (IOException e) {
    log.error("Exception encountered opening repository:", e);
  }
  return null;
}

代码示例来源:origin: mauricioaniche/repodriller

protected Git openRepository() throws IOException, GitAPIException {
  Git git = Git.open(new File(path));
  if (this.mainBranchName == null) {
    this.mainBranchName = discoverMainBranchName(git);
  }
  return git;
}

代码示例来源:origin: indeedeng/proctor

private Git pullRepository(final File workingDir) throws GitAPIException, IOException {
  final Git git = Git.open(workingDir);
  git.pull().setProgressMonitor(PROGRESS_MONITOR)
      .setRebase(true)
      .setCredentialsProvider(user)
      .setTimeout(pullPushTimeoutSeconds)
      .call();
  return git;
}

相关文章