Example usage for org.eclipse.jgit.lib Constants R_NOTES_COMMITS

List of usage examples for org.eclipse.jgit.lib Constants R_NOTES_COMMITS

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Constants R_NOTES_COMMITS.

Prototype

String R_NOTES_COMMITS

To view the source code for org.eclipse.jgit.lib Constants R_NOTES_COMMITS.

Click Source Link

Document

Standard notes ref

Usage

From source file:hudson.plugins.git.GitPublisherTest.java

License:Open Source License

@Issue("JENKINS-24786")
@Test//from  w w  w. ja v a 2 s  .c om
public void testPushEnvVarsInRemoteConfig() throws Exception {
    FreeStyleProject project = setupSimpleProject("master");

    // create second (bare) test repository as target
    TaskListener listener = StreamTaskListener.fromStderr();
    TestGitRepo testTargetRepo = new TestGitRepo("target", tmpFolder.newFolder("push_env_vars"), listener);
    testTargetRepo.git.init_().workspace(testTargetRepo.gitDir.getAbsolutePath()).bare(true).execute();
    testTargetRepo.commit("lostTargetFile", new PersonIdent("John Doe", "john@example.com"),
            "Initial Target Commit");

    // add second test repository as remote repository with environment variables
    List<UserRemoteConfig> remoteRepositories = remoteConfigs();
    remoteRepositories.add(new UserRemoteConfig("$TARGET_URL", "$TARGET_NAME",
            "+refs/heads/$TARGET_BRANCH:refs/remotes/$TARGET_NAME/$TARGET_BRANCH", null));

    GitSCM scm = new GitSCM(remoteRepositories, Collections.singletonList(new BranchSpec("origin/master")),
            false, Collections.<SubmoduleConfig>emptyList(), null, null,
            Collections.<GitSCMExtension>emptyList());
    project.setScm(scm);

    // add parameters for remote repository configuration
    project.addProperty(new ParametersDefinitionProperty(
            new StringParameterDefinition("TARGET_URL", testTargetRepo.gitDir.getAbsolutePath()),
            new StringParameterDefinition("TARGET_NAME", "target"),
            new StringParameterDefinition("TARGET_BRANCH", "master")));

    String tag_name = "test-tag";
    String note_content = "Test Note";

    project.getPublishersList()
            .add(new GitPublisher(
                    Collections.singletonList(new TagToPush("$TARGET_NAME", tag_name, "", false, false)),
                    Collections.singletonList(new BranchToPush("$TARGET_NAME", "$TARGET_BRANCH")),
                    Collections.singletonList(
                            new NoteToPush("$TARGET_NAME", note_content, Constants.R_NOTES_COMMITS, false)),
                    true, false, true));

    commitNewFile("commitFile");
    testGitClient.tag(tag_name, "Comment");
    ObjectId expectedCommit = testGitClient.revParse("master");

    build(project, Result.SUCCESS, "commitFile");

    // check if everything reached target repository
    assertEquals(expectedCommit, testTargetRepo.git.revParse("master"));
    assertTrue(existsTagInRepo(testTargetRepo.git, tag_name));

}

From source file:hudson.plugins.git.GitPublisherTest.java

License:Open Source License

private void checkEnvVar(FreeStyleProject project, String envName, String envValue) throws Exception {

    String envReference = "${" + envName + "}";

    List<GitSCMExtension> scmExtensions = new ArrayList<GitSCMExtension>();
    scmExtensions.add(new PreBuildMerge(new UserMergeOptions("origin", envReference, null, null)));
    scmExtensions.add(new LocalBranch(envReference));
    GitSCM scm = new GitSCM(remoteConfigs(), Collections.singletonList(new BranchSpec("*")), false,
            Collections.<SubmoduleConfig>emptyList(), null, null, scmExtensions);
    project.setScm(scm);/*from w w w.  j  av a 2s. c  o m*/

    String tagNameReference = envReference + "-tag"; // ${BRANCH_NAME}-tag
    String tagNameValue = envValue + "-tag"; // master-tag
    String tagMessageReference = envReference + " tag message";
    String noteReference = "note for " + envReference;
    String noteValue = "note for " + envValue;
    GitPublisher publisher = new GitPublisher(
            Collections
                    .singletonList(new TagToPush("origin", tagNameReference, tagMessageReference, false, true)),
            Collections.singletonList(new BranchToPush("origin", envReference)),
            Collections
                    .singletonList(new NoteToPush("origin", noteReference, Constants.R_NOTES_COMMITS, false)),
            true, true, true);
    assertTrue(publisher.isForcePush());
    assertTrue(publisher.isPushBranches());
    assertTrue(publisher.isPushMerge());
    assertTrue(publisher.isPushNotes());
    assertTrue(publisher.isPushOnlyIfSuccess());
    assertTrue(publisher.isPushTags());
    project.getPublishersList().add(publisher);

    // create initial commit
    commitNewFile("commitFileBase");
    ObjectId initialCommit = testGitClient.getHeadRev(testGitDir.getAbsolutePath(), "master");
    assertTrue(testGitClient.isCommitInRepo(initialCommit));

    // Create branch in the test repo (pulled into the project workspace at build)
    assertFalse("Test repo has " + envValue + " branch", hasBranch(envValue));
    testGitClient.branch(envValue);
    assertTrue("Test repo missing " + envValue + " branch", hasBranch(envValue));
    assertFalse(tagNameValue + " in " + testGitClient, testGitClient.tagExists(tagNameValue));

    // Build the branch
    final FreeStyleBuild build0 = build(project, Result.SUCCESS, "commitFileBase");

    String build0HeadBranch = getHeadRevision(build0, envValue);
    assertEquals(build0HeadBranch, initialCommit.getName());
    assertTrue(tagNameValue + " not in " + testGitClient, testGitClient.tagExists(tagNameValue));
    assertTrue(tagNameValue + " not in build",
            build0.getWorkspace().child(".git/refs/tags/" + tagNameValue).exists());

    // Create a topic branch in the source repository and commit to topic branch
    String topicBranch = envValue + "-topic1";
    assertFalse("Test repo has " + topicBranch + " branch", hasBranch(topicBranch));
    testGitClient.checkout(null, topicBranch);
    assertTrue("Test repo has no " + topicBranch + " branch", hasBranch(topicBranch));
    final String commitFile1 = "commitFile1";
    commitNewFile(commitFile1);
    ObjectId topicCommit = testGitClient.getHeadRev(testGitDir.getAbsolutePath(), topicBranch);
    assertTrue(testGitClient.isCommitInRepo(topicCommit));

    // Run a build, should be on the topic branch, tagged, and noted
    final FreeStyleBuild build1 = build(project, Result.SUCCESS, commitFile1);
    FilePath myWorkspace = build1.getWorkspace();
    assertTrue(myWorkspace.child(commitFile1).exists());
    assertTrue("Tag " + tagNameValue + " not in build",
            myWorkspace.child(".git/refs/tags/" + tagNameValue).exists());

    String build1Head = getHeadRevision(build1, envValue);
    assertEquals(build1Head, testGitClient.revParse(Constants.HEAD).name());
    assertEquals("Wrong head commit in build1", topicCommit.getName(), build1Head);

}