public Git getGitByOpen(File file) throws IOException { Git git = Git.open(file); return git; }
@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); } } }
if (dirStream.iterator().hasNext()) { try { recordGit(Git.open(directory.toFile())); } catch (IOException e) { throw new ConfigException(
/** * 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); }
this.git = Git.open(repoDirFile);
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; } }
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()); } }
private Git gitOpen() throws GitException { try { return Git.open(getGitPath().toFile()); } catch (IOException e) { throw new GitException("Fail to open .git folder", e); } }
/** * 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); } }
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()); } }
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; }
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); } }
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 = ""; } }
/** * 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; }
Git git = Git.open(actPath.toFile());
/** * 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; }
/** * 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; }
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; }
protected Git openRepository() throws IOException, GitAPIException { Git git = Git.open(new File(path)); if (this.mainBranchName == null) { this.mainBranchName = discoverMainBranchName(git); } return git; }
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; }