/** {@inheritDoc} */ @Override public boolean isCommitInRepo(ObjectId commit) throws GitException { if (commit == null) { return false; } final boolean found; try (Repository repo = getRepository()) { found = repo.hasObject(commit); } return found; }
/** {@inheritDoc} */ @Override public boolean refExists(String refName) throws GitException, InterruptedException { refName = refName.replace(' ', '_'); try (Repository repo = getRepository()) { Ref ref = repo.findRef(refName); return ref != null; } catch (IOException e) { throw new GitException("Error checking ref " + refName, e); } }
/** {@inheritDoc} */ @Override public boolean tagExists(String tagName) throws GitException { try (Repository repo = getRepository()) { Ref tag = repo.exactRef(R_TAGS + tagName); return tag != null; } catch (IOException e) { throw new GitException(e); } }
/** {@inheritDoc} */ @Override public String getRemoteUrl(String name) throws GitException { try (Repository repo = getRepository()) { return repo.getConfig().getString("remote",name,"url"); } }
/** {@inheritDoc} */ @Deprecated @Override public String getSubmoduleUrl(String name) throws GitException, InterruptedException { String v = null; try (Repository repo = getRepository()) { v = repo.getConfig().getString("submodule", name, "url"); } if (v==null) throw new GitException("No such submodule: "+name); return v.trim(); }
private Iterable<JGitAPIImpl> submodules() throws IOException { List<JGitAPIImpl> submodules = new ArrayList<>(); try (Repository repo = getRepository()) { SubmoduleWalk generator = SubmoduleWalk.forIndex(repo); while (generator.next()) { submodules.add(new JGitAPIImpl(generator.getDirectory(), listener)); } } return submodules; }
public Set<Branch> getBranchesInternal(ListBranchCommand.ListMode mode) throws GitException { try (Repository repo = getRepository()) { List<Ref> refs = git(repo).branchList().setListMode(mode).call(); Set<Branch> branches = new HashSet<>(refs.size()); for (Ref ref : refs) { branches.add(new Branch(ref)); } return branches; } catch (GitAPIException e) { throw new GitException(e); } }
/** {@inheritDoc} */ @Override public ObjectId revParse(String revName) throws GitException { try (Repository repo = getRepository()) { ObjectId id = repo.resolve(revName + "^{commit}"); if (id == null) throw new GitException("Unknown git object "+ revName); return id; } catch (IOException e) { throw new GitException("Failed to resolve git reference "+ revName, e); } }
/** {@inheritDoc} */ @Deprecated @Override public void setSubmoduleUrl(String name, String url) throws GitException, InterruptedException { try (Repository repo = getRepository()) { StoredConfig config = repo.getConfig(); config.setString("submodule", name, "url", url); config.save(); } catch (IOException e) { throw new GitException(e); } }
private StoredConfig getConfig(String GIT_DIR) throws GitException { try (Repository repo = isBlank(GIT_DIR) ? getRepository() : new RepositoryBuilder().setWorkTree(new File(GIT_DIR)).build()) { return repo.getConfig(); } catch (IOException ioe) { throw new GitException(ioe); } }
/** {@inheritDoc} */ @Deprecated @Override public void reset(boolean hard) throws GitException, InterruptedException { try (Repository repo = getRepository()) { ResetCommand reset = new ResetCommand(repo); reset.setMode(hard?HARD:MIXED); reset.call(); } catch (GitAPIException e) { throw new GitException(e); } }
/** {@inheritDoc} */ @Override public void setRemoteUrl(String name, String url) throws GitException { try (Repository repo = getRepository()) { StoredConfig config = repo.getConfig(); config.setString("remote", name, "url", url); config.save(); } catch (IOException e) { throw new GitException(e); } }
/** {@inheritDoc} */ @Override public String getTagMessage(String tagName) throws GitException { try (Repository repo = getRepository(); ObjectReader or = repo.newObjectReader(); RevWalk walk = new RevWalk(or)) { return walk.parseTag(repo.resolve(tagName)).getFullMessage().trim(); } catch (IOException e) { throw new GitException(e); } }
/** {@inheritDoc} */ @Override public void commit(String message) throws GitException { try (Repository repo = getRepository()) { CommitCommand cmd = git(repo).commit().setMessage(message).setAuthor(author); if (committer!=null) cmd.setCommitter(new PersonIdent(committer,new Date())); cmd.call(); } catch (GitAPIException e) { throw new GitException(e); } }
/** {@inheritDoc} */ @Override public void branch(String name) throws GitException { try (Repository repo = getRepository()) { git(repo).branchCreate().setName(name).call(); } catch (GitAPIException e) { throw new GitException(e); } }
/** {@inheritDoc} */ @Override public void deleteTag(String tagName) throws GitException { try (Repository repo = getRepository()) { git(repo).tagDelete().setTags(tagName).call(); } catch (GitAPIException e) { throw new GitException(e); } }
/** {@inheritDoc} */ @Override public void add(String filePattern) throws GitException { try (Repository repo = getRepository()) { git(repo).add().addFilepattern(filePattern).call(); } catch (GitAPIException e) { throw new GitException(e); } }
/** {@inheritDoc} */ @Override public void addSubmodule(String remoteURL, String subdir) throws GitException { try (Repository repo = getRepository()) { git(repo).submoduleAdd().setPath(subdir).setURI(remoteURL).call(); } catch (GitAPIException e) { throw new GitException(e); } }
/** {@inheritDoc} */ @Override public void deleteBranch(String name) throws GitException { try (Repository repo = getRepository()) { git(repo).branchDelete().setForce(true).setBranchNames(name).call(); } catch (GitAPIException e) { throw new GitException(e); } }
private void doCheckout(String ref, String branch) throws GitException { try (Repository repo = getRepository()) { git(repo).checkout().setName(branch).setCreateBranch(true).setForce(true).setStartPoint(ref).call(); } catch (GitAPIException e) { throw new GitException("Could not checkout " + branch + " with start point " + ref, e); } }