Esempio n. 1
0
  private RemoteConfig newRemoteConfig(String name, String refUrl, RefSpec refSpec) {

    File temp = null;
    try {
      temp = File.createTempFile("tmp", "config");
      RepositoryConfig repoConfig = new RepositoryConfig(null, temp);
      // Make up a repo config from the request parameters

      repoConfig.setString("remote", name, "url", refUrl);
      repoConfig.setString("remote", name, "fetch", refSpec.toString());
      repoConfig.save();
      return RemoteConfig.getAllRemoteConfigs(repoConfig).get(0);
    } catch (Exception ex) {
      throw new GitException("Error creating temp file");
    } finally {
      if (temp != null) temp.delete();
    }
  }
Esempio n. 2
0
    public SCM newInstance(StaplerRequest req) throws FormException {
      List<RemoteConfig> remoteRepositories;
      File temp;

      try {
        temp = File.createTempFile("tmp", "config");

      } catch (IOException e1) {
        throw new GitException("Error creating repositories", e1);
      }

      RepositoryConfig repoConfig = new RepositoryConfig(null, temp);
      // Make up a repo config from the request parameters

      String[] urls = req.getParameterValues("git.repo.url");
      String[] names = req.getParameterValues("git.repo.name");

      names = GitUtils.fixupNames(names, urls);

      String[] refs = req.getParameterValues("git.repo.refspec");
      if (names != null) {
        for (int i = 0; i < names.length; i++) {
          String name = names[i];
          name = name.replace(' ', '_');

          if (refs[i] == null || refs[i].length() == 0) {
            refs[i] = "+refs/heads/*:refs/remotes/" + name + "/*";
          }

          repoConfig.setString("remote", name, "url", urls[i]);
          repoConfig.setString("remote", name, "fetch", refs[i]);
        }
      }

      try {
        repoConfig.save();
        remoteRepositories = RemoteConfig.getAllRemoteConfigs(repoConfig);
      } catch (Exception e) {
        throw new GitException("Error creating repositories", e);
      }

      temp.delete();

      List<BranchSpec> branches = new ArrayList<BranchSpec>();
      String[] branchData = req.getParameterValues("git.branch");
      for (int i = 0; i < branchData.length; i++) {
        branches.add(new BranchSpec(branchData[i]));
      }

      if (branches.size() == 0) {
        branches.add(new BranchSpec("*/master"));
      }

      PreBuildMergeOptions mergeOptions = new PreBuildMergeOptions();
      if (req.getParameter("git.mergeTarget") != null
          && req.getParameter("git.mergeTarget").trim().length() > 0) {
        mergeOptions.setMergeTarget(req.getParameter("git.mergeTarget"));
      }

      Collection<SubmoduleConfig> submoduleCfg = new ArrayList<SubmoduleConfig>();

      GitWeb gitWeb = null;
      String gitWebUrl = req.getParameter("gitweb.url");
      if (gitWebUrl != null && gitWebUrl.length() > 0) {
        try {
          gitWeb = new GitWeb(gitWebUrl);
        } catch (MalformedURLException e) {
          throw new GitException("Error creating GitWeb", e);
        }
      }

      return new GitSCM(
          remoteRepositories,
          branches,
          mergeOptions,
          req.getParameter("git.generate") != null,
          submoduleCfg,
          req.getParameter("git.clean") != null,
          gitWeb);
    }