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); } }
/** * submoduleInit. * * @throws hudson.plugins.git.GitException if underlying git operation fails. * @throws java.lang.InterruptedException if interrupted. */ @Deprecated @Override public void submoduleInit() throws GitException, InterruptedException { try (Repository repo = getRepository()) { git(repo).submoduleInit().call(); } catch (GitAPIException e) { throw new GitException(e); } }
/** * submoduleSync. * * @throws hudson.plugins.git.GitException if underlying git operation fails. * @throws java.lang.InterruptedException if interrupted. */ @Deprecated @Override public void submoduleSync() throws GitException, InterruptedException { try (Repository repo = getRepository()) { git(repo).submoduleSync().call(); } catch (GitAPIException 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 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 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 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 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); } }
/** {@inheritDoc} */ @Override public void fetch(String remoteName, RefSpec... refspec) throws GitException { try (Repository repo = getRepository()) { FetchCommand fetch = git(repo).fetch().setTagOpt(TagOpt.FETCH_TAGS); if (remoteName != null) fetch.setRemote(remoteName); fetch.setCredentialsProvider(getProvider()); List<RefSpec> refSpecs = new ArrayList<>(); if (refspec != null && refspec.length > 0) for (RefSpec rs: refspec) if (rs != null) refSpecs.add(rs); fetch.setRefSpecs(refSpecs); fetch.call(); } catch (GitAPIException e) { throw new GitException(e); } }
/** {@inheritDoc} */ @Override public void tag(String name, String message) throws GitException { try (Repository repo = getRepository()) { git(repo).tag().setName(name).setMessage(message).setForceUpdate(true).call(); } catch (GitAPIException e) { throw new GitException(e); } }
/** {@inheritDoc} */ @Override public void appendNote(String note, String namespace) throws GitException { try (Repository repo = getRepository()) { ObjectId head = repo.resolve(HEAD); // commit to put a note on ShowNoteCommand cmd = git(repo).notesShow(); cmd.setNotesRef(qualifyNotesNamespace(namespace)); try (ObjectReader or = repo.newObjectReader(); RevWalk walk = new RevWalk(or)) { cmd.setObjectId(walk.parseAny(head)); Note n = cmd.call(); if (n==null) { addNote(note,namespace); } else { ObjectLoader ol = or.open(n.getData()); StringWriter sw = new StringWriter(); IOUtils.copy(new InputStreamReader(ol.openStream(),CHARSET),sw); sw.write("\n"); addNote(sw.toString() + normalizeNote(note), namespace); } } } catch (GitAPIException | IOException 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); } }
git(repo).reset().setMode(HARD).call(); } catch (GitAPIException e) { throw new GitException("Could not reset the workspace before checkout of " + ref, e); git(repo).checkout().setName(ref).setForce(true).call(); return; listener.getLogger().format("[WARNING] Automatically creating a local branch '%s' tracking remote branch '%s'", ref, removeStart(matchingRemoteBranch, Constants.R_REMOTES)); git(repo).checkout() .setCreateBranch(true) .setName(ref)
/** * clean. * * @param cleanSubmodule flag to add extra -f * @throws hudson.plugins.git.GitException if underlying git operation fails. */ @Override public void clean(boolean cleanSubmodule) throws GitException { try (Repository repo = getRepository()) { Git git = git(repo); git.reset().setMode(HARD).call(); git.clean().setCleanDirectories(true).setIgnore(false).setForce(cleanSubmodule).call(); } catch (GitAPIException e) { throw new GitException(e); } }
/** {@inheritDoc} */ @Override public void addNote(String note, String namespace) throws GitException { try (Repository repo = getRepository()) { ObjectId head = repo.resolve(HEAD); // commit to put a note on AddNoteCommand cmd = git(repo).notesAdd(); cmd.setMessage(normalizeNote(note)); cmd.setNotesRef(qualifyNotesNamespace(namespace)); try (ObjectReader or = repo.newObjectReader(); RevWalk walk = new RevWalk(or)) { cmd.setObjectId(walk.parseAny(head)); cmd.call(); } } catch (GitAPIException | IOException e) { throw new GitException(e); } }