Skip to content

Setting evaluateOnCommit to any branch will only result in the commit-id instead of the branch name #403

@TheSnoozer

Description

@TheSnoozer

Describe the bug

As discussed in
#395 (comment)
the property <evaluateOnCommit>HEAD</evaluateOnCommit> should allow everything like HEAD, HEAD^1 or a specific branch name (e.g. branch). However when setting it to a specific branch name the git.branch will always be the full commit-id (which is the right fall back when the branch can not be determined -- e.g. detached HEAD).

Steps to Reproduce

  @Test
  @Parameters(method = "useNativeGit")
  public void verifyEvalOnDifferentCommitWithCommitHash(boolean useNativeGit) throws Exception {
    // given
    mavenSandbox.withParentProject("my-jar-project", "jar")
                .withNoChildProject()
                .withGitRepoInParent(AvailableGitTestRepo.WITH_TAG_ON_DIFFERENT_BRANCH)
                .create();
    MavenProject targetProject = mavenSandbox.getParentProject();
    setProjectToExecuteMojoIn(targetProject);

    GitDescribeConfig gitDescribe = createGitDescribeConfig(true, 9);
    gitDescribe.setDirty(null);

    mojo.gitDescribe = gitDescribe;
    mojo.useNativeGit = useNativeGit;
    mojo.evaluateOnCommit = "test";

    // when
    mojo.execute();

    // then
    assertPropertyPresentAndEqual(targetProject.getProperties(), "git.commit.id.abbrev", "9cb810e");

    assertPropertyPresentAndEqual(targetProject.getProperties(), "git.commit.id.describe", "test_tag-0-g9cb810e57");

    assertPropertyPresentAndEqual(targetProject.getProperties(), "git.branch", "test");

    assertPropertyPresentAndEqual(targetProject.getProperties(), "git.tags", "test_tag");

    assertPropertyPresentAndEqual(targetProject.getProperties(), "git.dirty", "true");

    assertPropertyPresentAndEqual(targetProject.getProperties(), "git.total.commit.count", "2");
  }

Expected behavior

  • Tests should pass

Additional context

For reproducibility please provide the following:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions