Skip to content

Commit a8e244e

Browse files
committed
fix: Default branch name not using PAT
1 parent bb49d2a commit a8e244e

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

BananaGit/BananaGit/Services/GitService.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Diagnostics.CodeAnalysis;
33
using System.IO;
44
using System.Windows;
5-
using System.Windows.Threading;
65
using BananaGit.EventArgExtensions;
76
using BananaGit.Exceptions;
87
using BananaGit.Models;
@@ -48,7 +47,7 @@ public GitService(GitInfoModel? gitInfo)
4847
// Attach this service to the current branch after it's been loaded
4948
_gitInfo?.CurrentBranch?.AttachService(this);
5049

51-
_defaultBranchName = Lib2GitSharpExt.GetDefaultRepoName(_gitInfo?.GetUrl());
50+
_defaultBranchName = Lib2GitSharpExt.GetDefaultRepoName(_gitInfo?.GetUrl(), _gitInfo?.PersonalToken);
5251
}
5352

5453
private bool _hasUserInfoReloaded;
@@ -570,7 +569,7 @@ await Task.Run(() =>
570569
MarkBranchVisible(localName);
571570
});
572571
OnRepositoryChanged?.Invoke(this, EventArgs.Empty);
573-
_defaultBranchName = Lib2GitSharpExt.GetDefaultRepoName(_gitInfo?.GetUrl());
572+
_defaultBranchName = Lib2GitSharpExt.GetDefaultRepoName(_gitInfo?.GetUrl(), _gitInfo?.PersonalToken);
574573
}
575574

576575
/// <summary>
@@ -1183,7 +1182,7 @@ await Task.Run(() =>
11831182

11841183
//Notify view models that the repository data has changed
11851184
OnRepositoryChanged?.Invoke(this, EventArgs.Empty);
1186-
_defaultBranchName = Lib2GitSharpExt.GetDefaultRepoName(_gitInfo?.GetUrl());
1185+
_defaultBranchName = Lib2GitSharpExt.GetDefaultRepoName(_gitInfo?.GetUrl(), _gitInfo?.PersonalToken);
11871186
}
11881187
catch (Exception ex)
11891188
{

BananaGit/BananaGit/Utilities/Lib2GitSharpExt.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ public static class Lib2GitSharpExt
1212
/// Finds the default head branch of a repository
1313
/// </summary>
1414
/// <param name="repoUrl">The repositories URL</param>
15+
/// <param name="token">The PAT</param>
1516
/// <returns>The name of the default branch head</returns>
16-
public static string? GetDefaultRepoName(string? repoUrl)
17+
public static string? GetDefaultRepoName(string? repoUrl, string? token)
1718
{
1819
try
1920
{
@@ -23,10 +24,16 @@ public static class Lib2GitSharpExt
2324
return null;
2425
}
2526

27+
string effectiveUrl = repoUrl;
28+
if (!string.IsNullOrEmpty(token) && repoUrl.StartsWith("https://"))
29+
{
30+
effectiveUrl = repoUrl.Replace("https://", $"https://{token}@");
31+
}
32+
2633
var gitProcessInfo = new ProcessStartInfo
2734
{
2835
FileName = "git",
29-
Arguments = $"ls-remote --symref \"{repoUrl}\" HEAD",
36+
Arguments = $"ls-remote --symref \"{effectiveUrl}\" HEAD",
3037
RedirectStandardOutput = true,
3138
RedirectStandardError = true,
3239
UseShellExecute = false,

0 commit comments

Comments
 (0)