crotwell / version-class

A Gradle Plugin to create a class containing version info based on the project.
Apache License 2.0
5 stars 1 forks source link

error with git_last_tag #2

Closed crotwell closed 1 month ago

crotwell commented 1 month ago

In new 1.4.0, sometimes git_last_tag_date gives multiline value, which is then not legal java:

    private static final String git_last_tag_date = "tag first_tag
Tagger: Philip Crotwell <crotwell@seis.sc.edu>

first tag
2024-09-26T12:11:02-04:00";

This is from a test project, after: git tag -a -m 'first tag' first_tag

Running the git command manually also gives a longer response:

> git show -s --format=%cI first_tag --
tag first_tag
Tagger: Philip Crotwell <crotwell@seis.sc.edu>

first tag
2024-09-26T12:11:02-04:00

This is with git version 2.39.5 (Apple Git-154).

Maybe related to annotate tags???

@AliAlbarrak have you seen this? Seems like either a better git cmd to only get the date, or some code to handle a multiline string is needed?

AliAlbarrak commented 1 month ago

This seems to happen when using annotated tags. We don't use annotated tag so I missed testing this. This command should work on annotated tags but I didn't test all other scenarios.

git show -s --no-notes --format='%cI' $(git rev-list -n 1 first_tag) --

Please note that the command is using substitution syntax $() which may not work on Windows. It needs to be split into 2 commands instead.

I'll confirm if it doesn't break anything else then will make another pull request.

Sorry for the issue

crotwell commented 1 month ago

Do you think this would work?

git log -1 --format=%ai $git_last_tag
crotwell commented 1 month ago

Maybe better with strict iso dates, so --format=%aI

AliAlbarrak commented 1 month ago

I tested multiple scenarios and using the git log command works. Also, strict iso8601 format is better for consistency with other dates.

crotwell commented 1 month ago

thanks for testing. updated, released 1.4.1 with the log command