Skip to content

Commit

Permalink
Fix detection of branch name when remote (bis)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Feb 27, 2022
1 parent 6b22cc9 commit 45c8cdd
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/dotnet-releaser/GitInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace DotNetReleaser;

public class GitInformation
{
private GitInformation(Repository repository, Branch branch)
private GitInformation(Repository repository, Branch branch, string branchName)
{
Repository = repository;
Head = repository.Head.Tip;
Branch = branch;
BranchName = GetShortBranchName(branch);
BranchName = branchName;
}

public Repository Repository { get; }
Expand All @@ -34,8 +34,8 @@ private GitInformation(Repository repository, Branch branch)

var repository = new Repository(repositoryPath);

var branchesFound = repository.Branches.Where(branch => branch.Tip != null && branch.Tip.Sha == repository.Head.Tip.Sha).ToList();
var branchNamesFound = branchesFound.Select(GetShortBranchName).ToList();
var branchesFound = repository.Branches.Where(branch => branch.Tip != null && branch.Tip.Sha == repository.Head.Tip.Sha).Select(x => (Branch: x, BranchName: GetShortBranchName(x))).ToList();
var branchNamesFound = branchesFound.Select(x => x.BranchName).ToList();

var branchName = branchNamesFound.FirstOrDefault(branches.Contains) ?? branchNamesFound.FirstOrDefault() ?? string.Empty;

Expand All @@ -49,9 +49,9 @@ private GitInformation(Repository repository, Branch branch)
return null;
}

var branch = branchesFound.First(x => x.FriendlyName == branchName);
var branchAndName = branchesFound.First(x => x.BranchName == branchName);

return new GitInformation(repository, branch);
return new GitInformation(repository, branchAndName.Branch, branchAndName.BranchName);
}

private static string GetShortBranchName(Branch branch)
Expand Down

0 comments on commit 45c8cdd

Please sign in to comment.