public void fetch() throws GitException { fetch(null, null); }
public void checkout(String commitish) throws GitException { checkoutBranch(null, commitish); }
/** * Get a remote's URL * * @param name The name of the remote (e.g. origin) * @throws GitException if executing the git command fails */ public String getRemoteUrl(String name) throws GitException { String result = launchCommand("config", "--get", "remote." + name + ".url"); return firstLine(result).trim(); }
public void setupSubmoduleUrls(String remote, TaskListener listener) throws GitException { // This is to make sure that we don't miss any new submodules or // changes in submodule origin paths... submoduleInit(); submoduleSync(); // This allows us to seamlessly use bare and non-bare superproject // repositories. fixSubmoduleUrls(remote, listener); }
public boolean hasGitModules(String treeIsh) throws GitException { return hasGitModules() && !getSubmodules(treeIsh).isEmpty(); }
String url = getRemoteUrl(remote); String gitEnd = pathJoin("", ".git"); if (url.endsWith(gitEnd)) { url = url.substring(0, url.length() - gitEnd.length()); paths.add(pathJoin(origin.getPath(), ".git")); is_bare = isBareRepository(path); break;// we can break already if we don't have an exception } catch (GitException e) { List<IndexEntry> submodules = getSubmodules("HEAD"); String sUrl = pathJoin(origin.getPath(), submodule.getFile()); setSubmoduleUrl(submodule.getFile(), sUrl); String subGitDir = pathJoin(submodule.getFile(), ".git"); if (hasGitRepo(subGitDir) && !"".equals(getRemoteUrl("origin", subGitDir))) { setRemoteUrl("origin", sUrl, subGitDir);
public Boolean invoke(File localWorkspace, VirtualChannel channel) throws IOException { IGitAPI git = new GitAPI(gitExe, new FilePath(localWorkspace), listener, environment); if (git.hasGitRepo()) { // Repo is there - do a fetch listener.getLogger().println("Fetching changes from the remote Git repositories"); // Fetch updates for (RemoteConfig remoteRepository : paramRepos) { fetchFrom(git, listener, remoteRepository); } listener.getLogger().println("Polling for changes in"); Collection<Revision> origCandidates = buildChooser.getCandidateRevisions( true, singleBranch, git, listener, buildData); List<Revision> candidates = new ArrayList<Revision>(); for (Revision c : origCandidates) { if (!isRevExcluded(git, c, listener)) { candidates.add(c); } } return (candidates.size() > 0); } else { listener.getLogger().println("No Git repository yet, an initial checkout is required"); return true; } } });
/** * Set up submodule URLs so that they correspond to the remote pertaining to * the revision that has been checked out. */ public void setupSubmoduleUrls(Revision rev, TaskListener listener) throws GitException { String remote; Iterator<Branch> bi = rev.getBranches().iterator(); if (bi.hasNext()) { // this is supposed to be a remote branch String b = bi.next().getName(); if (b != null) { int slash = b.indexOf('/'); if (slash == -1) { throw new GitException("no remote from branch name (" + b + ")"); } remote = getDefaultRemote(b.substring(0, slash)); } else { remote = getDefaultRemote(); } } else { remote = getDefaultRemote(); } setupSubmoduleUrls(remote, listener); }
/** * @param args * @param workDir * @return command output * @throws GitException */ private String launchCommandIn(ArgumentListBuilder args, FilePath workDir) throws GitException { ByteArrayOutputStream fos = new ByteArrayOutputStream(); try { args.prepend(getGitExe()); int status = launcher.launch().cmds(args.toCommandArray()). envs(environment).stdout(fos).pwd(workDir).join(); String result = fos.toString(); if (status != 0) { throw new GitException( "Command \"" + StringUtils.join(args.toCommandArray(), " ") + "\" returned status code " + status + ": " + result); } return result; } catch (Exception e) { throw new GitException("Error performing command: " + StringUtils.join(args.toCommandArray(), " ") + "\n" + e.getMessage(), e); } }
public List<Branch> getRemoteBranches() throws GitException, IOException { Repository db = getRepository(); Map<String, Ref> refs = db.getAllRefs(); List<Branch> branches = new ArrayList<Branch>(); for (Ref candidate : refs.values()) { if (candidate.getName().startsWith(Constants.R_REMOTES)) { Branch buildBranch = new Branch(candidate); listener.getLogger().println("Seen branch in repository " + buildBranch.getName()); branches.add(buildBranch); } } return branches; }
/** * Get the default remote. * * @return "origin" if it exists, otherwise return the first remote. * @throws GitException if executing the git command fails */ public String getDefaultRemote() throws GitException { return getDefaultRemote("origin"); }
String url = getRemoteUrl(remote); String gitEnd = pathJoin("", ".git"); if (url.endsWith(gitEnd)) { url = url.substring(0, url.length() - gitEnd.length()); paths.add(pathJoin(origin.getPath(), ".git")); is_bare = isBareRepository(path); break;// we can break already if we don't have an exception } catch (GitException e) { List<IndexEntry> submodules = getSubmodules("HEAD"); String sUrl = pathJoin(origin.getPath(), submodule.getFile()); setSubmoduleUrl(submodule.getFile(), sUrl); String subGitDir = pathJoin(submodule.getFile(), ".git"); if (hasGitRepo(subGitDir) && !"".equals(getRemoteUrl("origin", subGitDir))) { setRemoteUrl("origin", sUrl, subGitDir);
public GitClient invoke(File f, VirtualChannel channel) throws IOException, InterruptedException { if (listener == null) listener = TaskListener.NULL; if (env == null) env = new EnvVars(); if (exe == null || JGitTool.MAGIC_EXENAME.equalsIgnoreCase(exe)) { return new JGitAPIImpl(f, listener); } if (JGitApacheTool.MAGIC_EXENAME.equalsIgnoreCase(exe)) { final PreemptiveAuthHttpClientConnectionFactory factory = new PreemptiveAuthHttpClientConnectionFactory(); return new JGitAPIImpl(f, listener, factory); } // Ensure we return a backward compatible GitAPI, even API only claim to provide a GitClient return new GitAPI(exe, f, listener, env); } }
public void setupSubmoduleUrls(String remote, TaskListener listener) throws GitException { // This is to make sure that we don't miss any new submodules or // changes in submodule origin paths... submoduleInit(); submoduleSync(); // This allows us to seamlessly use bare and non-bare superproject // repositories. fixSubmoduleUrls(remote, listener); }
public boolean hasGitModules(String treeIsh) throws GitException { return hasGitModules() && (getSubmodules(treeIsh).size() > 0); }
remote = getDefaultRemote( b.substring(0,slash) ); remote = getDefaultRemote(); setupSubmoduleUrls( remote, listener );
/** * @param args * @param workDir * @return command output * @throws GitException */ private String launchCommandIn(ArgumentListBuilder args, FilePath workDir) throws GitException { ByteArrayOutputStream fos = new ByteArrayOutputStream(); try { args.prepend(getGitExe()); int status = launcher.launch().cmds(args.toCommandArray()). envs(environment).stdout(fos).pwd(workDir).join(); String result = fos.toString(); if (status != 0) { throw new GitException( "Command \"" + StringUtils.join(args.toCommandArray(), " ") + "\" returned status code " + status + ": " + result); } return result; } catch (Exception e) { throw new GitException("Error performing command: " + StringUtils.join(args.toCommandArray(), " ") + "\n" + e.getMessage(), e); } }
public List<Tag> getTagsOnCommit(String revName) throws GitException, IOException { Repository db = getRepository(); ObjectId commit = db.resolve(revName); List<Tag> ret = new ArrayList<Tag>(); for (final Map.Entry<String, Ref> tag : db.getTags().entrySet()) { Tag ttag = db.mapTag(tag.getKey()); if (ttag.getObjId().equals(commit)) { ret.add(ttag); } } return ret; }
/** * Get the default remote. * * @return "origin" if it exists, otherwise return the first remote. * @throws GitException if executing the git command fails */ public String getDefaultRemote() throws GitException { return getDefaultRemote(Constants.DEFAULT_REMOTE_NAME); }
workspace = workspace.child(entry.getKey()); IGitAPI git = new GitAPI(gitExe, workspace, listener, environment);