Skip to content

Commit 743094f

Browse files
Enrique Raso BarberoEnrique Raso Barbero
authored andcommitted
Fix issue with pullrequests on remotes. PullRequest not well detected and Remotes not well replaced.
1 parent bc9c9d0 commit 743094f

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/GitVersion.Core/Git/ReferenceName.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class ReferenceName : IEquatable<ReferenceName?>, IComparable<ReferenceNa
1313
private const string TagPrefix = "refs/tags/";
1414
private const string PullRequestPrefix1 = "refs/pull/";
1515
private const string PullRequestPrefix2 = "refs/pull-requests/";
16+
private const string RemotePullRequestPrefix1 = "refs/remotes/pull/";
17+
private const string RemotePullRequestPrefix2 = "refs/remotes/pull-requests/";
1618

1719
public ReferenceName(string canonical)
1820
{
@@ -23,7 +25,10 @@ public ReferenceName(string canonical)
2325
IsBranch = IsPrefixedBy(Canonical, LocalBranchPrefix);
2426
IsRemoteBranch = IsPrefixedBy(Canonical, RemoteTrackingBranchPrefix);
2527
IsTag = IsPrefixedBy(Canonical, TagPrefix);
26-
IsPullRequest = IsPrefixedBy(Canonical, PullRequestPrefix1) || IsPrefixedBy(Canonical, PullRequestPrefix2);
28+
IsPullRequest = IsPrefixedBy(Canonical, PullRequestPrefix1)
29+
|| IsPrefixedBy(Canonical, PullRequestPrefix2)
30+
|| IsPrefixedBy(Canonical, RemotePullRequestPrefix1)
31+
|| IsPrefixedBy(Canonical, RemotePullRequestPrefix2);
2732
}
2833

2934
public static ReferenceName Parse(string canonicalName)
@@ -75,9 +80,17 @@ private string RemoveRemote()
7580
{
7681
var isRemote = IsPrefixedBy(Canonical, RemoteTrackingBranchPrefix);
7782

78-
return isRemote
79-
? Friendly.Substring(Friendly.IndexOf("/", StringComparison.Ordinal) + 1)
80-
: Friendly;
83+
if (isRemote)
84+
{
85+
var isPullRequest = IsPrefixedBy(Canonical, RemotePullRequestPrefix1)
86+
|| IsPrefixedBy(Canonical, RemotePullRequestPrefix2);
87+
88+
if (!isPullRequest)
89+
return Friendly.Substring(Friendly.IndexOf("/", StringComparison.Ordinal) + 1);
90+
}
91+
92+
return Friendly;
8193
}
94+
8295
private static bool IsPrefixedBy(string input, string prefix) => input.StartsWith(prefix, StringComparison.Ordinal);
8396
}

0 commit comments

Comments
 (0)