-
Notifications
You must be signed in to change notification settings - Fork 653
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
GitVersion should only consider tags matching current branch config (was: GitVersion fails to return correct version when tag exists on commit) #2340
Comments
The workflow you are describing is not supported by GitVersion. The closest match you have may be Mainline mode, but tags are going to have the highest weight when figuring out a version number no matter what you do. This is by design and is not going to change. |
Can you elaborate more on why the workflow is not supported? I use GitFlow, with develop creating snapshots (instead of alpha). Mainline mode does not suite our development needs. I know that it is a design decision to build versions preferably by using the commit's tag, and I am not suggesting to remove it, but rather to improve it. Of course this can also be a configurable option for each branch. The option could work like that: (in the branch configuration) If that improvement is not an option (apart from possible minor bugs in my suggested implementation), please explain why, and what I could change to build a release (candidate) from an already tagged commit. |
Perhaps I'm not properly understanding your use-case. Please submit a PR with a |
I'd like to, but the way of working for such a change and the GitVersion internals are all new to me. But I'll try to get through it. I just did a code analysis to find a place where I would assume the change to take place. In My intention is to have GitVersion focus more on the current branch and disregard tags on the same commit, but belonging to another branch (again, using the configuration to tell to which branch a tag belongs). The essential code seems to be in
where Is there a function somewhere that can tell me if a Git-tag matches a specific configured branch tag? How would I get the configured branch tag? Also, two special cases have to be considered: if the configured branch tag is empty (e.g. master branch), the match must yield true if the Git-tag has no prefix, and if the configured branch tag is "useBranchName", this has to be resolved. |
Adding a test shouldn't require deep knowledge about the GitVersion codebase. They are pretty straight forward: GitVersion/src/GitVersionCore.Tests/IntegrationTests/VersionInTagScenarios.cs Lines 33 to 52 in e8102ab
Start with writing a test that provokes the behaviour you're experiencing, then you can start deep-diving into the code and change things to see whether it fixes your problem or not. Without seeing a reproduction in a test, it's very hard for me to help you figure out where or how to fix your problem, so please start there. You can submit a draft pull request to allow feedback and discussion before the problem is solved and the PR is good for a final review and merge.
This sounds impossible. Git doesn't have a link between branch and tag references. To Git, they are basically the same: a reference to a commit. So as long as you have a tag reference to the same commit that is checked out, which branch was checked out when the commit was made, is irrelevant. You would need to add another commit to the current branch to deviate from the "tagged branch" so to say. |
I'll try to get quite close to it for one example at least, based on some other tests. Apologies for likely mistakes.
|
Sorry, but writing code in a comment is not the same as submitting a draft pull request, @DocZoid. |
Sorry, but you are not being helpful either, @asbjornu . |
Sorry, but the constructive feedback is very hard to give on an island of code like that. If I had a proper draft pull request to look at, I would for instance know whether the code even compiled and the result of the test would be available to me. As presented, I would have to open my editor, paste in your code, compile it, execute tests, etc. That requires me to actually block out time to even know what I'm looking at here. If you are unable to allot the required time and energy to submit a draft pull request, I'm not going to be able to allot the required time and energy to give you feedback. Sorry. |
I never said that I won't make a pull request, it's just small steps with a fail-fast mindset (if you tell me "that won't work because you have not considered <mutant unicorns>" I might as well give it up altogether). Well, I have checked out the code and added a (hopefully improved) test. I have no access to push the commit - is it something I have to look up in GitHub or do you need to give me repo rights? I didn't use GitHub for contributing yet and the permissions doc page I found didn't help. Edit: I believe I need collaborator rights |
We don't give permissions to directly commit the changes to the repository. But all those that want to contribute usually fork the repository, make the adjustments in their fork then they create a pull request against the original repository. |
You can read about how to fork a repository and then how to submit a pull request from a fork. |
…mit should not consider the tag if it does not match to the current branch config
Getting there... do I work on master then, or do I still start a new branch? |
A separate branch would be best, as a pull request is not frozen in time, so whenever commits are added to the branch you create the pull request from, they will be added to the pull request. As |
…mit should not consider the tag if it does not match to the current branch config
…mit should not consider the tag if it does not match to the current branch config
…mit should not consider the tag if it does not match to the current branch config
@asbjornu I finally have some time again to get back on this topic. Does this pull request match your expectations or am I missing something? What is your opinion on the shown behavior? |
Thanks for the PR and test, @DocZoid. It is a great way to understand your use-case. From what I understand, you would like I don't think we can support that, at least not without configuration. Tags always take presedence when they are available on the current commit and I'm not sure we want to change this, even with configuration. It's also a bit strange to create a Which flow are you using? |
Exactly, that is scenario 1 from my initial comment. I'll try to add a test for scenario 2 as well. It has to be configurable for sure. I wrote
For example, the release branch configuration for the test would be
Actually we are using Git Flow, but only as a branching model, not using the commands. When creating a release branch, we do not create empty commits to branch out of develop because this would be a step which would have to be done automatically by our CI/CD build pipeline, and we would not want to have it commit automatically. This is also not supported by the repository permissions and commit hook configuration. Just using a regular branch (initiated by jira in our case) is a neat way to support Git Flow but not using the command line tool. |
… commit, the tag should not be considered if it does not match to the current branch config
This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs. Thank you for your contributions. |
there might be an easier solution
Sorry for not answering this before, @DocZoid.
I too use Git Flow "manually" so to speak, because I often don't agree with everything the automatic tooling does and prefer doing the individual steps myself. But by the sound of your workflow, it does not match entirely what Git Flow prescribes.
If you're not adding any commits to the |
@NatMarchand, thanks for the detailed explanation. Is the following pseudocode a fair description of what's happening? var semver = new SemVer("0.2.0");
var taggedSemanticVersion = new SemVer("0.2.0-alpha.0");
if (semver.CompareTo(taggedSemanticVersion, false) > 0)
{
// "0.2.0-alpha.0" is considered to be equal to "0.2.0",
// therefore, the `taggedSemanticVersion` is set to `null`
// and `semver` is used instead.
} I can't say exactly why the prerelease label would not be considered in this case. Can you name the tests that are failing when changing |
It seems like this may be a duplicate of #2241. |
An integration test in #3441 gives the follwoting result: [Test]
public void __Just_A_Test__()
{
var configuration = GitFlowConfigurationBuilder.New
.WithBranch("develop", builder => builder.WithLabel("snapshot"))
.WithBranch("release", builder => builder.WithLabel("rc"))
.Build();
using var fixture = new EmptyRepositoryFixture();
fixture.MakeACommit();
fixture.BranchTo("develop");
fixture.MakeACommit();
fixture.MakeATaggedCommit("0.1.2-snapshot.2");
fixture.BranchTo("release/0.1.2");
// ✅ succeeds as expected
fixture.AssertFullSemver("0.1.2-rc.1+0", configuration);
} |
🎉 This issue has been resolved in version 6.0.0-beta.2 🎉 Your GitReleaseManager bot 📦🚀 |
Describe the bug
Tags have a too strong weight on the version evaluation which I feel is a bug. I am quite new to versioning and GitVersion, so I might be on the wrong track without knowing. I have read in some other issue that fast-forward merges for master are generally discouraged (forbidden?), and this is a part of my issue (#2). The proposed fix would as a side effect allow using fast-forward merges in my opinion.
There are two scenarios where the tag should not be used to evaluate the version:
Expected Behavior
Actual Behavior
Possible Fix
Multiple branches point to the same commit. This is confusing GitVersion, which takes tags from that commit, but it does not respect the branch configuration of the current branch when analyzing the tags, e.g. when I am working on a release branch, it should only look for previous version tags which are formatted like its own tag configuration in the release branch ("with "rc" in it, so tags 0.1.2-rc.1 should be considered, but not 0.1.2-snapshot.2, because of the configuration "tag: rc")
Steps to Reproduce
Context
We have commit hooks checking every commit message. Therefor, it seems like an easy option to use fast-forward merges for master to avoid commits, but GitVersion is missing the mentioned configuration option to be able to handle fast-forward merges.
Also, I do not know how GitVersion is intended to be used when creating a release branch without adding an empty commit on that branch before building it, if the commit already has a tag. Deleting all tags locally would be a workaround, but it has a smell of nastiness.
Your Environment
The text was updated successfully, but these errors were encountered: