public Object readResolve() { // Migrate data // Default unspecified to v0 if (configVersion == null) configVersion = 0L; if (source != null) { remoteRepositories = new ArrayList<RemoteConfig>(); branches = new ArrayList<BranchSpec>(); doGenerateSubmoduleConfigurations = false; mergeOptions = new PreBuildMergeOptions(); remoteRepositories.add( newRemoteConfig("origin", source, new RefSpec("+refs/heads/*:refs/remotes/origin/*"))); if (branch != null) { branches.add(new BranchSpec(branch)); } else { branches.add(new BranchSpec("*/master")); } } if (configVersion < 1 && branches != null) { // Migrate the branch specs from // single * wildcard, to ** wildcard. for (BranchSpec branchSpec : branches) { String name = branchSpec.getName(); name = name.replace("*", "**"); branchSpec.setName(name); } } if (mergeOptions.doMerge() && mergeOptions.getMergeRemote() == null) { mergeOptions.setMergeRemote(remoteRepositories.get(0)); } return this; }
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.doMerge") != null && req.getParameter("git.doMerge").trim().length() > 0) { RemoteConfig mergeRemote = null; String mergeRemoteName = req.getParameter("git.mergeRemote").trim(); if (mergeRemoteName.length() == 0) mergeRemote = remoteRepositories.get(0); else for (RemoteConfig remote : remoteRepositories) { if (remote.getName().equals(mergeRemoteName)) { mergeRemote = remote; break; } } if (mergeRemote == null) throw new FormException( "No remote repository configured with name '" + mergeRemoteName + "'", "git.mergeRemote"); mergeOptions.setMergeRemote(mergeRemote); 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, req.getParameter("git.choosing_strategy"), gitWeb); }