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

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

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

Git.<init>介绍

[英]Construct a new org.eclipse.jgit.api.Git object which can interact with the specified git repository.

All command classes returned by methods of this class will always interact with this git repository.

The caller is responsible for closing the repository; #close() on this instance does not close the repo.
[中]构建一个新的组织。日食jgit。应用程序编程接口。可以与指定Git存储库交互的Git对象。
此类方法返回的所有命令类都将始终与此git存储库交互。
调用方负责关闭存储库#此实例上的close()不会关闭repo。

代码示例

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

@Autowired
public ConfigRepository(SystemEnvironment systemEnvironment) throws IOException {
  this.systemEnvironment = systemEnvironment;
  workingDir = this.systemEnvironment.getConfigRepoDir();
  File configRepoDir = new File(workingDir, ".git");
  gitRepo = new FileRepositoryBuilder().setGitDir(configRepoDir).build();
  gitRepo.getConfig().setInt("gc", null, "auto", 0);
  git = new Git(gitRepo);
}

代码示例来源:origin: apache/usergrid

/**
 * @param gitConfigFolder e.g. /your/project/root/.git
 *
 * @return Returns true if 'git status' has modified files inside the 'Changes to be committed' section
 */
public static boolean isCommitNecessary( String gitConfigFolder ) throws MojoExecutionException {
  try {
    Repository repo = new FileRepository( gitConfigFolder );
    Git git = new Git( repo );
    Status status = git.status().call();
    Set<String> modified = status.getModified();
    return ( modified.size() != 0 );
  }
  catch ( Exception e ) {
    throw new MojoExecutionException( "Error trying to find out if git commit is needed", e );
  }
}

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

/**
 * Wrap repository
 *
 * @param repo
 *            the git repository this class is interacting with;
 *            {@code null} is not allowed.
 * @return a {@link org.eclipse.jgit.api.Git} object for the existing git
 *         repository. The caller is responsible for closing the repository;
 *         {@link #close()} on this instance does not close the repo.
 */
public static Git wrap(Repository repo) {
  return new Git(repo);
}

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

