@Test public void testCheckoutMultiUrl() throws IOException, ScmException, NoHeadException, GitAPIException { final Path localGitRepos = targetDir.resolve("local-git-repos"); final Path srcdepsTestArtifactDirectory0 = localGitRepos .resolve("srcdeps-test-artifact-testCheckoutMultiUrl-0"); SrcdepsCoreUtils.deleteDirectory(srcdepsTestArtifactDirectory0); final Path srcdepsTestArtifactDirectory1 = localGitRepos .resolve("srcdeps-test-artifact-testCheckoutMultiUrl-1"); SrcdepsCoreUtils.deleteDirectory(srcdepsTestArtifactDirectory1); final String remoteGitUri = "https: final String mornigBranch = "morning-branch"; try (Git git = Git.cloneRepository().setURI(remoteGitUri).setDirectory(srcdepsTestArtifactDirectory0.toFile()) .setCloneAllBranches(true).call()) { git.checkout().setName(mornigBranch).setCreateBranch(true).setStartPoint("origin/" + mornigBranch).call(); } SrcdepsCoreUtils.copyDirectory(srcdepsTestArtifactDirectory0, srcdepsTestArtifactDirectory1); final String localGitUri0 = srcdepsTestArtifactDirectory0.resolve(".git").toUri().toString(); final String localGitUri1 = srcdepsTestArtifactDirectory1.resolve(".git").toUri().toString(); final Path testTxtPath = srcdepsTestArtifactDirectory1.resolve("test.txt"); Files.write(testTxtPath, "Test0".getBytes(StandardCharsets.UTF_8)); final Path dir = targetDir.resolve("test-repo-testCheckoutMultiUrl"); SrcdepsCoreUtils.ensureDirectoryExistsAndEmpty(dir); { final String addedCommitId; try (Git git = Git.init().setDirectory(srcdepsTestArtifactDirectory1.toFile()).call()) { git.add().addFilepattern(testTxtPath.getFileName().toString()).call(); addedCommitId = git.commit().setMessage("Added test.txt").call().getId().getName(); } final BuildRequest cloningRequest = BuildRequest.builder() .scmRepositoryId("test") .encoding(StandardCharsets.UTF_8) .output(LineConsumer::dummy) .srcVersion(SrcVersion.parse("0.0.1-SRC-revision-" + addedCommitId)) .dependentProjectRootDirectory(dir) .projectRootDirectory(dir) .scmUrl("git:" + localGitUri0) .scmUrl("git:" + localGitUri1) .versionsMavenPluginVersion(Maven.getDefaultVersionsMavenPluginVersion()) .gradleModelTransformer(CharStreamSource.defaultModelTransformer()) .build(); final JGitScm jGitScm = new JGitScm(); final String commitId = jGitScm.checkout(cloningRequest); Assert.assertEquals(addedCommitId, commitId); } Files.write(testTxtPath, "Test1".getBytes(StandardCharsets.UTF_8)); { final String addedCommitId; try (Git git = Git.init().setDirectory(srcdepsTestArtifactDirectory1.toFile()).call()) { git.add().addFilepattern(testTxtPath.getFileName().toString()).call(); addedCommitId = git.commit().setMessage("Changed test.txt").call().getId().getName(); } final BuildRequest fetchResetRequest = BuildRequest.builder() .scmRepositoryId("test") .encoding(StandardCharsets.UTF_8) .output(LineConsumer::dummy) .srcVersion(SrcVersion.parse("0.0.1-SRC-revision-" + addedCommitId)) .dependentProjectRootDirectory(dir) .projectRootDirectory(dir) .scmUrl("git:" + localGitUri0) .scmUrl("git:" + localGitUri1) .versionsMavenPluginVersion(Maven.getDefaultVersionsMavenPluginVersion()) .gradleModelTransformer(CharStreamSource.defaultModelTransformer()) .build(); final JGitScm jGitScm = new JGitScm(); final String commitId = jGitScm.checkout(fetchResetRequest); Assert.assertEquals(addedCommitId, commitId); } }
@Override public String checkout(BuildRequest request) throws ScmException { final Path dir = request.getProjectRootDirectory(); int i = 0; final List<String> urls = request.getScmUrls(); try (Git git = openGit(request.getScmRepositoryId(), dir)) { for (String url : urls) { final String useUrl = stripUriPrefix(url); final String result = fetchAndReset(request.getScmRepositoryId(), useUrl, i, urls.size(), request.getSrcVersion(), dir, git); if (result != null) { return result; } i++; } } throw new ScmException( String.format("Could not checkout [%s] from URLs %s", request.getSrcVersion(), request.getScmUrls())); }
JGitScm implements Scm { @Override public String checkout(BuildRequest request) throws ScmException { final Path dir = request.getProjectRootDirectory(); int i = 0; final List<String> urls = request.getScmUrls(); try (Git git = openGit(request.getScmRepositoryId(), dir)) { for (String url : urls) { final String useUrl = stripUriPrefix(url); final String result = fetchAndReset(request.getScmRepositoryId(), useUrl, i, urls.size(), request.getSrcVersion(), dir, git); if (result != null) { return result; } i++; } } throw new ScmException( String.format("Could not checkout [%s] from URLs %s", request.getSrcVersion(), request.getScmUrls())); } }
JGitScm implements Scm { @Override public String checkout(BuildRequest request) throws ScmException { final Path dir = request.getProjectRootDirectory(); int i = 0; final List<String> urls = request.getScmUrls(); try (Git git = openGit(request.getScmRepositoryId(), dir)) { for (String url : urls) { final String useUrl = stripUriPrefix(url); final String result = fetchAndReset(request.getScmRepositoryId(), useUrl, i, urls.size(), request.getSrcVersion(), dir, git); if (result != null) { return result; } i++; } } throw new ScmException( String.format("Could not checkout [%s] from URLs %s", request.getSrcVersion(), request.getScmUrls())); }  }
JGitScm implements Scm { @Override public String checkout(BuildRequest request) throws ScmException { final Path dir = request.getProjectRootDirectory(); int i = 0; final List<String> urls = request.getScmUrls(); try (Git git = openGit(request.getScmRepositoryId(), dir)) { for (String url : urls) { final String useUrl = stripUriPrefix(url); final String result = fetchAndReset(request.getScmRepositoryId(), useUrl, i, urls.size(), request.getSrcVersion(), dir, git); if (result != null) { return result; } i++; } } throw new ScmException( String.format("Could not checkout [%s] from URLs %s", request.getSrcVersion(), request.getScmUrls())); }  static String getScmGitPrefix(); static String getSrcdepsWorkingBranch(); @Override String checkout(BuildRequest request); @Override boolean supports(String url); }
JGitScm implements Scm { @Override public String checkout(BuildRequest request) throws ScmException { final Path dir = request.getProjectRootDirectory(); int i = 0; final List<String> urls = request.getScmUrls(); try (Git git = openGit(request.getScmRepositoryId(), dir)) { for (String url : urls) { final String useUrl = stripUriPrefix(url); final String result = fetchAndReset(request.getScmRepositoryId(), useUrl, i, urls.size(), request.getSrcVersion(), dir, git); if (result != null) { return result; } i++; } } throw new ScmException( String.format("Could not checkout [%s] from URLs %s", request.getSrcVersion(), request.getScmUrls())); }  static String getScmGitPrefix(); static String getSrcdepsWorkingBranch(); @Override String checkout(BuildRequest request); @Override boolean supports(String url);  }