Skip to content

Commit 3e907dc

Browse files
committed
feat: prune on demand - with respect to git config as default
the project already have global setting that is fully synced with git config. but sometimes there is a need to prune on demand. in these scenarios there is no way to do it via SourceGit and I find myself everytime switch to terminal I also saw there was another PR suggesting a fix for that - but this PR respects the repo config and git config
1 parent 4692df9 commit 3e907dc

5 files changed

Lines changed: 25 additions & 5 deletions

File tree

src/Commands/Fetch.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace SourceGit.Commands
55
{
66
public class Fetch : Command
77
{
8-
public Fetch(string repo, string remote, bool noTags, bool force)
8+
public Fetch(string repo, string remote, bool noTags, bool force, bool prune)
99
{
1010
_remote = remote;
1111

@@ -17,6 +17,8 @@ public Fetch(string repo, string remote, bool noTags, bool force)
1717
builder.Append(noTags ? "--no-tags " : "--tags ");
1818
if (force)
1919
builder.Append("--force ");
20+
if (prune)
21+
builder.Append("--prune ");
2022
builder.Append(remote);
2123

2224
Args = builder.ToString();

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@
386386
<x:String x:Key="Text.Fetch.AllRemotes" xml:space="preserve">Fetch all remotes</x:String>
387387
<x:String x:Key="Text.Fetch.Force" xml:space="preserve">Force override local refs</x:String>
388388
<x:String x:Key="Text.Fetch.NoTags" xml:space="preserve">Fetch without tags</x:String>
389+
<x:String x:Key="Text.Fetch.Prune" xml:space="preserve">Prune deleted branches</x:String>
389390
<x:String x:Key="Text.Fetch.Remote" xml:space="preserve">Remote:</x:String>
390391
<x:String x:Key="Text.Fetch.Title" xml:space="preserve">Fetch Remote Changes</x:String>
391392
<x:String x:Key="Text.FileCM.AssumeUnchanged" xml:space="preserve">Assume unchanged</x:String>

src/ViewModels/AddRemote.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public override async Task<bool> Sure()
105105
.Use(log)
106106
.SetAsync($"remote.{_name}.sshkey", _useSSH ? SSHKey : null);
107107

108-
await new Commands.Fetch(_repo.FullPath, _name, false, false)
108+
await new Commands.Fetch(_repo.FullPath, _name, false, false, false)
109109
.Use(log)
110110
.RunAsync();
111111
}

src/ViewModels/Fetch.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ public bool Force
4343
set => _repo.Settings.EnableForceOnFetch = value;
4444
}
4545

46+
public bool Prune
47+
{
48+
get => _prune;
49+
set => SetProperty(ref _prune, value);
50+
}
51+
4652
public Fetch(Repository repo, Models.Remote preferredRemote = null)
4753
{
4854
_repo = repo;
@@ -62,6 +68,10 @@ public Fetch(Repository repo, Models.Remote preferredRemote = null)
6268
{
6369
SelectedRemote = _repo.Remotes[0];
6470
}
71+
72+
// Initialize prune from git config
73+
var pruneConfig = new Commands.Config(_repo.FullPath).Get("fetch.prune");
74+
_prune = pruneConfig == "true";
6575
}
6676

6777
public override async Task<bool> Sure()
@@ -71,19 +81,20 @@ public override async Task<bool> Sure()
7181
var navigateToUpstreamHEAD = _repo.SelectedView is Histories { AutoSelectedCommit: { IsCurrentHead: true } };
7282
var notags = _repo.Settings.FetchWithoutTags;
7383
var force = _repo.Settings.EnableForceOnFetch;
84+
var prune = Prune;
7485
var log = _repo.CreateLog("Fetch");
7586
Use(log);
7687

7788
if (FetchAllRemotes)
7889
{
7990
foreach (var remote in _repo.Remotes)
80-
await new Commands.Fetch(_repo.FullPath, remote.Name, notags, force)
91+
await new Commands.Fetch(_repo.FullPath, remote.Name, notags, force, prune)
8192
.Use(log)
8293
.RunAsync();
8394
}
8495
else
8596
{
86-
await new Commands.Fetch(_repo.FullPath, SelectedRemote.Name, notags, force)
97+
await new Commands.Fetch(_repo.FullPath, SelectedRemote.Name, notags, force, prune)
8798
.Use(log)
8899
.RunAsync();
89100
}
@@ -106,5 +117,6 @@ public override async Task<bool> Sure()
106117

107118
private readonly Repository _repo = null;
108119
private bool _fetchAllRemotes = false;
120+
private bool _prune = false;
109121
}
110122
}

src/Views/Fetch.axaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Text="{DynamicResource Text.Fetch.Title}"/>
1919
</StackPanel>
2020

21-
<Grid Margin="0,16,0,0" RowDefinitions="32,32,Auto,32" ColumnDefinitions="120,*">
21+
<Grid Margin="0,16,0,0" RowDefinitions="32,32,Auto,32,32" ColumnDefinitions="120,*">
2222
<TextBlock Grid.Row="0" Grid.Column="0"
2323
HorizontalAlignment="Right" VerticalAlignment="Center"
2424
Margin="0,0,8,0"
@@ -60,6 +60,11 @@
6060
Content="{DynamicResource Text.Fetch.NoTags}"
6161
IsChecked="{Binding NoTags, Mode=TwoWay}"
6262
ToolTip.Tip="--no-tags"/>
63+
64+
<CheckBox Grid.Row="4" Grid.Column="1"
65+
Content="{DynamicResource Text.Fetch.Prune}"
66+
IsChecked="{Binding Prune, Mode=TwoWay}"
67+
ToolTip.Tip="--prune"/>
6368
</Grid>
6469
</StackPanel>
6570
</UserControl>

0 commit comments

Comments
 (0)