-
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
Incorrect calculated version on new branch without any commits #1289
Comments
I created a GitHub repo with a simplistic build script to reproduce this issue. I confirm that I was able to reproduce this issue with the following version of GitVersion:
In the following screenshot (taken from here), I have circled in red the build versions that were calculated incorrectly and circled in green the build versions that were calculated correctly: The pattern is consistent: every time I push a new branch without any commits, the version is incorrect. As soon as I push a commit to this new branch the version is calculated correctly. |
@Jericho to rule out any issues with caching on AppVeyor, can you remove this line: https://github.com/Jericho/GitVersion_Issue_Repro/blob/master/appveyor.yml#L24 And then re-run the tests again? Even though you are changing the version number of the tool in the pre-processor directive, if GitVersion is already resolved locally in the tools folder, it won't be updated. This issue is being corrected in 0.22.0 of Cake. |
i.e. I want to rule out this: https://ci.appveyor.com/project/Jericho/gitversion-issue-repro/build/4.0.12-rc.1.build.18#L6 |
@gep13 as you suggested I removed the caching from appveyor.yml and ran my tests again. Unfortunately, same result: |
@Jericho Can I suggest that you use this: https://www.gep13.co.uk/blog/how-to-use-appveyor-remote-desktop-connection To try checking directly on the server to see if there is something "strange" going on when running on AppVeyor? The fact that it is working locally means it has to be something on the environment. |
I RDP'd to the appveyor box and manually ran the GitVersion tool from command prompt with
|
one thing I find odd is: This goes back to what I said when I opened this issue: I think GitVersion is confused by the fact that the latest commit on the release branch is also the latest commit in the master branch since I haven't committed anything to the release yet. |
Wait, something just occurred to me: AppVeyor checks out a specific commit like so:
but, as I said, this commit is both the latest on the master branch and the latest on my release branch so how is GitVersion supposed to figure out that I want the release branch? When I run GitVersion locally, it probably looks at some git metadata to figure it out. |
I noticed something else: in the clone command, AppVeyor specifically specifies "master".
Could this issue be caused by AppVeyor rather than GitVersion? |
I'll see if I can get @FeodorFitsner help with the investigation. |
I opened a ticket with AppVeyor, you can follow the discussion here: http://help.appveyor.com/discussions/problems/7739-appveyor-picks-the-wrong-branch |
@IlyaFinkelshteyn responded to my AppVeyor ticket and pointed out that I may have confused the numerous builds. The Looking at the output of the GitVersion command with
Is it normal to see |
Just to make sure we are on the same page, let me reiterate that I created a new branch, pushed it to GitHub but I haven't committed anything to this new branch. Visually, my repo tree looks like this: and GitVersion visually displays this same information like so:
I'm mentioning this again because I think it's important. GitVersion seems to think the 'HEAD' points to the master branch. With that in mind, please consider the following code in GitVersionCore\ExecuteCore.cs
and more specifically, line 111:
This line creates a new
In my scenario, this assumption is wrong: the desired branch is not the HEAD because it points to "master". Therefore, I propose the following change which attempts to pick the desired branch instead of simply assuming the HEAD:
|
@Jericho: If you make that change to GitVersion, run all the tests and they are all green, we'll happily merge a PR with that change in it. Even better if that PR includes a test that verifies your specific scenario. |
@asbjornu all tests are green and I was having a discussion with @pascalberger last night about writing a unit test but I pointed out to him that current testing fixtures don't seem to exhibit the "bug" I'm trying to solve. For instance, take this existing unit test:
If I understand this test correctly, branch "release-2.0.0" is checked out immediately after being created and the version number is successfully asserted to be "2.0.0-beta.1+0" which, based on my investigation, is not the case in reality (and that's specifically what my PR is trying to fix). In other words, I can't seem to be able to reproduce the issue I'm trying to solve. So (and I hope I'm wrong) it seems like the testing fixtures do not 100% match reality. Thoughts? |
Can I get some guidance on unit testing? As I pointed out, unless I'm wrong, I think the testing fixture does not exhibit the issue that my PR is solving so I don't know how I can effectively demonstrate that my PR indeed solves the issue. |
I believed the Relatedly, this is one of many areas in GitVersion where #1244 might have a huge impact. |
I continued investigating and, it took me while, but I realized the RepositoryFixtureBase has a Checkout method that accept the name of a branch but it doesn't have a method that accepts the SHA of a commit. What I think I would need in order to be able to fully reproduce the issue is something like this:
|
Continuing my research, I made some progress: I found out that the existing
However, I get an exception: I'm continuing my research to try to understand why |
Continuing my research I made some more progress: it looks like the Specifically, it appears that One last thing: Please note that this doesn't explain why this issue results in GitVersion miscalculating the version while it causes the testing fixture to throw an exception but at this point I'm loosing patience and I don't really feel like investigating why they behave differently. |
Doesn't make sense for me too. @JakeGinnivan @asbjornu Do you have any idea why it was implemented like this? |
Duplicated code should be unnecessary. Sounds a bit like it touches on #883 and any change in the codebase that avoids duplication and ensures centralized logic receives a rain of 👍 😄 . |
ok, but what does it mean for my PR?
|
Is it not possible to encapsulate the duplicated code within |
ok, challenge accepted. Let me see how I can encapsulate the duplicate code. |
I came up with a good solution: I moved the logic to properly select the desired branch to a new I was also going to suggest adding the
|
Excellent! How many places is that obsolete constructor in use? Is it a massive task to just delete it and update its usage to you newly created constructor? |
I only found the obsolete constructor used in two places: the "Build" method in I'll be happy to delete the constructor and adjust these two methods to invoke the new constructor. |
Please do! |
Done. Hopefully the PR is now ready to be merged! |
Here's an issue I am experiencing when building on AppVeyor but I am unable to reproduce locally.
Let's say the current build number is
0.4.2
, let's also say that every push triggers a build on AppVeyor and finally let's say that a step in the build script uses GitVersion to calculate the build version.Repro steps
release/0.4.3
Steps to restore expected behavior
I'm guessing GitVersion is confused because the latest commit on the new branch is the same as the latest on the develop branch, but that's just a guess on my part.
I have confirmed this incorrect behavior with GitVersion 3.6.2 I'll double check and confirm if 4.0 beta also suffers from this issue.
The text was updated successfully, but these errors were encountered: