Skip to content

Commit 31bfa1b

Browse files
feat: Add depth parameter to Fetch and Pull operations (#1605)
Enhanced the Fetch and Pull classes to support a new `depth` parameter for specifying operation depth. Introduced properties in RepositorySettings for managing fetch and pull depth settings. Updated localization files to include new depth-related strings. Modified AddRemote and UI components to accommodate the new depth functionality, allowing user configuration of fetch and pull depth.
1 parent 05dba32 commit 31bfa1b

File tree

10 files changed

+128
-8
lines changed

10 files changed

+128
-8
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 force)
7+
public Fetch(string repo, string remote, bool noTags, bool force, int depth)
88
{
99
_remoteKey = $"remote.{remote}.sshkey";
1010

@@ -20,6 +20,9 @@ public Fetch(string repo, string remote, bool noTags, bool force)
2020
if (force)
2121
Args += "--force ";
2222

23+
if (depth > 0)
24+
Args += $"--depth={depth} ";
25+
2326
Args += remote;
2427

2528
}

src/Commands/Pull.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 Pull : Command
66
{
7-
public Pull(string repo, string remote, string branch, bool useRebase)
7+
public Pull(string repo, string remote, string branch, bool useRebase, int depth)
88
{
99
_remote = remote;
1010

@@ -15,6 +15,9 @@ public Pull(string repo, string remote, string branch, bool useRebase)
1515
if (useRebase)
1616
Args += "--rebase=true ";
1717

18+
if (depth > 0)
19+
Args += $"--depth={depth} ";
20+
1821
Args += $"{remote} {branch}";
1922
}
2023

src/Models/RepositorySettings.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,30 @@ public string LastCommitMessage
230230
set;
231231
} = string.Empty;
232232

233+
public bool EnableFetchDepth
234+
{
235+
get;
236+
set;
237+
} = false;
238+
239+
public int FetchDepthValue
240+
{
241+
get;
242+
set;
243+
} = 1;
244+
245+
public bool EnablePullDepth
246+
{
247+
get;
248+
set;
249+
} = false;
250+
251+
public int PullDepthValue
252+
{
253+
get;
254+
set;
255+
} = 1;
256+
233257
public Dictionary<string, FilterMode> CollectHistoriesFilters()
234258
{
235259
var map = new Dictionary<string, FilterMode>();

src/Resources/Locales/en_US.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@
193193
<x:String x:Key="Text.Configure.Git.AutoFetchIntervalSuffix" xml:space="preserve">Minute(s)</x:String>
194194
<x:String x:Key="Text.Configure.Git.DefaultRemote" xml:space="preserve">Default Remote</x:String>
195195
<x:String x:Key="Text.Configure.Git.PreferredMergeMode" xml:space="preserve">Preferred Merge Mode</x:String>
196+
<x:String x:Key="Text.Configure.Git.FetchDepth" xml:space="preserve">Fetch depth</x:String>
197+
<x:String x:Key="Text.Configure.Git.PullDepth" xml:space="preserve">Pull depth</x:String>
196198
<x:String x:Key="Text.Configure.IssueTracker" xml:space="preserve">ISSUE TRACKER</x:String>
197199
<x:String x:Key="Text.Configure.IssueTracker.AddSampleAzure" xml:space="preserve">Add Azure DevOps Rule</x:String>
198200
<x:String x:Key="Text.Configure.IssueTracker.AddSampleGerritChangeIdCommit" xml:space="preserve">Add Gerrit Change-Id Commit Rule</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, _repo.Settings.EnableFetchDepth ? _repo.Settings.FetchDepthValue : 0)
109109
.Use(log)
110110
.RunAsync();
111111
}

src/ViewModels/Fetch.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,20 @@ public override async Task<bool> Sure()
6060

6161
var notags = _repo.Settings.FetchWithoutTags;
6262
var force = _repo.Settings.EnableForceOnFetch;
63+
var depth = _repo.Settings.EnableFetchDepth ? _repo.Settings.FetchDepthValue : 0;
6364
var log = _repo.CreateLog("Fetch");
6465
Use(log);
6566

6667
if (FetchAllRemotes)
6768
{
6869
foreach (var remote in _repo.Remotes)
69-
await new Commands.Fetch(_repo.FullPath, remote.Name, notags, force)
70+
await new Commands.Fetch(_repo.FullPath, remote.Name, notags, force, depth)
7071
.Use(log)
7172
.RunAsync();
7273
}
7374
else
7475
{
75-
await new Commands.Fetch(_repo.FullPath, SelectedRemote.Name, notags, force)
76+
await new Commands.Fetch(_repo.FullPath, SelectedRemote.Name, notags, force, depth)
7677
.Use(log)
7778
.RunAsync();
7879
}

src/ViewModels/Pull.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ public override async Task<bool> Sure()
145145
_repo.FullPath,
146146
_selectedRemote.Name,
147147
!string.IsNullOrEmpty(Current.Upstream) && Current.Upstream.Equals(_selectedBranch.FullName) ? string.Empty : _selectedBranch.Name,
148-
UseRebase).Use(log).RunAsync();
148+
UseRebase,
149+
_repo.Settings.EnablePullDepth ? _repo.Settings.PullDepthValue : 0).Use(log).RunAsync();
149150
if (rs)
150151
{
151152
if (updateSubmodules)

src/ViewModels/Repository.cs

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

31393139
Dispatcher.UIThread.Invoke(() => IsAutoFetching = true);
31403140
foreach (var remote in remotes)
3141-
await new Commands.Fetch(_fullpath, remote, false, false) { RaiseError = false }.RunAsync();
3141+
await new Commands.Fetch(_fullpath, remote, false, false, _settings.EnableFetchDepth ? _settings.FetchDepthValue : 0) { RaiseError = false }.RunAsync();
31423142
_lastFetchTime = DateTime.Now;
31433143
Dispatcher.UIThread.Invoke(() => IsAutoFetching = false);
31443144
}

src/ViewModels/RepositoryConfigure.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,58 @@ public int? AutoFetchInterval
101101
}
102102
}
103103

104+
public bool EnableFetchDepth
105+
{
106+
get => _repo.Settings.EnableFetchDepth;
107+
set
108+
{
109+
if (_repo.Settings.EnableFetchDepth != value)
110+
{
111+
_repo.Settings.EnableFetchDepth = value;
112+
OnPropertyChanged();
113+
}
114+
}
115+
}
116+
117+
public int FetchDepthValue
118+
{
119+
get => _repo.Settings.FetchDepthValue;
120+
set
121+
{
122+
if (_repo.Settings.FetchDepthValue != value)
123+
{
124+
_repo.Settings.FetchDepthValue = value;
125+
OnPropertyChanged();
126+
}
127+
}
128+
}
129+
130+
public bool EnablePullDepth
131+
{
132+
get => _repo.Settings.EnablePullDepth;
133+
set
134+
{
135+
if (_repo.Settings.EnablePullDepth != value)
136+
{
137+
_repo.Settings.EnablePullDepth = value;
138+
OnPropertyChanged();
139+
}
140+
}
141+
}
142+
143+
public int PullDepthValue
144+
{
145+
get => _repo.Settings.PullDepthValue;
146+
set
147+
{
148+
if (_repo.Settings.PullDepthValue != value)
149+
{
150+
_repo.Settings.PullDepthValue = value;
151+
OnPropertyChanged();
152+
}
153+
}
154+
}
155+
104156
public AvaloniaList<Models.CommitTemplate> CommitTemplates
105157
{
106158
get => _repo.Settings.CommitTemplates;

src/Views/RepositoryConfigure.axaml

Lines changed: 35 additions & 1 deletion
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" 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"
@@ -178,6 +178,40 @@
178178
Margin="5,0,0,0"
179179
Text="{DynamicResource Text.Configure.Git.AutoFetchIntervalSuffix}" />
180180
</StackPanel>
181+
182+
<Grid Grid.Row="10" Grid.Column="1">
183+
<CheckBox x:Name="FetchDepthCheckBox"
184+
Content="{DynamicResource Text.Configure.Git.FetchDepth}"
185+
IsChecked="{Binding EnableFetchDepth, Mode=TwoWay}"/>
186+
187+
<NumericUpDown Minimum="1" Increment="1"
188+
Height="26" Width="220"
189+
Margin="8,0,0,0" Padding="4"
190+
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}"
191+
CornerRadius="3"
192+
ParsingNumberStyle="Integer"
193+
FormatString="0"
194+
Value="{Binding FetchDepthValue, Mode=TwoWay, FallbackValue=1}"
195+
IsEnabled="{Binding #FetchDepthCheckBox.IsChecked}"
196+
HorizontalAlignment="Right"/>
197+
</Grid>
198+
199+
<Grid Grid.Row="11" Grid.Column="1">
200+
<CheckBox x:Name="PullDepthCheckBox"
201+
Content="{DynamicResource Text.Configure.Git.PullDepth}"
202+
IsChecked="{Binding EnablePullDepth, Mode=TwoWay}"/>
203+
204+
<NumericUpDown Minimum="1" Increment="1"
205+
Height="26" Width="220"
206+
Margin="8,0,0,0" Padding="4"
207+
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}"
208+
CornerRadius="3"
209+
ParsingNumberStyle="Integer"
210+
FormatString="0"
211+
Value="{Binding PullDepthValue, Mode=TwoWay, FallbackValue=1}"
212+
IsEnabled="{Binding #PullDepthCheckBox.IsChecked}"
213+
HorizontalAlignment="Right"/>
214+
</Grid>
181215
</Grid>
182216
</TabItem>
183217

0 commit comments

Comments
 (0)