/** * submoduleInit. * * @throws hudson.plugins.git.GitException if underlying git operation fails. * @throws java.lang.InterruptedException if interrupted. */ public void submoduleInit() throws GitException, InterruptedException { launchCommand("submodule", "init"); }
/** * {@inheritDoc} * * Set submodule URL */ public void setSubmoduleUrl(String name, String url) throws GitException, InterruptedException { launchCommand( "config", "submodule."+name+".url", url ); }
/** * Sync submodule URLs * * @throws hudson.plugins.git.GitException if underlying git operation fails. * @throws java.lang.InterruptedException if interrupted. */ public void submoduleSync() throws GitException, InterruptedException { // Check if git submodule has sync support. // Only available in git 1.6.1 and above launchCommand("submodule", "sync"); }
/** {@inheritDoc} */ public void setRemoteUrl(String name, String url, String GIT_DIR ) throws GitException, InterruptedException { launchCommand( "--git-dir=" + GIT_DIR, "config", "remote."+name+".url", url ); }
/** {@inheritDoc} */ @Deprecated public String getAllLogEntries(String branch) throws InterruptedException { // BROKEN: --all and branch are conflicting. return launchCommand("log", "--all", "--pretty=format:'%H#%ct'", branch); }
/** {@inheritDoc} */ public List<Branch> getBranchesContaining(String revspec, boolean allBranches) throws GitException, InterruptedException { final String commandOutput; if (allBranches) { commandOutput = launchCommand("branch", "-a", "-v", "--no-abbrev", "--contains", revspec); } else { commandOutput = launchCommand("branch", "-v", "--no-abbrev", "--contains", revspec); } return new ArrayList<>(parseBranches(commandOutput)); }
/** {@inheritDoc} */ public String getTagMessage(String tagName) throws GitException, InterruptedException { // 10000 lines of tag message "ought to be enough for anybody" String out = launchCommand("tag", "-l", tagName, "-n10000"); // Strip the leading four spaces which git prefixes multi-line messages with return out.substring(tagName.length()).replaceAll("(?m)(^ )", "").trim(); }
/** {@inheritDoc} */ public void add(String filePattern) throws GitException, InterruptedException { try { launchCommand("add", filePattern); } catch (GitException e) { throw new GitException("Cannot add " + filePattern, e); } }
private void getGitVersion() { if (gitVersion != 0) { return; } String version = ""; try { version = launchCommand("--version").trim(); } catch (Throwable e) { } computeGitVersion(version); }
/** * Returns the set of branches defined in this repository, * including local branches and remote branches. Remote branches * are prefixed by "remotes/". * * @return a {@link java.util.Set} object. * @throws hudson.plugins.git.GitException if underlying git operation fails. * @throws java.lang.InterruptedException if interrupted. */ public Set<Branch> getBranches() throws GitException, InterruptedException { return parseBranches(launchCommand("branch", "-a", "-v", "--no-abbrev")); }
/** {@inheritDoc} */ public void ref(String refName) throws GitException, InterruptedException { refName = refName.replace(' ', '_'); try { launchCommand("update-ref", refName, "HEAD"); } catch (GitException e) { throw new GitException("Could not apply ref " + refName, e); } }
/** {@inheritDoc} */ public void deleteBranch(String name) throws GitException, InterruptedException { try { launchCommand("branch", "-D", name); } catch (GitException e) { throw new GitException("Could not delete branch " + name, e); } }
/** {@inheritDoc} */ public void deleteRef(String refName) throws GitException, InterruptedException { refName = refName.replace(' ', '_'); try { launchCommand("update-ref", "-d", refName); } catch (GitException e) { throw new GitException("Could not delete ref " + refName, e); } }
/** {@inheritDoc} */ @Deprecated public void merge(String refSpec) throws GitException, InterruptedException { try { launchCommand("merge", refSpec); } catch (GitException e) { throw new GitException("Could not merge " + refSpec, e); } }
/** * Get submodule path. * * @param name submodule name whose path is returned * @return path to submodule * @throws GitException on git error * @throws InterruptedException if interrupted */ public @CheckForNull String getSubmodulePath(String name) throws GitException, InterruptedException { String result = launchCommand( "config", "-f", ".gitmodules", "--get", "submodule."+name+".path" ); return StringUtils.trim(firstLine(result)); }
/** {@inheritDoc} */ public String describe(String commitIsh) throws GitException, InterruptedException { String result = launchCommand("describe", "--tags", commitIsh); String line = firstLine(result); if (line == null) throw new GitException("null first line from describe(" + commitIsh +")"); return line.trim(); }
/** * {@inheritDoc} * * Get submodule URL */ public @CheckForNull String getSubmoduleUrl(String name) throws GitException, InterruptedException { String result = launchCommand( "config", "--get", "submodule."+name+".url" ); return StringUtils.trim(firstLine(result)); }
/** {@inheritDoc} */ public @CheckForNull String getRemoteUrl(String name) throws GitException, InterruptedException { String result = launchCommand( "config", "--get", "remote."+name+".url" ); return StringUtils.trim(firstLine(result)); }
private void createNote(String note, String namespace, String command ) throws GitException, InterruptedException { File msg = null; try { msg = createTempFile("git-note", ".txt"); FileUtils.writeStringToFile(msg,note); launchCommand("notes", "--ref=" + namespace, command, "-F", msg.getAbsolutePath()); } catch (IOException | GitException e) { throw new GitException("Could not apply note " + note, e); } finally { deleteTempFile(msg); } }
/** {@inheritDoc} */ public ObjectId revParse(String revName) throws GitException, InterruptedException { String arg = sanitize(revName + "^{commit}"); String result = launchCommand("rev-parse", arg); String line = StringUtils.trimToNull(result); if (line == null) throw new GitException("rev-parse no content returned for " + revName); return ObjectId.fromString(line); }