Skip to content

[5.0.0] mainline fails when a single commit #1768

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

Closed
JonCubed opened this issue Aug 8, 2019 · 6 comments
Closed

[5.0.0] mainline fails when a single commit #1768

JonCubed opened this issue Aug 8, 2019 · 6 comments
Labels

Comments

@JonCubed
Copy link
Contributor

JonCubed commented Aug 8, 2019

I've come across this problem quite often for new repos and finally looked into it. When I run GitVersion on a new repo where it uses mainline calculation, GitVersion will crash with an exception

 ERROR [08/08/19 6:09:47:47] An unexpected error occurred:
System.InvalidOperationException: Sequence contains no elements
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at GitVersion.VersionCalculation.MainlineVersionCalculator.FindMergeBaseBeforeForwardMerge(GitVersionContext context, Commit baseVersionSource, Branch mainline, Commit& mainlineTip) in D:\a\1\s\src\GitVersionCore\VersionCalculation\MainlineVersionCalculator.cs:line 218   at GitVersion.VersionCalculation.MainlineVersionCalculator.FindMainlineModeVersion(BaseVersion baseVersion, GitVersionContext context) in D:\a\1\s\src\GitVersionCore\VersionCalculation\MainlineVersionCalculator.cs:line 38
   at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion(GitVersionContext context) in D:\a\1\s\src\GitVersionCore\VersionCalculation\NextVersionCalculator.cs:line 47
   at GitVersion.GitVersionFinder.FindVersion(GitVersionContext context) in D:\a\1\s\src\GitVersionCore\GitVersionFinder.cs:line 24
   at GitVersion.ExecuteCore.<>c__DisplayClass7_0.<ExecuteInternal>b__0(IRepository repo) in D:\a\1\s\src\GitVersionCore\ExecuteCore.cs:line 111
   at GitVersion.GitPreparer.WithRepository[TResult](Func`2 action) in D:\a\1\s\src\GitVersionCore\GitPreparer.cs:line 93
   at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId, Config overrideConfig, Boolean noCache) in D:\a\1\s\src\GitVersionCore\ExecuteCore.cs:line 55
   at GitVersion.SpecifiedArgumentRunner.Run(Arguments arguments, IFileSystem fileSystem) in D:\a\1\s\src\GitVersionExe\SpecifiedArgumentRunner.cs:line 46
   at GitVersion.Program.VerifyArgumentsAndRun() in D:\a\1\s\src\GitVersionExe\Program.cs:line 111

I've trace this back to the following if block with ln223 being the culprit. mergeBase is the current commit and mainlineCommitLog is an empty list but it expects that there are parents commits however it is the first so there are not.

// detect forward merge and rewind mainlineTip to before it
if (mergeBase == context.CurrentCommit && !mainlineCommitLog.Contains(mergeBase))
{
var mainlineTipPrevious = mainlineTip.Parents.First();
var message = $"Detected forward merge at {mainlineTip}; rewinding mainline to previous commit {mainlineTipPrevious}";
Logger.WriteInfo(message);
// re-do mergeBase detection before the forward merge
mergeBase = context.Repository.ObjectDatabase.FindMergeBase(context.CurrentCommit, mainlineTipPrevious);
mainlineTip = GetEffectiveMainlineTip(mainlineCommitLog, mergeBase, mainlineTipPrevious);
}

This can be fixed if the if statement is adjusted to the following

if (mergeBase == context.CurrentCommit && !mainlineCommitLog.Contains(mergeBase) && mainlineTip.Parents.Any())

I am uncertain if this is an acceptable fix, but if it is I am happy to make a pr for it

@stale
Copy link

stale bot commented Nov 6, 2019

This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 6, 2019
@stale stale bot closed this as completed Dec 6, 2019
@asbjornu
Copy link
Member

asbjornu commented Dec 6, 2019

Hi, @JonCubed and sorry for the lack of response leading to your issue being closed by stalebot. We would love a PR that fixes this problem, alongside a RepositoryFixture test that ensures the problem is fixed. 👍

@asbjornu asbjornu reopened this Dec 6, 2019
@stale stale bot removed the stale label Dec 6, 2019
@stale
Copy link

stale bot commented Mar 5, 2020

This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 5, 2020
@stale stale bot closed this as completed Apr 4, 2020
@asbjornu
Copy link
Member

asbjornu commented Apr 4, 2020

Is this still a problem in 5.2.4?

@asbjornu asbjornu reopened this Apr 4, 2020
@stale stale bot removed the stale label Apr 4, 2020
@asbjornu
Copy link
Member

#2318 may help alleviate the exception here and give you the fallback strategy.

@stale
Copy link

stale bot commented Sep 12, 2020

This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 12, 2020
@stale stale bot closed this as completed Oct 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants