Example #1
0
 private static FetchResult fetch(File directory, String url) throws GitException {
   try {
     String remoteOfUrl = getRemoteOfUrl(directory, url);
     Git git = openRepository(directory);
     return git.fetch().setRemote(remoteOfUrl).call();
   } catch (GitAPIException e) {
     throw new GitException("Fetch of repository " + url + " failed", e);
   }
 }
  public static void main(final String[] args) throws Exception {

    logger.debug("init");

    final FileRepositoryBuilder builder = new FileRepositoryBuilder();
    builder.setGitDir(FILE);
    builder.readEnvironment();
    builder.findGitDir();

    final Repository repo = builder.build();

    // logger.debug("branch=" + repo.getBranch());
    // logger.debug("state=" + repo.getRepositoryState());

    switch (repo.getRepositoryState()) {
      case BARE:
        break;
      case SAFE:
        break;
      default:
        logger.error("wrong state");
    }

    final Git git = make();
    logger.debug("state=" + git.getRepository().getRepositoryState());

    // git.checkout().setName(Constants.MASTER).call();
    // git.pull().setTimeout(10).call();

    git.fetch().call();

    git.checkout().setName("current-config").call();

    // runClone();

    // final Git git = Git.open(FILE);
    // final StatusCommand status = git.status();
    // final Status result = status.call();
    // logger.debug("result=" + result);

    // final Git git = new Git(repo);

    // final RevCommit commit =
    // git.commit().setMessage("test commit").call();

    // final RevTag tag = git.tag().setName("test_tag").call();

    // logger.debug("branch=" + repo.getBranch());
    // logger.debug("state=" + repo.getRepositoryState());

    logger.debug("done");
  }
Example #3
0
 public void run(ForkEntry fe, Object arg) throws Exception {
   Git git = (Git) arg;
   RefSpec all;
   String fork = GitWorks.getSafeName(fe);
   //    System.out.print("Adding " + fork + " ...");
   //    System.out.flush();
   StoredConfig config = git.getRepository().getConfig();
   config.setString("remote", fork, "url", GitWorks.getProjectPath(fe));
   config.setString("remote", fork, "fetch", "+refs/heads/*:refs/remotes/" + fork + "/*");
   config.save();
   all = new RefSpec(config.getString("remote", fork, "fetch"));
   git.fetch().setRemote(fork).setRefSpecs(all).call();
   //    System.out.println(" done!");
   //    System.out.flush();
 }
Example #4
0
  public static List<Ref> getRemoteBranches(final Git repo) throws GitAPIException {
    List<Ref> results = new ArrayList<Ref>();
    try {
      FetchResult fetch = repo.fetch().setRemote("origin").call();
      Collection<Ref> refs = fetch.getAdvertisedRefs();
      for (Ref ref : refs) {
        if (ref.getName().startsWith("refs/heads")) {
          results.add(ref);
        }
      }
    } catch (InvalidRemoteException e) {
      e.printStackTrace();
    }

    return results;
  }
Example #5
0
  private void reload(String botName) throws IOException, GitAPIException {
    log.info("Starting bot reload");
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    Repository repository =
        builder.setGitDir(new File(arguments.getBasePath() + "/.git")).readEnvironment().build();
    log.info("Starting repository update");
    Git git = new Git(repository);
    git.reset().setMode(ResetCommand.ResetType.HARD).call();
    log.info("Reset complete");
    git.clean().call();
    log.info("Clean compete");
    git.fetch().call();
    log.info("Fetch complete");
    git.pull().call();
    log.info("Repository update finished");

    initBot(botName);
    log.info("Bot reloaded");
  }
Example #6
0
  @Override
  protected void run() throws Exception {
    try (Git git = new Git(db)) {
      FetchCommand fetch = git.fetch();
      if (fsck != null) fetch.setCheckFetchedObjects(fsck.booleanValue());
      if (prune != null) fetch.setRemoveDeletedRefs(prune.booleanValue());
      if (toget != null) fetch.setRefSpecs(toget);
      if (tags != null) {
        fetch.setTagOpt(tags.booleanValue() ? TagOpt.FETCH_TAGS : TagOpt.NO_TAGS);
      }
      if (0 <= timeout) fetch.setTimeout(timeout);
      fetch.setDryRun(dryRun);
      fetch.setRemote(remote);
      if (thin != null) fetch.setThin(thin.booleanValue());
      if (quiet == null || !quiet.booleanValue())
        fetch.setProgressMonitor(new TextProgressMonitor(errw));

      FetchResult result = fetch.call();
      if (result.getTrackingRefUpdates().isEmpty()) return;

      showFetchResult(result);
    }
  }
Example #7
0
  public static FetchResult fetch(
      final Git git,
      final String remote,
      final String refSpec,
      final int timeout,
      final boolean fsck,
      final boolean dryRun,
      final boolean thin,
      final boolean prune)
      throws GitAPIException {
    FetchCommand fetch = git.fetch();
    fetch.setCheckFetchedObjects(fsck);
    fetch.setRemoveDeletedRefs(prune);
    if (refSpec != null) fetch.setRefSpecs(new RefSpec(refSpec));
    if (timeout >= 0) fetch.setTimeout(timeout);
    fetch.setDryRun(dryRun);
    fetch.setRemote(remote);
    fetch.setThin(thin);
    fetch.setProgressMonitor(new TextProgressMonitor());

    FetchResult result = fetch.call();
    return result;
  }