Skip to content

Commit d746e35

Browse files
committed
feature: supports to set default remote to push local branches without any tracking remotes (#534)
1 parent 6d1dfad commit d746e35

File tree

7 files changed

+66
-10
lines changed

7 files changed

+66
-10
lines changed

src/Models/RepositorySettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ namespace SourceGit.Models
44
{
55
public class RepositorySettings
66
{
7+
public string DefaultRemote
8+
{
9+
get;
10+
set;
11+
} = string.Empty;
12+
713
public DealWithLocalChanges DealWithLocalChangesOnCheckoutBranch
814
{
915
get;

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
<x:String x:Key="Text.Configure.Git" xml:space="preserve">GIT</x:String>
139139
<x:String x:Key="Text.Configure.Git.AutoFetch" xml:space="preserve">Fetch remotes automatically</x:String>
140140
<x:String x:Key="Text.Configure.Git.AutoFetchIntervalSuffix" xml:space="preserve">Minute(s)</x:String>
141+
<x:String x:Key="Text.Configure.Git.DefaultRemote" xml:space="preserve">Default Remote</x:String>
141142
<x:String x:Key="Text.Configure.IssueTracker" xml:space="preserve">ISSUE TRACKER</x:String>
142143
<x:String x:Key="Text.Configure.IssueTracker.AddSampleGithub" xml:space="preserve">Add Sample Github Rule</x:String>
143144
<x:String x:Key="Text.Configure.IssueTracker.AddSampleJira" xml:space="preserve">Add Sample Jira Rule</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
<x:String x:Key="Text.Configure.Git" xml:space="preserve">GIT配置</x:String>
142142
<x:String x:Key="Text.Configure.Git.AutoFetch" xml:space="preserve">启用定时自动拉取远程更新</x:String>
143143
<x:String x:Key="Text.Configure.Git.AutoFetchIntervalSuffix" xml:space="preserve">分钟</x:String>
144+
<x:String x:Key="Text.Configure.Git.DefaultRemote" xml:space="preserve">默认远程</x:String>
144145
<x:String x:Key="Text.Configure.IssueTracker" xml:space="preserve">ISSUE追踪</x:String>
145146
<x:String x:Key="Text.Configure.IssueTracker.AddSampleGithub" xml:space="preserve">新增匹配Github Issue规则</x:String>
146147
<x:String x:Key="Text.Configure.IssueTracker.AddSampleJira" xml:space="preserve">新增匹配Jira规则</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
<x:String x:Key="Text.Configure.Git" xml:space="preserve">Git 設定</x:String>
142142
<x:String x:Key="Text.Configure.Git.AutoFetch" xml:space="preserve">啟用定時自動提取 (fetch) 遠端更新</x:String>
143143
<x:String x:Key="Text.Configure.Git.AutoFetchIntervalSuffix" xml:space="preserve">分鐘</x:String>
144+
<x:String x:Key="Text.Configure.Git.DefaultRemote" xml:space="preserve">預設遠端存放庫</x:String>
144145
<x:String x:Key="Text.Configure.IssueTracker" xml:space="preserve">Issue 追蹤</x:String>
145146
<x:String x:Key="Text.Configure.IssueTracker.AddSampleGithub" xml:space="preserve">新增符合 GitHub Issue 規則</x:String>
146147
<x:String x:Key="Text.Configure.IssueTracker.AddSampleJira" xml:space="preserve">新增符合 Jira 規則</x:String>

src/ViewModels/Push.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,15 @@ public Push(Repository repo, Models.Branch localBranch)
137137
}
138138
}
139139

140-
// Set default remote to the first if haven't been set.
140+
// Set default remote to the first if it has not been set.
141141
if (_selectedRemote == null)
142-
_selectedRemote = repo.Remotes[0];
142+
{
143+
var remote = null as Models.Remote;
144+
if (!string.IsNullOrEmpty(_repo.Settings.DefaultRemote))
145+
remote = repo.Remotes.Find(x => x.Name == _repo.Settings.DefaultRemote);
146+
147+
_selectedRemote = remote ?? repo.Remotes[0];
148+
}
143149

144150
// Auto select preferred remote branch.
145151
AutoSelectBranchByRemote();

src/ViewModels/RepositoryConfigure.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,24 @@ public string UserEmail
1818
set;
1919
}
2020

21+
public List<string> Remotes
22+
{
23+
get;
24+
}
25+
26+
public string DefaultRemote
27+
{
28+
get => _repo.Settings.DefaultRemote;
29+
set
30+
{
31+
if (_repo.Settings.DefaultRemote != value)
32+
{
33+
_repo.Settings.DefaultRemote = value;
34+
OnPropertyChanged();
35+
}
36+
}
37+
}
38+
2139
public bool GPGCommitSigningEnabled
2240
{
2341
get;
@@ -88,6 +106,10 @@ public RepositoryConfigure(Repository repo)
88106
{
89107
_repo = repo;
90108

109+
Remotes = new List<string>();
110+
foreach (var remote in _repo.Remotes)
111+
Remotes.Add(remote.Name);
112+
91113
_cached = new Commands.Config(repo.FullPath).ListAll();
92114
if (_cached.TryGetValue("user.name", out var name))
93115
UserName = name;

src/Views/RepositoryConfigure.axaml

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<TextBlock Classes="tab_header" Text="{DynamicResource Text.Configure.Git}"/>
5252
</TabItem.Header>
5353

54-
<Grid Margin="16,4,16,8" RowDefinitions="32,32,32,32,32,32,32" ColumnDefinitions="Auto,*">
54+
<Grid Margin="16,4,16,8" RowDefinitions="32,32,32,32,32,32,32,32" ColumnDefinitions="Auto,*">
5555
<TextBlock Grid.Row="0" Grid.Column="0"
5656
HorizontalAlignment="Right" VerticalAlignment="Center"
5757
Margin="0,0,8,0"
@@ -72,12 +72,31 @@
7272
CornerRadius="3"
7373
Watermark="{DynamicResource Text.Configure.Email.Placeholder}"
7474
Text="{Binding UserEmail, Mode=TwoWay}"/>
75-
75+
7676
<TextBlock Grid.Row="2" Grid.Column="0"
77+
HorizontalAlignment="Right" VerticalAlignment="Center"
78+
Margin="0,0,8,0"
79+
Text="{DynamicResource Text.Configure.Git.DefaultRemote}"/>
80+
<ComboBox Grid.Row="2" Grid.Column="1"
81+
Height="28" Padding="8,0"
82+
VerticalAlignment="Center" HorizontalAlignment="Stretch"
83+
ItemsSource="{Binding Remotes}"
84+
SelectedItem="{Binding DefaultRemote, Mode=TwoWay}">
85+
<ComboBox.ItemTemplate>
86+
<DataTemplate>
87+
<StackPanel Orientation="Horizontal" Height="20" VerticalAlignment="Center">
88+
<Path Margin="0,6,8,0" Width="14" Height="14" Fill="{DynamicResource Brush.FG1}" Data="{StaticResource Icons.Remote}"/>
89+
<TextBlock Text="{Binding}"/>
90+
</StackPanel>
91+
</DataTemplate>
92+
</ComboBox.ItemTemplate>
93+
</ComboBox>
94+
95+
<TextBlock Grid.Row="3" Grid.Column="0"
7796
HorizontalAlignment="Right" VerticalAlignment="Center"
7897
Margin="0,0,8,0"
7998
Text="{DynamicResource Text.Configure.Proxy}"/>
80-
<TextBox Grid.Row="2" Grid.Column="1"
99+
<TextBox Grid.Row="3" Grid.Column="1"
81100
Height="28"
82101
CornerRadius="3"
83102
Watermark="{DynamicResource Text.Configure.Proxy.Placeholder}"
@@ -89,25 +108,25 @@
89108
</TextBox.InnerRightContent>
90109
</TextBox>
91110

92-
<TextBlock Grid.Row="3" Grid.Column="0"
111+
<TextBlock Grid.Row="4" Grid.Column="0"
93112
HorizontalAlignment="Right" VerticalAlignment="Center"
94113
Margin="0,0,8,0"
95114
Text="{DynamicResource Text.Preference.GPG.UserKey}"/>
96-
<TextBox Grid.Row="3" Grid.Column="1"
115+
<TextBox Grid.Row="4" Grid.Column="1"
97116
Height="28"
98117
CornerRadius="3"
99118
Watermark="{DynamicResource Text.Preference.GPG.UserKey.Placeholder}"
100119
Text="{Binding GPGUserSigningKey, Mode=TwoWay}"/>
101120

102-
<CheckBox Grid.Row="4" Grid.Column="1"
121+
<CheckBox Grid.Row="5" Grid.Column="1"
103122
Content="{DynamicResource Text.Preference.GPG.CommitEnabled}"
104123
IsChecked="{Binding GPGCommitSigningEnabled, Mode=TwoWay}"/>
105124

106-
<CheckBox Grid.Row="5" Grid.Column="1"
125+
<CheckBox Grid.Row="6" Grid.Column="1"
107126
Content="{DynamicResource Text.Preference.GPG.TagEnabled}"
108127
IsChecked="{Binding GPGTagSigningEnabled, Mode=TwoWay}"/>
109128

110-
<StackPanel Grid.Row="6" Grid.Column="1" Orientation="Horizontal">
129+
<StackPanel Grid.Row="7" Grid.Column="1" Orientation="Horizontal">
111130
<CheckBox x:Name="AutoFetchCheckBox"
112131
Content="{DynamicResource Text.Configure.Git.AutoFetch}"
113132
IsChecked="{Binding EnableAutoFetch, Mode=TwoWay}"/>

0 commit comments

Comments
 (0)