diff --git a/src/GitVersion.LibGit2Sharp/Git/GitRepository.cs b/src/GitVersion.LibGit2Sharp/Git/GitRepository.cs index b79cc659bc..5519a5e736 100644 --- a/src/GitVersion.LibGit2Sharp/Git/GitRepository.cs +++ b/src/GitVersion.LibGit2Sharp/Git/GitRepository.cs @@ -335,7 +335,7 @@ public ICommit GetBaseVersionSource(ICommit currentBranchTip) } catch (NotFoundException exception) { - throw new GitVersionException($"Cannot find commit {currentBranchTip.Sha}. Please ensure that the repository is an unshallow clone with `git fetch --unshallow`.", exception); + throw new GitVersionException($"Cannot find commit {currentBranchTip}. Please ensure that the repository is an unshallow clone with `git fetch --unshallow`.", exception); } } public IEnumerable GetMainlineCommitLog(ICommit baseVersionSource, ICommit mainlineTip) diff --git a/src/GitVersionCore.Tests/Core/RepositoryExtensionsTests.cs b/src/GitVersionCore.Tests/Core/RepositoryExtensionsTests.cs index badad76764..b5d9cab59d 100644 --- a/src/GitVersionCore.Tests/Core/RepositoryExtensionsTests.cs +++ b/src/GitVersionCore.Tests/Core/RepositoryExtensionsTests.cs @@ -55,7 +55,7 @@ private static void EnsureLocalBranchExistsForCurrentBranch(IGitRepository repo, } else { - log.Info(isBranch ? $"Updating local branch {localCanonicalName} to point at {repoTip.Sha}" + log.Info(isBranch ? $"Updating local branch {localCanonicalName} to point at {repoTip}" : $"Updating local branch {localCanonicalName} to match ref {currentBranch}"); var localRef = repo.Refs[localCanonicalName]; repo.Refs.UpdateTarget(localRef, repoTipId); diff --git a/src/GitVersionCore/Configuration/BranchConfigurationCalculator.cs b/src/GitVersionCore/Configuration/BranchConfigurationCalculator.cs index 9a2e680454..f3a0e14bf7 100644 --- a/src/GitVersionCore/Configuration/BranchConfigurationCalculator.cs +++ b/src/GitVersionCore/Configuration/BranchConfigurationCalculator.cs @@ -31,7 +31,7 @@ public BranchConfig GetBranchConfiguration(IBranch targetBranch, ICommit current if (matchingBranches == null) { - log.Info($"No branch configuration found for branch {targetBranch.Name.Friendly}, falling back to default configuration"); + log.Info($"No branch configuration found for branch {targetBranch}, falling back to default configuration"); matchingBranches = BranchConfig.CreateDefaultBranchConfig(FallbackConfigName) .Apply(new BranchConfig @@ -103,7 +103,7 @@ private BranchConfig InheritBranchConfiguration(IBranch targetBranch, BranchConf } } - log.Info("Found possible parent branches: " + string.Join(", ", possibleParents.Select(p => p.Name.Friendly))); + log.Info("Found possible parent branches: " + string.Join(", ", possibleParents.Select(p => p.ToString()))); if (possibleParents.Count == 1) { @@ -125,7 +125,7 @@ private BranchConfig InheritBranchConfiguration(IBranch targetBranch, BranchConf // if develop exists and master if not var errorMessage = possibleParents.Count == 0 ? "Failed to inherit Increment branch configuration, no branches found." - : "Failed to inherit Increment branch configuration, ended up with: " + string.Join(", ", possibleParents.Select(p => p.Name.Friendly)); + : "Failed to inherit Increment branch configuration, ended up with: " + string.Join(", ", possibleParents.Select(p => p.ToString())); var chosenBranch = repositoryMetadataProvider.GetChosenBranch(configuration); if (chosenBranch == null) @@ -204,7 +204,7 @@ private IBranch[] CalculateWhenMultipleParents(ICommit currentCommit, ref IBranc } } - log.Info("HEAD is merge commit, this is likely a pull request using " + currentBranch.Name.Friendly + " as base"); + log.Info($"HEAD is merge commit, this is likely a pull request using {currentBranch} as base"); return excludedBranches; } diff --git a/src/GitVersionCore/Core/GitPreparer.cs b/src/GitVersionCore/Core/GitPreparer.cs index c87fa99b05..1954b7947c 100644 --- a/src/GitVersionCore/Core/GitPreparer.cs +++ b/src/GitVersionCore/Core/GitPreparer.cs @@ -244,7 +244,7 @@ private void NormalizeGitDirectory(string gitDirectory, bool noFetch, string cur } else { - log.Info($"Checking out local branch 'refs/heads/{localBranchesWhereCommitShaIsHead[0].Name.Friendly}'."); + log.Info($"Checking out local branch 'refs/heads/{localBranchesWhereCommitShaIsHead[0]}'."); repository.Checkout(repository.Branches[localBranchesWhereCommitShaIsHead[0].Name.Friendly]); } } @@ -346,7 +346,7 @@ private static void EnsureLocalBranchExistsForCurrentBranch(IGitRepository repo, } else { - log.Info(isBranch ? $"Updating local branch {localCanonicalName} to point at {repoTip.Sha}" + log.Info(isBranch ? $"Updating local branch {localCanonicalName} to point at {repoTip}" : $"Updating local branch {localCanonicalName} to match ref {currentBranch}"); var localRef = repo.Refs[localCanonicalName]; repo.Refs.UpdateTarget(localRef, repoTipId); diff --git a/src/GitVersionCore/Core/RepositoryMetadataProvider.cs b/src/GitVersionCore/Core/RepositoryMetadataProvider.cs index 190d3c6749..874d45cdd9 100644 --- a/src/GitVersionCore/Core/RepositoryMetadataProvider.cs +++ b/src/GitVersionCore/Core/RepositoryMetadataProvider.cs @@ -36,11 +36,11 @@ public ICommit FindMergeBase(IBranch branch, IBranch otherBranch) if (mergeBaseCache.ContainsKey(key)) { - log.Debug($"Cache hit for merge base between '{branch.Name.Friendly}' and '{otherBranch.Name.Friendly}'."); + log.Debug($"Cache hit for merge base between '{branch}' and '{otherBranch}'."); return mergeBaseCache[key].MergeBase; } - using (log.IndentLog($"Finding merge base between '{branch.Name.Friendly}' and '{otherBranch.Name.Friendly}'.")) + using (log.IndentLog($"Finding merge base between '{branch}' and '{otherBranch}'.")) { // Otherbranch tip is a forward merge var commitToFindCommonBase = otherBranch.Tip; @@ -53,7 +53,7 @@ public ICommit FindMergeBase(IBranch branch, IBranch otherBranch) var findMergeBase = repository.FindMergeBase(commit, commitToFindCommonBase); if (findMergeBase != null) { - log.Info($"Found merge base of {findMergeBase.Sha}"); + log.Info($"Found merge base of {findMergeBase}"); // We do not want to include merge base commits which got forward merged into the other branch ICommit forwardMerge; do @@ -65,7 +65,7 @@ public ICommit FindMergeBase(IBranch branch, IBranch otherBranch) { // TODO Fix the logging up in this section var second = forwardMerge.Parents.First(); - log.Debug("Second " + second.Sha); + log.Debug($"Second {second}"); var mergeBase = repository.FindMergeBase(commit, second); if (mergeBase == null) { @@ -73,7 +73,7 @@ public ICommit FindMergeBase(IBranch branch, IBranch otherBranch) } else { - log.Debug("New Merge base " + mergeBase.Sha); + log.Debug($"New Merge base {mergeBase}"); } if (Equals(mergeBase, findMergeBase)) { @@ -90,7 +90,7 @@ public ICommit FindMergeBase(IBranch branch, IBranch otherBranch) // Store in cache. mergeBaseCache.Add(key, new MergeBaseData(findMergeBase)); - log.Info($"Merge base of {branch.Name.Friendly}' and '{otherBranch.Name.Friendly} is {findMergeBase}"); + log.Info($"Merge base of {branch}' and '{otherBranch} is {findMergeBase}"); return findMergeBase; } } @@ -240,7 +240,7 @@ public IEnumerable GetBranchesContainingCommit(ICommit commit, IEnumera } directBranchHasBeenFound = true; - log.Info($"Direct branch found: '{branch.Name.Friendly}'."); + log.Info($"Direct branch found: '{branch}'."); yield return branch; } @@ -252,17 +252,17 @@ public IEnumerable GetBranchesContainingCommit(ICommit commit, IEnumera log.Info($"No direct branches found, searching through {(onlyTrackedBranches ? "tracked" : "all")} branches."); foreach (var branch in branchList.Where(b => IncludeTrackedBranches(b, onlyTrackedBranches))) { - log.Info($"Searching for commits reachable from '{branch.Name.Friendly}'."); + log.Info($"Searching for commits reachable from '{branch}'."); var commits = repository.GetCommitsReacheableFrom(commit, branch); if (!commits.Any()) { - log.Info($"The branch '{branch.Name.Friendly}' has no matching commits."); + log.Info($"The branch '{branch}' has no matching commits."); continue; } - log.Info($"The branch '{branch.Name.Friendly}' has a matching commit."); + log.Info($"The branch '{branch}' has a matching commit."); yield return branch; } } @@ -296,11 +296,11 @@ public BranchCommit FindCommitBranchWasBranchedFrom(IBranch branch, Config confi throw new ArgumentNullException(nameof(branch)); } - using (log.IndentLog($"Finding branch source of '{branch.Name.Friendly}'")) + using (log.IndentLog($"Finding branch source of '{branch}'")) { if (branch.Tip == null) { - log.Warning(string.Format(MissingTipFormat, branch.Name.Friendly)); + log.Warning(string.Format(MissingTipFormat, branch)); return BranchCommit.Empty; } @@ -311,9 +311,9 @@ public BranchCommit FindCommitBranchWasBranchedFrom(IBranch branch, Config confi if (possibleBranches.Count > 1) { var first = possibleBranches.First(); - log.Info($"Multiple source branches have been found, picking the first one ({first.Branch.Name.Friendly}).{System.Environment.NewLine}" + + log.Info($"Multiple source branches have been found, picking the first one ({first.Branch}).{System.Environment.NewLine}" + $"This may result in incorrect commit counting.{System.Environment.NewLine}Options were:{System.Environment.NewLine}" + - string.Join(", ", possibleBranches.Select(b => b.Branch.Name.Friendly))); + string.Join(", ", possibleBranches.Select(b => b.Branch.ToString()))); return first; } @@ -429,7 +429,7 @@ private IEnumerable GetMergeCommitsForBranch(IBranch branch, Confi { if (otherBranch.Tip == null) { - log.Warning(string.Format(MissingTipFormat, otherBranch.Name.Friendly)); + log.Warning(string.Format(MissingTipFormat, otherBranch)); return BranchCommit.Empty; } diff --git a/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/MergeMessageVersionStrategy.cs b/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/MergeMessageVersionStrategy.cs index 42cd2ba844..ea07d17f4e 100644 --- a/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/MergeMessageVersionStrategy.cs +++ b/src/GitVersionCore/VersionCalculation/BaseVersionCalculators/MergeMessageVersionStrategy.cs @@ -32,7 +32,7 @@ public override IEnumerable GetVersions() mergeMessage.Version != null && Context.FullConfiguration.IsReleaseBranch(TrimRemote(mergeMessage.MergedBranch))) { - log.Info($"Found commit [{Context.CurrentCommit.Sha}] matching merge message format: {mergeMessage.FormatName}"); + log.Info($"Found commit [{Context.CurrentCommit}] matching merge message format: {mergeMessage.FormatName}"); var shouldIncrement = !Context.Configuration.PreventIncrementForMergedBranchVersion; return new[] { diff --git a/src/GitVersionCore/VersionCalculation/MainlineVersionCalculator.cs b/src/GitVersionCore/VersionCalculation/MainlineVersionCalculator.cs index be3c131a89..f23cf57d08 100644 --- a/src/GitVersionCore/VersionCalculation/MainlineVersionCalculator.cs +++ b/src/GitVersionCore/VersionCalculation/MainlineVersionCalculator.cs @@ -46,7 +46,7 @@ public SemanticVersion FindMainlineModeVersion(BaseVersion baseVersion) if (!context.CurrentBranch.Equals(mainline)) { mergeBase = FindMergeBaseBeforeForwardMerge(baseVersion.BaseVersionSource, mainline, out mainlineTip); - log.Info($"Current branch ({context.CurrentBranch.Name.Friendly}) was branch from {mergeBase}"); + log.Info($"Current branch ({context.CurrentBranch}) was branch from {mergeBase}"); } var mainlineCommitLog = repositoryMetadataProvider.GetMainlineCommitLog(baseVersion.BaseVersionSource, mainlineTip).ToList(); @@ -87,7 +87,7 @@ public SemanticVersionBuildMetaData CreateVersionBuildMetaData(ICommit baseVersi { var commitLog = repositoryMetadataProvider.GetCommitLog(baseVersionSource, context.CurrentCommit); var commitsSinceTag = commitLog.Count(); - log.Info($"{commitsSinceTag} commits found between {baseVersionSource.Sha} and {context.CurrentCommit.Sha}"); + log.Info($"{commitsSinceTag} commits found between {baseVersionSource} and {context.CurrentCommit}"); var shortSha = repositoryMetadataProvider.ShortenObjectId(context.CurrentCommit); return new SemanticVersionBuildMetaData( @@ -116,7 +116,7 @@ private SemanticVersion AggregateMergeCommitIncrement(ICommit commit, List b.Name.Friendly))}) have the same merge base for the current branch, choosing {chosenMainline.Name.Friendly} because we found that branch first..."); + log.Info($"Multiple mainlines ({string.Join(", ", possibleMainlineBranches.Select(b => b))}) have the same merge base for the current branch, choosing {chosenMainline} because we found that branch first..."); return chosenMainline; } @@ -231,7 +231,7 @@ private SemanticVersion IncrementForEachCommit(IEnumerable directCommit var directCommitIncrement = IncrementStrategyFinder.GetIncrementForCommits(context, new[] { directCommit }) ?? FindDefaultIncrementForBranch(context, mainline.Name.Friendly); mainlineVersion = mainlineVersion.IncrementVersion(directCommitIncrement); - log.Info($"Direct commit on master {directCommit.Sha} incremented base versions {directCommitIncrement}, now {mainlineVersion}"); + log.Info($"Direct commit on master {directCommit} incremented base versions {directCommitIncrement}, now {mainlineVersion}"); } return mainlineVersion; diff --git a/src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs b/src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs index b78d70e410..a2c4f7621b 100644 --- a/src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs +++ b/src/GitVersionCore/VersionCalculation/NextVersionCalculator.cs @@ -29,7 +29,7 @@ public class NextVersionCalculator : INextVersionCalculator public SemanticVersion FindVersion() { - log.Info($"Running against branch: {context.CurrentBranch.Name.Friendly} ({(context.CurrentCommit == null ? "-" : context.CurrentCommit.Sha)})"); + log.Info($"Running against branch: {context.CurrentBranch} ({(context.CurrentCommit != null ? context.CurrentCommit.ToString() : "-")})"); if (context.IsCurrentCommitTagged) { log.Info($"Current commit is tagged with version {context.CurrentCommitTaggedVersion}, " + diff --git a/src/GitVersionCore/VersionCalculation/ShaVersionFilter.cs b/src/GitVersionCore/VersionCalculation/ShaVersionFilter.cs index 4534c1a882..56cd4d93c1 100644 --- a/src/GitVersionCore/VersionCalculation/ShaVersionFilter.cs +++ b/src/GitVersionCore/VersionCalculation/ShaVersionFilter.cs @@ -22,7 +22,7 @@ public bool Exclude(BaseVersion version, out string reason) if (version.BaseVersionSource != null && shas.Any(sha => version.BaseVersionSource.Sha.StartsWith(sha, StringComparison.OrdinalIgnoreCase))) { - reason = $"Sha {version.BaseVersionSource.Sha} was ignored due to commit having been excluded by configuration"; + reason = $"Sha {version.BaseVersionSource} was ignored due to commit having been excluded by configuration"; return true; }