Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get changelog between HEAD and most recent tag? #67

Closed
webminster opened this issue Feb 14, 2022 · 15 comments
Closed

How to get changelog between HEAD and most recent tag? #67

webminster opened this issue Feb 14, 2022 · 15 comments

Comments

@webminster
Copy link

Describe your use-case which is not covered by existing documentation.

Is there any way to get the changes between the top of the repor (HEAD) and the most recent of some matching tag? I need to create a changelog for what changed between HEAD and the last "release" that was done.

I'm trying to use the pipeline version of this, but I see no options for this in the snippets generator. As far as tag refs, all I see is a fixed reference to 'git-changelog-1.50', but no other samples.

Can you explain tag refs a little better? Thanks.

Reference any relevant documentation, other materials or issues/pull requests that can be used for inspiration.

Request reopen of #66

Sorry, but how does this change help? I am trying to get a changelog between tags. This change appears to be how to get a version number. Can you explain?

@tomasbjerre
Copy link
Collaborator

It can now give you the most recent tag matching a semantic version.

You can construct a changelog between that tag and HEAD.

@webminster
Copy link
Author

Is there any way to not use semantic versioning for this request? I'm building an AMI build pipeline that I'd like to use something else (like the release date) as version. But I'd have to look back to either the most recent tag, or most recent tag named "release" or something.

@tomasbjerre
Copy link
Collaborator

If you just want the most recent tag, perhaps this works? https://gist.github.com/rponte/fdc0724dd984088606b0

@webminster
Copy link
Author

Am not having luck with 3.19 and getting tags. Is there a trick to what it's looking for?

I pushed a tag to the remote:
commit 069953e545e417cf89f5478dfcd5599e43e07500 (tag: 2022-02-11, tag: 1.0.0)
Author: Alan Sparks [email protected]
Date: Thu Feb 10 15:18:49 2022 -0700

Added this to a pipeline step:
def highestVersion = getHighestSemanticVersion()
currentVersion = highestVersion.findTag().orElse("")
println(" Git tag:" + currentVersion.toString())

But the printed value is empty.

Also had to add script approvals for se.bjurr.gitchangelog.internal.semantic.SemanticVersion findTag and for orElse().
-Alan

@tomasbjerre
Copy link
Collaborator

Are you sure Jenkins is fetching the tags?

This is why I like to use the command line tool:
https://github.com/tomasbjerre/git-changelog-command-line#example---semantic-versioning-from-conventional-commits

Easier to fiddle with locally.

@webminster
Copy link
Author

I'm seeing this in the Jenkins build log, I thought --tags would be including the tags. I was wanting to avoid installing NPM stuff on the server just for debugging...

11:04:40 > git fetch --tags --progress --prune -- [email protected]:CCoE/chglog.git +refs/heads/master:refs/remotes/origin/master # timeout=10
11:04:40 Checking out Revision 026ea085cf74bf

@tomasbjerre
Copy link
Collaborator

I ment you can use the command line locally. It uses the same code.

@webminster
Copy link
Author

webminster commented Feb 14, 2022

So, I'm a little lost. If I run "git tag", I get:
$ git tag
1.0.0
2022-02-11
release

If I run your utility, I get:
$ npx git-changelog-command-line --print-highest-version-tag
Exception in thread "main" java.util.NoSuchElementException: No value present
at java.base/java.util.Optional.get(Optional.java:148)
at se.bjurr.gitchangelog.main.Main.main(Main.java:746)

I see 1.0.0 there on the remote. Is the code looking for a tag format in particular?
-Alan

EDIT: I see - the tag has to be of format: vx.x.x.

@tomasbjerre
Copy link
Collaborator

Do you have just a few commits in the repo? A shallow clone maby? Is the tag on the first commit in the repo?
I actually found a bug here, perhaps same as you are experiencing.

@webminster
Copy link
Author

webminster commented Jul 15, 2022

I still can't figure out how to get what I need here. It's not making sense to me.

I have a branch, with a git log including:
`commit 482fea9011c61dc2d05a08260d3a328c3df1acdf (HEAD -> chglog, origin/chglog)
Author: Alan Sparks [email protected]
Date: Fri Jul 15 12:33:08 2022 -0600

remove PDSC-polkit

commit e482f40ba45fab3ecfc5b2d818d235be637e0fdb
Merge: 0f0f225 56065b3
Author: Alan Sparks [email protected]
Date: Wed Apr 13 13:11:01 2022 -0600

Upgrade to Packer 1.7

commit 0f0f2259a6501377d811ee1b5c122e25fc139389
Merge: ed7b1d3 82f2b5e
Author: Alan Sparks [email protected]
Date: Wed Apr 13 13:07:59 2022 -0600

Merge branch 'chglog' of gitlab.devops.ss.saas.microfocus.com:ami/foundation/amazon-2 into chglog

commit 56065b331d9fe444e71f215ec075e5036b8980cc (tag: 20220413)
Author: Alan Sparks [email protected]
sparksa@ubuntu1:~/glab/ami/foundation/amazon-2$ git log|cat
commit 482fea9011c61dc2d05a08260d3a328c3df1acdf
Author: Alan Sparks [email protected]
Date: Fri Jul 15 12:33:08 2022 -0600

remove PDSC-polkit

commit e482f40ba45fab3ecfc5b2d818d235be637e0fdb
Merge: 0f0f225 56065b3
Author: Alan Sparks [email protected]
Date: Wed Apr 13 13:11:01 2022 -0600

Upgrade to Packer 1.7

`

So I've tried all the combinations of commits and refs I can think of, and the command line version keeps adding way more than between the HEAD and the tag or commit I'm trying to stop at (tag: 20220413, commit 56065b331d9fe444e71f215ec075e5036b8980cc):

`npx git-changelog-command-line --from-commit 56065b331d9fe444e71f215ec075e5036b8980cc --to-commit HEAD -std --template template.txt

  • remove PDSC-polkit

    -- Alan Sparks 2022-07-15 18:33:08

  • Upgrade to Packer 1.7

    -- Alan Sparks 2022-04-13 19:11:01

  • Merge branch 'chglog' of gitlab.devops.ss.saas.microfocus.com:ami/foundation/amazon-2 into chglog

    -- Alan Sparks 2022-04-13 19:07:59

  • source ami filter in AMIspec

    -- Alan Sparks 2022-04-13 18:59:20

  • packer version and template update

    -- Alan Sparks 2022-04-13 18:59:20

  • duplicate source_ami def

    -- Alan Sparks 2022-04-13 18:59:20

  • fix name tag

    -- Alan Sparks 2022-04-13 18:59:20

  • add override to template

    -- Alan Sparks 2022-04-13 18:59:20

  • fix name tag

    -- Alan Sparks 2022-03-16 22:09:41

  • duplicate source_ami def

    -- Alan Sparks 2022-03-16 19:41:01

  • packer version and template update

    -- Alan Sparks 2022-03-16 19:38:18

  • add override to template

    -- Alan Sparks 2022-03-04 23:07:05

  • source ami filter in AMIspec

    -- Alan Sparks 2022-03-04 22:23:45
    `

It's even stranger to me that it picks it's own place in the log to stop, that 3/4 date isn't the first commit.
Is there a bug here? Is there no way to get the changes between HEAD and the most recent tag ref?
-Alan

@tomasbjerre
Copy link
Collaborator

It would be easier to understand your use case if you supplied a graph like:
git log --oneline --graph

@tomasbjerre
Copy link
Collaborator

The full graph, as in previous comment, and also the template being used would help understand this.

I made a test in this repo:

