Skip to content

Commit ac9bc4f

Browse files
authored
Merge pull request #2859 from ajsmith27/feature/prevent-remote-being-returned-as-source-branch
Feature/Prevent remote being returned as source branch
2 parents c26e27f + bc20f67 commit ac9bc4f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/GitVersion.Core.Tests/Core/RepositoryStoreTests.cs

+16
Original file line numberDiff line numberDiff line change
@@ -217,5 +217,21 @@ public void GetBranchesContainingCommitThrowsDirectlyOnNullCommit()
217217

218218
Assert.Throws<ArgumentNullException>(() => gitRepoMetadataProvider.GetBranchesContainingCommit(null));
219219
}
220+
221+
[Test]
222+
public void FindCommitBranchWasBranchedFromShouldReturnNullIfTheRemoteIsTheOnlySource()
223+
{
224+
using var fixture = new RemoteRepositoryFixture();
225+
fixture.MakeACommit("initial");
226+
227+
var localRepository = fixture.LocalRepositoryFixture.Repository.ToGitRepository();
228+
229+
var gitRepoMetadataProvider = new RepositoryStore(this.log, localRepository, this.incrementStrategyFinder);
230+
231+
var branchedCommit = gitRepoMetadataProvider.FindCommitBranchWasBranchedFrom(localRepository.FindBranch("main"), new Model.Configuration.Config(), Array.Empty<IBranch>());
232+
233+
Assert.IsNull(branchedCommit.Branch);
234+
Assert.IsNull(branchedCommit.Commit);
235+
}
220236
}
221237
}

src/GitVersion.Core/Core/RepositoryStore.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ public BranchCommit FindCommitBranchWasBranchedFrom(IBranch branch, Config confi
321321
}
322322

323323
var possibleBranches = GetMergeCommitsForBranch(branch, configuration, excludedBranches)
324-
.Where(b => !branch.Equals(b.Branch))
324+
.Where(b => !branch.Name.EquivalentTo(b.Branch.Name.WithoutRemote))
325325
.ToList();
326326

327327
if (possibleBranches.Count > 1)

0 commit comments

Comments
 (0)