private static RevCommitsPair resolveRevCommitsPair(Repository repo) {
  RevCommitsPair revCommitIteratorPair;
  try (RevWalk revWalk = new RevWalk(repo); Git git = new Git(repo)) {
    final Iterator<RevCommit> first;
    final Iterator<RevCommit> second;
    final ObjectId headId = repo.resolve(Constants.HEAD);
    final RevCommit headCommit = revWalk.parseCommit(headId);
    if (isMergeCommit(headCommit)) {
      final RevCommit firstParent = headCommit.getParent(0);
      final RevCommit secondParent = headCommit.getParent(1);
      first = git.log().add(firstParent).call().iterator();
      second = git.log().add(secondParent).call().iterator();
    }
    else {
      first = git.log().call().iterator();
      second = Collections.emptyIterator();
    }
    revCommitIteratorPair =
        new RevCommitsPair(new OmitMergeCommitsIterator(first),
            new OmitMergeCommitsIterator(second));
  }
  catch (GitAPIException | IOException ignored) {
    revCommitIteratorPair = new RevCommitsPair();
  }
  return revCommitIteratorPair;
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
  try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
    try (Git git = new Git(repository)) {
      Properties ret = git.gc().
          setProgressMonitor(new PrintlnProgressMonitor()).call();
      for(Map.Entry<Object, Object> entry : ret.entrySet()) {
        System.out.println("Ret: " + entry.getKey() + ": " + entry.getValue());
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
  try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
    try (Git git = new Git(repository)) {
      Properties ret = git.gc().
          setProgressMonitor(new PrintlnProgressMonitor()).call();
      for(Map.Entry<Object, Object> entry : ret.entrySet()) {
        System.out.println("Ret: " + entry.getKey() + ": " + entry.getValue());
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
  try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
    try (Git git = new Git(repository)) {
      List<Ref> call = git.branchList().call();
      for (Ref ref : call) {
        List<Integer> counts = getCounts(repository, ref.getName());
        System.out.println("For branch: " + ref.getName());
        System.out.println("Commits ahead : " + counts.get(0));
        System.out.println("Commits behind : " + counts.get(1));
        System.out.println();
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
  try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
    try (Git git = new Git(repository)) {
      List<Ref> call = git.branchList().call();
      for (Ref ref : call) {
        List<Integer> counts = getCounts(repository, ref.getName());
        System.out.println("For branch: " + ref.getName());
        System.out.println("Commits ahead : " + counts.get(0));
        System.out.println("Commits behind : " + counts.get(1));
        System.out.println();
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      try (Git git = new Git(repository)) {
        Iterable<RevCommit> commits = git.log().all().call();
        int count = 0;
        for (RevCommit commit : commits) {
          System.out.println("LogCommit: " + commit);
          count++;
        }
        System.out.println(count);
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      try (Git git = new Git(repository)) {
        Iterable<RevCommit> commits = git.log().all().call();
        int count = 0;
        for (RevCommit commit : commits) {
          System.out.println("LogCommit: " + commit);
          count++;
        }
        System.out.println(count);
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      System.out.println("Starting fetch");
      try (Git git = new Git(repository)) {
        FetchResult result = git.fetch().setCheckFetchedObjects(true).call();
        System.out.println("Messages: " + result.getMessages());
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      System.out.println("Starting fetch");
      try (Git git = new Git(repository)) {
        FetchResult result = git.fetch().setCheckFetchedObjects(true).call();
        System.out.println("Messages: " + result.getMessages());
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

private static void listReflog(Repository repository, Ref ref) throws GitAPIException {
    /*
     * Ref head = repository.getRef(ref.getName());
     * RevWalk walk = new RevWalk(repository);
     * RevCommit commit = walk.parseCommit(head.getObjectId());
     */

    try (Git git = new Git(repository)) {
      Collection<ReflogEntry> call = git.reflog().setRef(ref.getName()).call();
      for (ReflogEntry reflog : call) {
        System.out.println("Reflog: " + reflog);
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

private static void listReflog(Repository repository, Ref ref) throws GitAPIException {
    /*
     * Ref head = repository.getRef(ref.getName());
     * RevWalk walk = new RevWalk(repository);
     * RevCommit commit = walk.parseCommit(head.getObjectId());
     */

    try (Git git = new Git(repository)) {
      Collection<ReflogEntry> call = git.reflog().setRef(ref.getName()).call();
      for (ReflogEntry reflog : call) {
        System.out.println("Reflog: " + reflog);
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

private static void addSubmodule(Repository mainRepo) throws GitAPIException {
  System.out.println("Adding submodule");
  try (Git git = new Git(mainRepo)) {
    try (Repository subRepoInit = git.submoduleAdd().
        setURI("https://github.com/github/testrepo.git").
        setPath("testrepo").
        call()) {
      if(subRepoInit.isBare()) {
        throw new IllegalStateException("Repository at " + subRepoInit.getDirectory() + " should not be bare");
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

private static void addSubmodule(Repository mainRepo) throws GitAPIException {
  System.out.println("Adding submodule");
  try (Git git = new Git(mainRepo)) {
    try (Repository subRepoInit = git.submoduleAdd().
        setURI("https://github.com/github/testrepo.git").
        setPath("testrepo").
        call()) {
      if(subRepoInit.isBare()) {
        throw new IllegalStateException("Repository at " + subRepoInit.getDirectory() + " should not be bare");
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
  try (final Repository repo = CookbookHelper.openJGitCookbookRepository()) {
    try (final Git git = new Git(repo)) {
      final String testFile = "README.md";
      // Modify the file
      FileUtils.write(new File(testFile), new Date().toString(), "UTF-8");
      System.out.println("Modified files: " + getModifiedFiles(git));
      new AssumeChangedCommand(repo, testFile, true).call();
      System.out.println("Modified files after assume-changed: " + getModifiedFiles(git));
      new AssumeChangedCommand(repo, testFile, false).call();
      System.out.println("Modified files after no-assume-changed: " + getModifiedFiles(git));
      git.checkout().addPath(testFile).call();
      System.out.println("Modified files after reset: " + getModifiedFiles(git));
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      try (Git git = new Git(repository)) {
        List<Note> call = git.notesList().call();
        System.out.println("Listing " + call.size() + " notes");
        for (Note note : call) {
          System.out.println("Note: " + note + " " + note.getName() + " " + note.getData().getName() + "\nContent: ");

          // displaying the contents of the note is done via a simple blob-read
          ObjectLoader loader = repository.open(note.getData());
          loader.copyTo(System.out);
        }
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      try (Git git = new Git(repository)) {
        List<Note> call = git.notesList().call();
        System.out.println("Listing " + call.size() + " notes");
        for (Note note : call) {
          System.out.println("Note: " + note + " " + note.getName() + " " + note.getData().getName() + "\nContent: ");

          // displaying the contents of the note is done via a simple blob-read
          ObjectLoader loader = repository.open(note.getData());
          loader.copyTo(System.out);
        }
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
  try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
    try (Git git = new Git(repository)) {
      List<Ref> refs = git.branchList().call();
      for (Ref ref : refs) {
        System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
        listReflog(repository, ref);
      }
      List<Ref> call = git.tagList().call();
      for (Ref ref : call) {
        System.out.println("Tag: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
        listReflog(repository, ref);
      }
    }
  }
}

相关文章