Skip to content

Commit 153a1f3

Browse files
committed
feature: supports toggle --force option for git fetch command (#721)
* Background auto fetch will always disable this option * This option is not add to pull operation Signed-off-by: leo <[email protected]>
1 parent c1c743f commit 153a1f3

File tree

9 files changed

+26
-7
lines changed

9 files changed

+26
-7
lines changed

src/Commands/Fetch.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace SourceGit.Commands
44
{
55
public class Fetch : Command
66
{
7-
public Fetch(string repo, string remote, bool noTags, bool prune, Action<string> outputHandler)
7+
public Fetch(string repo, string remote, bool noTags, bool prune, bool force, Action<string> outputHandler)
88
{
99
_outputHandler = outputHandler;
1010
WorkingDirectory = repo;
@@ -18,6 +18,9 @@ public Fetch(string repo, string remote, bool noTags, bool prune, Action<string>
1818
else
1919
Args += "--tags ";
2020

21+
if (force)
22+
Args += "--force ";
23+
2124
if (prune)
2225
Args += "--prune ";
2326

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@
268268
<x:String x:Key="Text.FastForwardWithoutCheck" xml:space="preserve">Fast-Forward (without checkout)</x:String>
269269
<x:String x:Key="Text.Fetch" xml:space="preserve">Fetch</x:String>
270270
<x:String x:Key="Text.Fetch.AllRemotes" xml:space="preserve">Fetch all remotes</x:String>
271+
<x:String x:Key="Text.Fetch.Force" xml:space="preserve">Enable '--force' option</x:String>
271272
<x:String x:Key="Text.Fetch.NoTags" xml:space="preserve">Fetch without tags</x:String>
272273
<x:String x:Key="Text.Fetch.Remote" xml:space="preserve">Remote:</x:String>
273274
<x:String x:Key="Text.Fetch.Title" xml:space="preserve">Fetch Remote Changes</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@
271271
<x:String x:Key="Text.FastForwardWithoutCheck" xml:space="preserve">快进(fast-forward,无需checkout)</x:String>
272272
<x:String x:Key="Text.Fetch" xml:space="preserve">拉取(fetch)</x:String>
273273
<x:String x:Key="Text.Fetch.AllRemotes" xml:space="preserve">拉取所有的远程仓库</x:String>
274+
<x:String x:Key="Text.Fetch.Force" xml:space="preserve">启用 --force 选项</x:String>
274275
<x:String x:Key="Text.Fetch.NoTags" xml:space="preserve">不拉取远程标签</x:String>
275276
<x:String x:Key="Text.Fetch.Remote" xml:space="preserve">远程仓库 :</x:String>
276277
<x:String x:Key="Text.Fetch.Title" 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
@@ -271,6 +271,7 @@
271271
<x:String x:Key="Text.FastForwardWithoutCheck" xml:space="preserve">快進 (fast-forward,無需 checkout)</x:String>
272272
<x:String x:Key="Text.Fetch" xml:space="preserve">提取 (fetch)</x:String>
273273
<x:String x:Key="Text.Fetch.AllRemotes" xml:space="preserve">提取所有的遠端存放庫</x:String>
274+
<x:String x:Key="Text.Fetch.Force" xml:space="preserve">啟用 [--force] 選項</x:String>
274275
<x:String x:Key="Text.Fetch.NoTags" xml:space="preserve">不提取遠端標籤</x:String>
275276
<x:String x:Key="Text.Fetch.Remote" xml:space="preserve">遠端存放庫:</x:String>
276277
<x:String x:Key="Text.Fetch.Title" xml:space="preserve">提取遠端存放庫內容</x:String>

src/ViewModels/AddRemote.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public override Task<bool> Sure()
100100
{
101101
SetProgressDescription("Fetching from added remote ...");
102102
new Commands.Config(_repo.FullPath).Set($"remote.{_name}.sshkey", _useSSH ? SSHKey : null);
103-
new Commands.Fetch(_repo.FullPath, _name, false, false, SetProgressDescription).Exec();
103+
new Commands.Fetch(_repo.FullPath, _name, false, false, false, SetProgressDescription).Exec();
104104
}
105105
CallUIThread(() =>
106106
{

src/ViewModels/Fetch.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,17 @@ public bool NoTags
2828
set => _repo.Settings.FetchWithoutTags = value;
2929
}
3030

31+
public bool Force
32+
{
33+
get;
34+
set;
35+
}
36+
3137
public Fetch(Repository repo, Models.Remote preferedRemote = null)
3238
{
3339
_repo = repo;
3440
_fetchAllRemotes = preferedRemote == null;
41+
Force = false;
3542
SelectedRemote = preferedRemote != null ? preferedRemote : _repo.Remotes[0];
3643
View = new Views.Fetch() { DataContext = this };
3744
}
@@ -42,20 +49,21 @@ public override Task<bool> Sure()
4249

4350
var notags = _repo.Settings.FetchWithoutTags;
4451
var prune = _repo.Settings.EnablePruneOnFetch;
52+
var force = Force;
4553
return Task.Run(() =>
4654
{
4755
if (FetchAllRemotes)
4856
{
4957
foreach (var remote in _repo.Remotes)
5058
{
5159
SetProgressDescription($"Fetching remote: {remote.Name}");
52-
new Commands.Fetch(_repo.FullPath, remote.Name, notags, prune, SetProgressDescription).Exec();
60+
new Commands.Fetch(_repo.FullPath, remote.Name, notags, prune, force, SetProgressDescription).Exec();
5361
}
5462
}
5563
else
5664
{
5765
SetProgressDescription($"Fetching remote: {SelectedRemote.Name}");
58-
new Commands.Fetch(_repo.FullPath, SelectedRemote.Name, notags, prune, SetProgressDescription).Exec();
66+
new Commands.Fetch(_repo.FullPath, SelectedRemote.Name, notags, prune, force, SetProgressDescription).Exec();
5967
}
6068

6169
CallUIThread(() =>

src/ViewModels/Pull.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ public override Task<bool> Sure()
152152
_selectedRemote.Name,
153153
NoTags,
154154
_repo.Settings.EnablePruneOnFetch,
155+
false,
155156
SetProgressDescription).Exec();
156157

157158
if (!rs)

src/ViewModels/Repository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2194,7 +2194,7 @@ private void AutoFetchImpl(object sender)
21942194

21952195
IsAutoFetching = true;
21962196
Dispatcher.UIThread.Invoke(() => OnPropertyChanged(nameof(IsAutoFetching)));
2197-
new Commands.Fetch(_fullpath, "--all", false, _settings.EnablePruneOnFetch, null) { RaiseError = false }.Exec();
2197+
new Commands.Fetch(_fullpath, "--all", false, _settings.EnablePruneOnFetch, false, null) { RaiseError = false }.Exec();
21982198
_lastFetchTime = DateTime.Now;
21992199
IsAutoFetching = false;
22002200
Dispatcher.UIThread.Invoke(() => OnPropertyChanged(nameof(IsAutoFetching)));

src/Views/Fetch.axaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<TextBlock FontSize="18"
1212
Classes="bold"
1313
Text="{DynamicResource Text.Fetch.Title}"/>
14-
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32" ColumnDefinitions="120,*">
14+
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32,32" ColumnDefinitions="120,*">
1515
<TextBlock Grid.Row="0" Grid.Column="0"
1616
HorizontalAlignment="Right" VerticalAlignment="Center"
1717
Margin="0,0,8,0"
@@ -33,10 +33,14 @@
3333
</ComboBox>
3434

3535
<CheckBox Grid.Row="1" Grid.Column="1"
36+
Content="{DynamicResource Text.Fetch.Force}"
37+
IsChecked="{Binding Force, Mode=TwoWay}"/>
38+
39+
<CheckBox Grid.Row="2" Grid.Column="1"
3640
Content="{DynamicResource Text.Fetch.AllRemotes}"
3741
IsChecked="{Binding FetchAllRemotes, Mode=TwoWay}"/>
3842

39-
<CheckBox Grid.Row="2" Grid.Column="1"
43+
<CheckBox Grid.Row="3" Grid.Column="1"
4044
Content="{DynamicResource Text.Fetch.NoTags}"
4145
IsChecked="{Binding NoTags, Mode=TwoWay}"/>
4246
</Grid>

0 commit comments

Comments
 (0)