use of com.google.copybara.testing.SkylarkTestExecutor in project copybara by google.
the class GitHubDestinationTest method setup.
@Before
public void setup() throws Exception {
console = new TestingConsole();
options = new OptionsBuilder().setConsole(console).setOutputRootToTmpDir();
options.testingOptions.checker = new DummyChecker(ImmutableSet.of("bad_word"));
workdir = Files.createTempDirectory("workdir");
destinationFiles = Glob.createGlob(ImmutableList.of("**"));
gitUtil = new GitTestUtil(options);
gitUtil.mockRemoteGitRepos(new CompleteRefValidator());
remote = gitUtil.mockRemoteRepo("github.com/foo");
primaryBranch = remote.getPrimaryBranch();
Path credentialsFile = Files.createTempFile("credentials", "test");
Files.write(credentialsFile, "https://user:SECRET@github.com".getBytes(UTF_8));
options.git.credentialHelperStorePath = credentialsFile.toString();
options.gitDestination = new GitDestinationOptions(options.general, options.git);
options.gitDestination.committerEmail = "commiter@email";
options.gitDestination.committerName = "Bara Kopi";
url = "https://github.com/foo";
force = false;
fetch = primaryBranch;
push = primaryBranch;
skylark = new SkylarkTestExecutor(options);
}
use of com.google.copybara.testing.SkylarkTestExecutor in project copybara by google.
the class GitHubPrOriginTest method testCheckout_noMergeRef_withForce.
@Test
public void testCheckout_noMergeRef_withForce() throws Exception {
GitRepository remote = withTmpWorktree(gitUtil.mockRemoteRepo("github.com/google/example"));
String baseRef = addFiles(remote, "base", ImmutableMap.of("test.txt", "a"));
remote.simpleCommand("branch", "feature");
String featureRef = addFiles(remote, "commit to feature branch", ImmutableMap.of("test.txt", "c"));
remote.forceCheckout(baseRef);
String mainRef = addFiles(remote, "commit to main branch", ImmutableMap.of("test.txt", "b"));
remote.simpleCommand("merge", "feature");
String mergeRef = remote.parseRef("HEAD");
remote.forceCheckout(mainRef);
remote.simpleCommand("update-ref", GitHubUtil.asHeadRef(123), featureRef);
remote.simpleCommand("update-ref", GitHubUtil.asMergeRef(123), mergeRef);
// Using --force should respect "use_merge = True" when a merge commit does exist
options.setForce(true);
skylark = new SkylarkTestExecutor(options);
MockPullRequest.create(gitUtil).setState("open").setPrimaryBranch("main").setPrNumber(123).setMergeable(true).mock();
GitHubPrOrigin origin = githubPrOrigin("url = 'https://github.com/google/example'", "use_merge = True");
assertThat(origin.resolve("123").getSha1()).isEqualTo(remote.resolveReference(GitHubUtil.asMergeRef(123)).getSha1());
assertThat(origin.resolve("123").associatedLabel(GITHUB_PR_USE_MERGE)).containsExactly("true");
// Using --force should override "use_merge = True", since no merge commit exists
options.setForce(true);
skylark = new SkylarkTestExecutor(options);
// delete the merge commit
remote.simpleCommand("reset", "--hard", "HEAD~1");
MockPullRequest.create(gitUtil).setState("open").setPrimaryBranch("main").setPrNumber(123).setMergeable(false).mock();
origin = githubPrOrigin("url = 'https://github.com/google/example'", "use_merge = True");
assertThat(origin.resolve("123").getSha1()).isEqualTo(remote.resolveReference(GitHubUtil.asHeadRef(123)).getSha1());
assertThat(origin.resolve("123").associatedLabel(GITHUB_PR_USE_MERGE)).containsExactly("false");
}
use of com.google.copybara.testing.SkylarkTestExecutor in project copybara by google.
the class GitHubPrOriginTest method setup.
@Before
public void setup() throws Exception {
repoGitDir = Files.createTempDirectory("GitHubPrDestinationTest-repoGitDir");
workdir = Files.createTempDirectory("workdir");
git("init", "--bare", repoGitDir.toString());
console = new TestingConsole();
options = new OptionsBuilder().setConsole(console).setOutputRootToTmpDir();
gitUtil = new GitTestUtil(options);
gitUtil.mockRemoteGitRepos(new CompleteRefValidator());
Path credentialsFile = Files.createTempFile("credentials", "test");
Files.write(credentialsFile, "https://user:SECRET@github.com".getBytes(UTF_8));
options.git.credentialHelperStorePath = credentialsFile.toString();
skylark = new SkylarkTestExecutor(options);
}
use of com.google.copybara.testing.SkylarkTestExecutor in project copybara by google.
the class GitMirrorTest method setup.
@Before
public void setup() throws Exception {
workdir = Files.createTempDirectory("workdir");
console = new TestingConsole();
options = new OptionsBuilder().setEnvironment(GitTestUtil.getGitEnv().getEnvironment()).setOutputRootToTmpDir().setWorkdirToRealTempDir().setConsole(console);
originRepo = newBareRepo(Files.createTempDirectory("gitdir"), getGitEnv(), /*verbose=*/
true, DEFAULT_TIMEOUT, /*noVerify=*/
false).withWorkTree(Files.createTempDirectory("worktree"));
originRepo.init();
destRepo = bareRepo(Files.createTempDirectory("destinationFolder"));
destRepo.init();
skylark = new SkylarkTestExecutor(options);
Files.write(originRepo.getWorkTree().resolve("test.txt"), "some content".getBytes(UTF_8));
originRepo.add().files("test.txt").run();
originRepo.simpleCommand("commit", "-m", "first file");
originRepo.simpleCommand("branch", "other");
primaryBranch = originRepo.getPrimaryBranch();
}
use of com.google.copybara.testing.SkylarkTestExecutor in project copybara by google.
the class GitOriginSubmodulesTest method testRewriteUrl.
@Test
public void testRewriteUrl() throws Exception {
Path base = Files.createTempDirectory("testRewriteUrl");
GitRepository r1 = createRepoWithFoo(base, "r1");
GitRepository r2 = createRepoWithFoo(base, "r2");
GitRepository r3 = GitRepository.newBareRepo(base.resolve("testRewriteUrl").resolve("r3"), getGitEnv(), false, Duration.ofMinutes(1), false).init();
r3.fetch("file://" + r1.getGitDir(), false, true, ImmutableList.of("refs/heads/*:refs/heads/*"), false);
String primaryBranch = r2.getPrimaryBranch();
OptionsBuilder options = new OptionsBuilder().setConsole(new TestingConsole()).setOutputRootToTmpDir();
options.git = new GitOptions(options.general) {
@Override
public String rewriteSubmoduleUrl(String url) {
return r3.getGitDir().toString();
}
};
skylark = new SkylarkTestExecutor(options);
r2.simpleCommand("submodule", "add", "-f", "--name", "r1", "file://" + r1.getWorkTree(), "r1");
commit(r2, "adding r3->r1 submodule");
// Nuke r1 to verify r3 is read
MoreFiles.deleteRecursively(r1.getGitDir());
GitOrigin origin = origin("file://" + r2.getGitDir(), primaryBranch);
GitRevision main = origin.resolve(primaryBranch);
origin.newReader(Glob.ALL_FILES, authoring).checkout(main, checkoutDir);
FileSubjects.assertThatPath(checkoutDir).containsFiles(GITMODULES).containsFile("r1/foo", "1");
}
Aggregations