Skip to content

should get exact version from tag #211

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

Merged
merged 2 commits into from
Jul 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion AcceptanceTests/GitFlow/PatchScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public void PatchLatestReleaseExample()
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("1.2.1-beta.1+1");
fixture.Repository.ApplyTag("1.2.1-beta.1");
fixture.AssertFullSemver("1.2.1-beta.2+1");
fixture.AssertFullSemver("1.2.1-beta.1+1");
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("1.2.1-beta.2+2");

// Merge hotfix branch to master
fixture.Repository.Checkout("master");
Expand Down
8 changes: 6 additions & 2 deletions AcceptanceTests/GitFlow/UncycloScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ public void MinorReleaseExample()
fixture.Repository.MakeACommit();
fixture.ExecuteGitVersion().OutputVariables[VariableProvider.FullSemVer].ShouldBe("1.3.0-beta.1+1");

// Apply beta.0 tag
// Apply beta.0 tag should be exact tag
fixture.Repository.ApplyTag("1.3.0-beta.1");
fixture.ExecuteGitVersion().OutputVariables[VariableProvider.FullSemVer].ShouldBe("1.3.0-beta.2+1");
fixture.ExecuteGitVersion().OutputVariables[VariableProvider.FullSemVer].ShouldBe("1.3.0-beta.1+1");

// Make a commit after a tag should bump up the beta
fixture.Repository.MakeACommit();
fixture.ExecuteGitVersion().OutputVariables[VariableProvider.FullSemVer].ShouldBe("1.3.0-beta.2+2");

// Merge release branch to master
fixture.Repository.Checkout("master");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ protected SemanticVersion FindVersion(

if (tagVersion != null)
{
tagVersion.PreReleaseTag.Number++;
semanticVersion.PreReleaseTag = tagVersion.PreReleaseTag;
//If the tag is on the eact commit then dont bump the PreReleaseTag
if (context.CurrentCommit.Sha != tagVersion.Commit.Sha)
{
tagVersion.SemVer.PreReleaseTag.Number++;
}
semanticVersion.PreReleaseTag = tagVersion.SemVer.PreReleaseTag;
}

return semanticVersion;
Expand All @@ -71,7 +75,7 @@ bool IsMostRecentCommitTagged(GitVersionContext context, out SemanticVersion ver
return false;
}

SemanticVersion RetrieveMostRecentOptionalTagVersion(
VersionTaggedCommit RetrieveMostRecentOptionalTagVersion(
IRepository repository, SemanticVersion branchVersion, IEnumerable<Commit> take)
{
foreach (var commit in take)
Expand All @@ -91,7 +95,7 @@ SemanticVersion RetrieveMostRecentOptionalTagVersion(
continue;
}

return version;
return new VersionTaggedCommit(commit, version);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"Major": 5,
"Minor": 0,
"Patch": 0,
"PreReleaseTag": {
"Name": "beta",
"Number": 2
},
"BuildMetaData": {
"CommitsSinceTag": 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be 0?

Copy link
Contributor

Choose a reason for hiding this comment

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

It probably should be.. I think the wiki is wrong in this regard sigh

Thoughts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@distantcam @JakeGinnivan issue raised here #213

"Branch": "release-5.0.0",
"ReleaseDate": {
"OriginalDate": "<date replaced>",
"OriginalCommitSha": "000000000000000000000000000000000000000",
"Date": "<date replaced>",
"CommitSha": "000000000000000000000000000000000000000"
},
"Sha": "000000000000000000000000000000000000000",
"OtherMetaData": null
}
}
19 changes: 19 additions & 0 deletions Tests/BranchFinders/ReleaseTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using GitVersion;
using LibGit2Sharp;
using NUnit.Framework;
using ObjectApproval;

[TestFixture]
public class ReleaseTests : Lg2sHelperBase
Expand Down Expand Up @@ -39,4 +40,22 @@ public void EnsureAReleaseBranchNameDoesNotExposeAStability()
}
}

[Test]
public void Tag_on_commit_should_be_exact_tag()
{
var repoPath = Clone(ASBMTestRepoWorkingDirPath);
using (var repo = new Repository(repoPath))
{
// Create a release branch from the parent of current develop tip
repo.Branches.Add("release-5.0.0", "develop~").ForceCheckout();

AddOneCommitToHead(repo, "code");
AddTag(repo, "5.0.0-beta2");

var finder = new ReleaseVersionFinder();

var version = finder.FindVersion(new GitVersionContext(repo, repo.Head));
ObjectApprover.VerifyWithJson(version, Scrubbers.GuidAndDateScrubber);
}
}
}
9 changes: 9 additions & 0 deletions Tests/Helpers/Lg2sHelperBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,13 @@ protected static Commit AddOneCommitToHead(Repository repo, string type)
var sign = Constants.SignatureNow();
return repo.Commit(type + " commit", sign, sign);
}

protected static void AddTag(Repository repo, string tagName)
{
var randomFile = Path.Combine(repo.Info.WorkingDirectory, Guid.NewGuid().ToString());
File.WriteAllText(randomFile, string.Empty);
repo.Index.Stage(randomFile);
var sign = Constants.SignatureNow();
repo.ApplyTag(tagName, repo.Head.Tip.Id.Sha, sign, "foo");
}
}