<T> T execute(GitOperation<T> gitOperation) {
   Git git = openRepository();
   try {
     return guarded(() -> gitOperation.execute(git));
   } finally {
     git.close();
   }
 }
  @Override
  public void close() {

    repository.close();
    git.close();
    treeWalk.close();
    revWalk.close();
    reader.close();
  }
  private void cloneGitProject() throws GitAPIException {
    Git result =
        Git.cloneRepository()
            .setURI(MODULE_GITHUB_URL)
            .setDirectory(new File(testDirectory, OPENMRS_MODULE_IDGEN))
            .call();

    result.close();
  }
示例#4
0
  /**
   * The main method.
   *
   * @param args the arguments
   */
  public static void main(String[] args) {
    String direc = args[0];
    String fileName = args[1];
    try {
      Repository r = new FileRepository(direc);
      Git g = new Git(r);

      Adder adr = new Adder();
      adr.addFile(g, fileName);

      g.close();
    } catch (IOException e) {
      e.printStackTrace();
      return;
    }
  }
示例#5
0
 /**
  * This will commit the local changes and push them to the repository. If the method is unable to
  * push to the repository without force, it will throw an exception. {@inheritDoc}
  */
 @Override
 public void closeConnection() throws ConnectionException {
   try {
     for (final String gitRemoteUri : gitCache.keySet()) {
       final Git git = gitCache.get(gitRemoteUri);
       git.add().addFilepattern(".").call(); // $NON-NLS-1$
       git.commit().setMessage(R.getString("commitmessage")).call(); // $NON-NLS-1$
       git.push().setRemote(gitRemoteUri).setCredentialsProvider(credentialsProvider).call();
       git.close();
       FileUtils.deleteDirectory(git.getRepository().getDirectory());
     }
   } catch (final GitAPIException e) {
     throw new ConnectionException(e.getMessage(), e);
   } catch (final IOException e) {
     throw new ConnectionException(e.getMessage(), e);
   }
 }