Skip to content

Commit 6944d02

Browse files
committed
Use context commit instead of branch tip
1 parent 3293a66 commit 6944d02

8 files changed

+16
-17
lines changed

GitVersionCore/GitFlow/BranchFinders/DevelopBasedVersionFinderBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ protected SemanticVersion FindVersion(
1010
BranchType branchType)
1111
{
1212
var ancestor = FindCommonAncestorWithDevelop(context.Repository, context.CurrentBranch, branchType);
13-
13+
1414
if (!IsThereAnyCommitOnTheBranch(context.Repository, context.CurrentBranch))
1515
{
1616
var developVersionFinder = new DevelopVersionFinder();
1717
return developVersionFinder.FindVersion(context);
1818
}
1919

2020
var versionOnMasterFinder = new VersionOnMasterFinder();
21-
var versionFromMaster = versionOnMasterFinder.Execute(context, context.CurrentBranch.Tip.Committer.When);
21+
var versionFromMaster = versionOnMasterFinder.Execute(context, context.CurrentCommit.Committer.When);
2222

2323
var numberOfCommitsOnBranchSinceCommit = NumberOfCommitsOnBranchSinceCommit(context, ancestor);
24-
var sha = context.CurrentBranch.Tip.Sha;
24+
var sha = context.CurrentCommit.Sha;
2525
var releaseDate = ReleaseDateFinder.Execute(context.Repository, sha, 0);
2626
var preReleaseTag = context.CurrentBranch.Name
2727
.TrimStart(branchType.ToString() + '-')
@@ -89,4 +89,4 @@ public bool IsThereAnyCommitOnTheBranch(IRepository repo, Branch branch)
8989
return true;
9090
}
9191
}
92-
}
92+
}

GitVersionCore/GitFlow/BranchFinders/DevelopVersionFinder.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class DevelopVersionFinder
88
public SemanticVersion FindVersion(GitVersionContext context)
99
{
1010
var versionOnMasterFinder = new VersionOnMasterFinder();
11-
var tip = context.CurrentBranch.Tip;
11+
var tip = context.CurrentCommit;
1212
var versionFromMaster = versionOnMasterFinder.Execute(context, tip.When());
1313

1414
var f = new CommitFilter
@@ -32,6 +32,5 @@ public SemanticVersion FindVersion(GitVersionContext context)
3232
};
3333
return semanticVersion;
3434
}
35-
3635
}
3736
}

GitVersionCore/GitFlow/BranchFinders/OptionallyTaggedBranchVersionFinderBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected SemanticVersion FindVersion(
3030

3131
var tagVersion = RetrieveMostRecentOptionalTagVersion(context.Repository, version, context.CurrentBranch.Commits.Take(nbHotfixCommits + 1));
3232

33-
var sha = context.CurrentBranch.Tip.Sha;
33+
var sha = context.CurrentCommit.Sha;
3434
var releaseDate = ReleaseDateFinder.Execute(context.Repository, sha, version.Patch);
3535
var semanticVersion = new SemanticVersion
3636
{
@@ -167,4 +167,4 @@ int NumberOfCommitsInBranchNotKnownFromBaseBranch(
167167
return repo.Commits.QueryBy(filter).Count();
168168
}
169169
}
170-
}
170+
}

GitVersionCore/GitFlow/GitFlowVersionFinder.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public SemanticVersion FindVersion(GitVersionContext context)
66
{
77
if (context.CurrentBranch.IsMaster())
88
{
9-
return new MasterVersionFinder().FindVersion(context.Repository, context.CurrentBranch.Tip);
9+
return new MasterVersionFinder().FindVersion(context.Repository, context.CurrentCommit);
1010
}
1111

1212
if (context.CurrentBranch.IsHotfix())
@@ -31,12 +31,10 @@ public SemanticVersion FindVersion(GitVersionContext context)
3131

3232
if (context.CurrentBranch.IsSupport())
3333
{
34-
return new SupportVersionFinder().FindVersion(context.Repository, context.CurrentBranch.Tip);
34+
return new SupportVersionFinder().FindVersion(context.Repository, context.CurrentCommit);
3535
}
3636

3737
return new FeatureVersionFinder().FindVersion(context);
3838
}
3939
}
40-
41-
4240
}

GitVersionCore/GitHubFlow/BuildNumberCalculator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ public SemanticVersion GetBuildNumber(GitVersionContext context)
2323
var commitsSinceLastRelease = NumberOfCommitsOnBranchSinceCommit(context, commit);
2424
var semanticVersion = nextSemverCalculator.NextVersion();
2525

26-
var sha = context.CurrentBranch.Tip.Sha;
26+
var sha = context.CurrentCommit.Sha;
2727
var releaseDate = ReleaseDateFinder.Execute(context.Repository, sha, semanticVersion.Patch);
2828

2929
// TODO Need a way of setting this in a cross cutting way
30-
semanticVersion.BuildMetaData = new SemanticVersionBuildMetaData(commitsSinceLastRelease,
30+
semanticVersion.BuildMetaData = new SemanticVersionBuildMetaData(commitsSinceLastRelease,
3131
context.CurrentBranch.Name, releaseDate);
3232
if (context.CurrentBranch.IsPullRequest())
3333
{

GitVersionCore/GitHubFlow/LastTaggedReleaseFinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ VersionTaggedCommit GetVersion(GitVersionContext context)
3131
})
3232
.Where(a => a != null)
3333
.ToArray();
34-
var olderThan = context.CurrentBranch.Tip.Committer.When;
34+
var olderThan = context.CurrentCommit.Committer.When;
3535
var lastTaggedCommit =
3636
context.CurrentBranch.Commits.FirstOrDefault(c => c.Committer.When <= olderThan && tags.Any(a => a.Commit == c));
3737

GitVersionCore/GitVersionContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ public GitVersionContext(IRepository repository, Branch currentBranch)
1616
{
1717
Repository = repository;
1818
CurrentBranch = currentBranch;
19+
CurrentCommit = CurrentBranch.Tip;
1920
}
2021

2122
public IRepository Repository { get; private set; }
2223
public Branch CurrentBranch { get; private set; }
24+
public Commit CurrentCommit { get; private set; }
2325
}
2426
}

GitVersionCore/GitVersionFinder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void EnsureHeadIsNotDetached(GitVersionContext context)
3939
return;
4040
}
4141

42-
var message = string.Format("It looks like the branch being examined is a detached Head pointing to commit '{0}'. Without a proper branch name GitVersion cannot determine the build version.", context.CurrentBranch.Tip.Id.ToString(7));
42+
var message = string.Format("It looks like the branch being examined is a detached Head pointing to commit '{0}'. Without a proper branch name GitVersion cannot determine the build version.", context.CurrentCommit.Id.ToString(7));
4343
throw new ErrorException(message);
4444
}
4545

@@ -54,4 +54,4 @@ void EnsureLocalBranchExists(IRepository repository, string branchName)
5454
throw new ErrorException(string.Format("This repository doesn't contain a branch named '{0}'. Please create one. Existing branches: {1}", branchName, existingBranches));
5555
}
5656
}
57-
}
57+
}

0 commit comments

Comments
 (0)