git clone [email protected]:tomasbjerre/git-changelog-lib.git
git checkout ba9d565
git log --oneline --graph 
* ba9d565 (HEAD) More settings can be set from command line
* 3950c64 [Gradle Release Plugin] - new version commit:  '1.1-SNAPSHOT'.
* 01484ce (tag: 1.0) [Gradle Release Plugin] - pre tag commit:  '1.0'.
* 83a8a7b Doc
* 5c54861 Test
* 051effe Work for 1.0
* 5aaeb90 Initial commit
* a1aa5ff (tag: 0.0.1) Initial commit
npx git-changelog-command-line --to-commit 01484ce -std  -tec "
{{#commits}}
  {{hash}}
{{/commits}}
"

  01484ce71bbc76e
  83a8a7b2f96ba88
  5c54861708099d9
  051effe72405e78
  5aaeb907f68915a
  a1aa5ff5b625e63
npx git-changelog-command-line --to-commit HEAD -std  -tec "
{{#commits}}
  {{hash}}
{{/commits}}
"

  ba9d565ddd15d1b
  3950c640e41f436
  01484ce71bbc76e
  83a8a7b2f96ba88
  5c54861708099d9
  051effe72405e78
  5aaeb907f68915a
  a1aa5ff5b625e63
npx git-changelog-command-line --from-commit 01484ce --to-commit HEAD -std   -tec "
{{#commits}}
  {{hash}}
{{/commits}}
"

  ba9d565ddd15d1b
  3950c640e41f436

@webminster
Copy link
Author

webminster commented Jul 18, 2022

OK, let me give something concrete. Maybe you can correct my understanding.

I have a git history like:

===============================================================
commit 482fea9011c61dc2d05a08260d3a328c3df1acdf (HEAD -> chglog, origin/chglog)
Author: Alan Sparks [email protected]
Date: Fri Jul 15 12:33:08 2022 -0600

remove PDSC-polkit

commit e482f40ba45fab3ecfc5b2d818d235be637e0fdb
Merge: 0f0f225 56065b3
Author: Alan Sparks [email protected]
Date: Wed Apr 13 13:11:01 2022 -0600

Upgrade to Packer 1.7

commit 0f0f2259a6501377d811ee1b5c122e25fc139389
Merge: ed7b1d3 82f2b5e
Author: Alan Sparks [email protected]
Date: Wed Apr 13 13:07:59 2022 -0600

Merge branch 'chglog' of gitlab.devops.ss.saas.microfocus.com:ami/foundation/amazon-2 into chglog

commit 56065b331d9fe444e71f215ec075e5036b8980cc (tag: 20220413)
Author: Alan Sparks [email protected]
Date: Wed Apr 13 13:07:13 2022 -0600

Add source AMI override/filter

=========================================================

and the git online requested looks like:

=========================================================

  • 482fea9 (HEAD -> chglog, origin/chglog) remove PDSC-polkit
  • e482f40 Upgrade to Packer 1.7
    |
    | * 56065b3 (tag: 20220413) Add source AMI override/filter
  • | 0f0f225 Merge branch 'chglog' of gitlab.devops.ss.saas.microfocus.com:ami/foundation/amazon-2 into chglog
    |\
    | * | 82f2b5e fix name tag
    | * | 8d1eda1 duplicate source_ami def
    | * | 8fa5efc packer version and template update
    | * | 14f9128 add override to template
    | * | ab74319 source ami filter in AMIspec
    | |/
    | * eab734b Changes to support CTP and SRE
  • | ed7b1d3 fix name tag
  • | 866121a duplicate source_ami def
  • | 891ffc1 packer version and template update
  • | 6fa9252 add override to template
  • | 7897ca9 source ami filter in AMIspec
    |/
  • 5f553d6 Reset cloud-init data
  • 884e34c (origin/development) Remove polkit per CVE-2021-4034

===============================================================

What I'm trying to do is get a changelog between the HEAD and to the tagged (20220413, commit 56065b331d9fe444e71f215ec075e5036b8980cc) on that branch. but I seem to keep going back farther, to commit 7897ca98ea38b16feb40d36cf70e61861580a55e.

Am I being stupid because there's a merge in there?
-Alan

@tomasbjerre
Copy link
Collaborator

This is intended. 7897ca9 is in the parents of HEAD and not in the parents of 20220413.

@tomasbjerre
Copy link
Collaborator

Perhaps this helps:
#84 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants