Skip to content

Commit 6df67f6

Browse files
committed
feat: Add option to prefer HTTP over HTTPS for visit URLs
- Add an option to prefer HTTP over HTTPS when generating visit URLs for remote repositories. - Add a property to prefer HTTP when visiting repositories. - Add a preference option to prefer HTTP when generating visit URLs. - Add a preference option to prioritize using HTTP when accessing URLs. - Add a new localization entry for preferring HTTP over HTTPS when accessing URLs. - Set remote preferences to use HTTP when visiting based on user settings. - Add a setting to prefer HTTP when visiting repositories. - Add a new checkbox for preferring HTTP when visiting repositories and adjust the grid layout to accommodate it.
1 parent 9ac6afa commit 6df67f6

File tree

9 files changed

+40
-3
lines changed

9 files changed

+40
-3
lines changed

src/Models/Remote.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public partial class Remote
3131

3232
public string Name { get; set; }
3333
public string URL { get; set; }
34+
public bool PreferHttpWhenVisit { get; set; }
3435

3536
public static bool IsSSH(string url)
3637
{
@@ -78,7 +79,8 @@ public bool TryGetVisitURL(out string url)
7879
var match = REG_TO_VISIT_URL_CAPTURE().Match(URL);
7980
if (match.Success)
8081
{
81-
url = $"https://{match.Groups[1].Value}/{match.Groups[2].Value}";
82+
var scheme = PreferHttpWhenVisit ? "http" : "https";
83+
url = $"{scheme}://{match.Groups[1].Value}/{match.Groups[2].Value}";
8284
return true;
8385
}
8486

src/Models/RepositorySettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ public string ConventionalTypesOverride
233233
set;
234234
} = string.Empty;
235235

236+
public bool PreferHttpWhenVisit
237+
{
238+
get;
239+
set;
240+
} = false;
241+
236242
public void PushCommitMessage(string message)
237243
{
238244
message = message.Trim().ReplaceLineEndings("\n");

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@
619619
<x:String x:Key="Text.Preferences.Git.IgnoreCRAtEOLInDiff" xml:space="preserve">Enable --ignore-cr-at-eol in diff</x:String>
620620
<x:String x:Key="Text.Preferences.Git.Invalid" xml:space="preserve">Git (&gt;= 2.25.1) is required by this app</x:String>
621621
<x:String x:Key="Text.Preferences.Git.Path" xml:space="preserve">Install Path</x:String>
622+
<x:String x:Key="Text.Preferences.Git.PreferHttpWhenVisit" xml:space="preserve">Prefer HTTP when generating visit URLs</x:String>
622623
<x:String x:Key="Text.Preferences.Git.SSLVerify" xml:space="preserve">Enable HTTP SSL Verify</x:String>
623624
<x:String x:Key="Text.Preferences.Git.UseLibsecret" xml:space="preserve">Use git-credential-libsecret instead of git-credential-manager</x:String>
624625
<x:String x:Key="Text.Preferences.Git.User" xml:space="preserve">User Name</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@
623623
<x:String x:Key="Text.Preferences.Git.IgnoreCRAtEOLInDiff" xml:space="preserve">对比文件时,默认忽略换行符变更 (--ignore-cr-at-eol)</x:String>
624624
<x:String x:Key="Text.Preferences.Git.Invalid" xml:space="preserve">本软件要求GIT最低版本为2.25.1</x:String>
625625
<x:String x:Key="Text.Preferences.Git.Path" xml:space="preserve">安装路径</x:String>
626+
<x:String x:Key="Text.Preferences.Git.PreferHttpWhenVisit" xml:space="preserve">访问URL时优先使用HTTP</x:String>
626627
<x:String x:Key="Text.Preferences.Git.SSLVerify" xml:space="preserve">启用HTTP SSL验证</x:String>
627628
<x:String x:Key="Text.Preferences.Git.UseLibsecret" xml:space="preserve">使用 git-credential-libsecret 替代 git-credential-manager</x:String>
628629
<x:String x:Key="Text.Preferences.Git.User" xml:space="preserve">用户名</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@
623623
<x:String x:Key="Text.Preferences.Git.IgnoreCRAtEOLInDiff" xml:space="preserve">對比檔案時,預設忽略行末的 CR 變更 (--ignore-cr-at-eol)</x:String>
624624
<x:String x:Key="Text.Preferences.Git.Invalid" xml:space="preserve">本軟體要求 Git 最低版本為 2.25.1</x:String>
625625
<x:String x:Key="Text.Preferences.Git.Path" xml:space="preserve">安裝路徑</x:String>
626+
<x:String x:Key="Text.Preferences.Git.PreferHttpWhenVisit" xml:space="preserve">訪問URL時優先使用HTTP</x:String>
626627
<x:String x:Key="Text.Preferences.Git.SSLVerify" xml:space="preserve">啟用 HTTP SSL 驗證</x:String>
627628
<x:String x:Key="Text.Preferences.Git.UseLibsecret" xml:space="preserve">使用 git-credential-libsecret 取代 git-credential-manager</x:String>
628629
<x:String x:Key="Text.Preferences.Git.User" xml:space="preserve">使用者名稱</x:String>

src/ViewModels/CommitDetail.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ public CommitDetail(Repository repo, CommitDetailSharedData sharedData)
172172
{
173173
_repo = repo;
174174
_sharedData = sharedData ?? new CommitDetailSharedData();
175+
176+
foreach (var r in repo.Remotes)
177+
r.PreferHttpWhenVisit = repo.Settings.PreferHttpWhenVisit;
178+
175179
WebLinks = Models.CommitLink.Get(repo.Remotes);
176180
}
177181

src/ViewModels/Repository.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,11 @@ public void RefreshBranches()
10911091
var remotes = await new Commands.QueryRemotes(FullPath).GetResultAsync().ConfigureAwait(false);
10921092
var builder = BuildBranchTree(branches, remotes);
10931093

1094+
foreach (var r in remotes)
1095+
{
1096+
r.PreferHttpWhenVisit = _settings.PreferHttpWhenVisit;
1097+
}
1098+
10941099
Dispatcher.UIThread.Invoke(() =>
10951100
{
10961101
if (token.IsCancellationRequested)

src/ViewModels/RepositoryConfigure.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,19 @@ public bool EnableAutoFetch
101101
set => _repo.Settings.EnableAutoFetch = value;
102102
}
103103

104+
public bool PreferHttpWhenVisit
105+
{
106+
get => _repo.Settings.PreferHttpWhenVisit;
107+
set
108+
{
109+
if (_repo.Settings.PreferHttpWhenVisit != value)
110+
{
111+
_repo.Settings.PreferHttpWhenVisit = value;
112+
OnPropertyChanged();
113+
}
114+
}
115+
}
116+
104117
public int? AutoFetchInterval
105118
{
106119
get => _repo.Settings.AutoFetchInterval;

src/Views/RepositoryConfigure.axaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<TextBlock Classes="tab_header" Text="{DynamicResource Text.Configure.Git}"/>
4545
</TabItem.Header>
4646

47-
<Grid Margin="16,4,16,8" RowDefinitions="32,32,32,32,32,32,32,32,32,32,32" ColumnDefinitions="Auto,*">
47+
<Grid Margin="16,4,16,8" RowDefinitions="32,32,32,32,32,32,32,32,32,32,32,32" ColumnDefinitions="Auto,*">
4848
<TextBlock Grid.Row="0" Grid.Column="0"
4949
HorizontalAlignment="Right" VerticalAlignment="Center"
5050
Margin="0,0,8,0"
@@ -174,7 +174,11 @@
174174
Content="{DynamicResource Text.Preferences.Git.EnablePruneOnFetch}"
175175
IsChecked="{Binding EnablePruneOnFetch, Mode=TwoWay}"/>
176176

177-
<StackPanel Grid.Row="10" Grid.Column="1" Orientation="Horizontal">
177+
<CheckBox Grid.Row="10" Grid.Column="1"
178+
Content="{DynamicResource Text.Preferences.Git.PreferHttpWhenVisit}"
179+
IsChecked="{Binding PreferHttpWhenVisit, Mode=TwoWay}"/>
180+
181+
<StackPanel Grid.Row="11" Grid.Column="1" Orientation="Horizontal">
178182
<CheckBox x:Name="AutoFetchCheckBox"
179183
Content="{DynamicResource Text.Configure.Git.AutoFetch}"
180184
IsChecked="{Binding EnableAutoFetch, Mode=TwoWay}"/>

0 commit comments

Comments
 (0)