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

Improve ExecuteCore.ExecuteInternal when HEAD is not pointing at the desired branch #1291

Merged
merged 5 commits into from
Sep 21, 2017

Conversation

Jericho
Copy link
Contributor

@Jericho Jericho commented Sep 7, 2017

This resolves #1289

@pascalberger
Copy link
Member

@Jericho Thanks for the PR! Would it be possible that you can also create a test case similar to the scenario with your demo repo (branch without a commit on it) and repo checked out to specific commit?

@Jericho Jericho force-pushed the head_not_pointing_at_desired_branch branch from adb8ec5 to 9da272c Compare September 19, 2017 02:56
…or on the GitVersionContext class

This allows this new logic introduced by the PR to be shared by the ExecuteCore class and the the unit testing fixture without having to duplicate code.
@Jericho Jericho force-pushed the head_not_pointing_at_desired_branch branch from 9da272c to dfa6c79 Compare September 19, 2017 03:02
…a given commit is on multiple branches and the desired branch is not specified
Copy link
Member

@asbjornu asbjornu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor nit, otherwise this LGTM! 👍

public GitVersionContext(IRepository repository, Config configuration, bool isForTrackingBranchOnly = true, string commitId = null)
: this(repository, repository.Head, configuration, isForTrackingBranchOnly, commitId)
public GitVersionContext(IRepository repository, string targetBranch, Config configuration, bool onlyEvaluateTrackedBranches = true, string commitId = null)
: this(repository, repository.Branches.SingleOrDefault(b => b.CanonicalName == targetBranch || b.FriendlyName == targetBranch) ?? repository.Head, configuration, onlyEvaluateTrackedBranches, commitId)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please reduce the number of statements per line here? It's a bit hard to read with so much going on in one line of code. 😃

@Jericho
Copy link
Contributor Author

Jericho commented Sep 20, 2017

@asbjornu done.

@Jericho
Copy link
Contributor Author

Jericho commented Sep 20, 2017

@pascalberger done. I created a file called BranchWithoutCommitScenario.cs where I have a test with this exact scenario.

Speaking of this scenario, I mentioned it before but I want to repeat it because it's been bothering me: if you remove the fix I wrote and run the unit test for my scenario, you would hope to see the version being miscalculated like I observed when using GitVersion on AppVeyor. But that's not the case. The testing fixture throws an exception because it can't handle a detached head in a git repo. I don't know why the behavior is different and, to be honest, I don't have the appetite to investigate but I want everyone to be aware.

: this(repository, repository.Branches.SingleOrDefault(b => b.CanonicalName == targetBranch || b.FriendlyName == targetBranch) ?? repository.Head, configuration, onlyEvaluateTrackedBranches, commitId)
: this(repository,
repository.Branches.SingleOrDefault(b => b.CanonicalName == targetBranch || b.FriendlyName == targetBranch) ?? repository.Head,
configuration, onlyEvaluateTrackedBranches, commitId)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only now discovered that this all happens within a constructor. Sorry for not catching that earlier. Could you please add a static method that wraps repository.Branches.SingleOrDefault(b => b.CanonicalName == targetBranch || b.FriendlyName == targetBranch) ?? repository.Head and invoke that method from the constructor?

@Jericho
Copy link
Contributor Author

Jericho commented Sep 20, 2017

@asbjornu done. Also, instead of just a one-liner, I broke it up into multiple lines which allowed me to add comments to explain each step in the logic.

@asbjornu
Copy link
Member

@Jericho: Beautiful! As soon as the tests are green, this will be merged. Thank you so much for your persistence and tireless effort! 😄 👍 ❤️

@pascalberger
Copy link
Member

@Jericho Thanks for getting this done and your persistence 👍

@asbjornu asbjornu merged commit 018ba17 into GitTools:master Sep 21, 2017
@Jericho Jericho deleted the head_not_pointing_at_desired_branch branch April 10, 2018 02:27
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

Successfully merging this pull request may close these issues.

Incorrect calculated version on new branch without any commits
3 participants