feat(*): 为 Pull、Fetch、Push 增加 --recurse-submodules 选项参数

This commit is contained in:
ZCShou 2020-07-24 19:52:47 +08:00
parent d29e5def4b
commit ceff6ef102
8 changed files with 84 additions and 26 deletions

View file

@ -57,7 +57,7 @@ namespace SourceGit.Git {
if (errs != null) { if (errs != null) {
App.RaiseError(errs); App.RaiseError(errs);
} else { } else {
repo.Fetch(new Remote() { Name = name }, true, null); repo.Fetch(new Remote() { Name = name }, "--recurse-submodules=on-demand", true, null);
} }
} }

View file

@ -448,12 +448,13 @@ namespace SourceGit.Git {
/// Fetch remote changes /// Fetch remote changes
/// </summary> /// </summary>
/// <param name="remote"></param> /// <param name="remote"></param>
/// <param name="submod">submod</param>
/// <param name="prune"></param> /// <param name="prune"></param>
/// <param name="onProgress"></param> /// <param name="onProgress"></param>
public void Fetch(Remote remote, bool prune, Action<string> onProgress) { public void Fetch(Remote remote, string submod, bool prune, Action<string> onProgress) {
isWatcherDisabled = true; isWatcherDisabled = true;
var args = "-c credential.helper=manager fetch --progress --verbose "; var args = $"-c credential.helper=manager fetch --progress --verbose {submod} ";
if (prune) args += "--prune "; if (prune) args += "--prune ";
@ -475,14 +476,15 @@ namespace SourceGit.Git {
/// </summary> /// </summary>
/// <param name="remote">remote</param> /// <param name="remote">remote</param>
/// <param name="branch">branch</param> /// <param name="branch">branch</param>
/// <param name="submod">submod</param>
/// <param name="onProgress">Progress message handler.</param> /// <param name="onProgress">Progress message handler.</param>
/// <param name="rebase">Use rebase instead of merge.</param> /// <param name="rebase">Use rebase instead of merge.</param>
/// <param name="autostash">Auto stash local changes.</param> /// <param name="autostash">Auto stash local changes.</param>
/// <param name="onProgress">Progress message handler.</param> /// <param name="onProgress">Progress message handler.</param>
public void Pull(string remote, string branch, Action<string> onProgress, bool rebase = false, bool autostash = false) { public void Pull(string remote, string branch, string submod, Action<string> onProgress, bool rebase = false, bool autostash = false) {
isWatcherDisabled = true; isWatcherDisabled = true;
var args = "-c credential.helper=manager pull --verbose --progress "; var args = $"-c credential.helper=manager pull --verbose --progress {submod} ";
var needPopStash = false; var needPopStash = false;
if (rebase) args += "--rebase "; if (rebase) args += "--rebase ";
@ -518,14 +520,15 @@ namespace SourceGit.Git {
/// <param name="remote">Remote</param> /// <param name="remote">Remote</param>
/// <param name="localBranch">Local branch name</param> /// <param name="localBranch">Local branch name</param>
/// <param name="remoteBranch">Remote branch name</param> /// <param name="remoteBranch">Remote branch name</param>
/// <param name="submod">submod</param>
/// <param name="onProgress">Progress message handler.</param> /// <param name="onProgress">Progress message handler.</param>
/// <param name="withTags">Push tags</param> /// <param name="withTags">Push tags</param>
/// <param name="track">Create track reference</param> /// <param name="track">Create track reference</param>
/// <param name="force">Force push</param> /// <param name="force">Force push</param>
public void Push(string remote, string localBranch, string remoteBranch, Action<string> onProgress, bool withTags = false, bool track = false, bool force = false) { public void Push(string remote, string localBranch, string remoteBranch, string submod, Action<string> onProgress, bool withTags = false, bool track = false, bool force = false) {
isWatcherDisabled = true; isWatcherDisabled = true;
var args = "-c credential.helper=manager push --progress --verbose "; var args = $"-c credential.helper=manager push --progress --verbose {submod} ";
if (withTags) args += "--tags "; if (withTags) args += "--tags ";
if (track) args += "-u "; if (track) args += "-u ";

View file

@ -6,7 +6,7 @@
xmlns:git="clr-namespace:SourceGit.Git" xmlns:git="clr-namespace:SourceGit.Git"
xmlns:converters="clr-namespace:SourceGit.Converters" xmlns:converters="clr-namespace:SourceGit.Converters"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="192" d:DesignWidth="500" Height="192" Width="500"> d:DesignHeight="192" d:DesignWidth="500" Height="224" Width="500">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="32"/> <RowDefinition Height="32"/>
@ -14,6 +14,7 @@
<RowDefinition Height="32"/> <RowDefinition Height="32"/>
<RowDefinition Height="32"/> <RowDefinition Height="32"/>
<RowDefinition Height="32"/> <RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="16"/> <RowDefinition Height="16"/>
<RowDefinition Height="32"/> <RowDefinition Height="32"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
@ -41,17 +42,24 @@
</ComboBox.ItemTemplate> </ComboBox.ItemTemplate>
</ComboBox> </ComboBox>
<CheckBox Grid.Row="3" Grid.Column="1" <Label Grid.Row="3" Grid.Column="0" HorizontalAlignment="Right" Content="Recurse Submodules :"/>
<StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal">
<RadioButton x:Name="RbtnRrsSubModYes" Content="Yes" GroupName="RecurseSubmodules"/>
<RadioButton x:Name="RbtnRrsSubModDemand" Content="On-Demand" Margin="8,0,0,0" GroupName="RecurseSubmodules" IsChecked="True"/>
<RadioButton x:Name="RbtnRrsSubModNo" Content="No" Margin="8,0,0,0" GroupName="RecurseSubmodules"/>
</StackPanel>
<CheckBox Grid.Row="4" Grid.Column="1"
x:Name="chkFetchAll" x:Name="chkFetchAll"
IsChecked="True" IsChecked="True"
Content="Fetch all remotes"/> Content="Fetch all remotes"/>
<CheckBox Grid.Row="4" Grid.Column="1" <CheckBox Grid.Row="5" Grid.Column="1"
x:Name="chkPrune" x:Name="chkPrune"
IsChecked="True" IsChecked="True"
Content="Prune remote dead branches"/> Content="Prune remote dead branches"/>
<Grid Grid.Row="6" Grid.ColumnSpan="2"> <Grid Grid.Row="7" Grid.ColumnSpan="2">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="80"/> <ColumnDefinition Width="80"/>

View file

@ -51,13 +51,22 @@ namespace SourceGit.UI {
private async void Start(object sender, RoutedEventArgs e) { private async void Start(object sender, RoutedEventArgs e) {
bool prune = chkPrune.IsChecked == true; bool prune = chkPrune.IsChecked == true;
string subMod;
if (RbtnRrsSubModYes.IsChecked == true) {
subMod = "--recurse-submodules=yes";
} else if (RbtnRrsSubModNo.IsChecked == true) {
subMod = "--recurse-submodules=no";
} else {
subMod = "--recurse-submodules=on-demand";
}
PopupManager.Lock(); PopupManager.Lock();
if (chkFetchAll.IsChecked == true) { if (chkFetchAll.IsChecked == true) {
await Task.Run(() => repo.Fetch(null, prune, PopupManager.UpdateStatus)); await Task.Run(() => repo.Fetch(null, subMod, prune, PopupManager.UpdateStatus));
} else { } else {
var remote = combRemotes.SelectedItem as Git.Remote; var remote = combRemotes.SelectedItem as Git.Remote;
await Task.Run(() => repo.Fetch(remote, prune, PopupManager.UpdateStatus)); await Task.Run(() => repo.Fetch(remote, subMod, prune, PopupManager.UpdateStatus));
} }
PopupManager.Close(true); PopupManager.Close(true);

View file

@ -4,7 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="248" d:DesignWidth="500" Height="248" Width="500"> d:DesignHeight="248" d:DesignWidth="500" Height="280" Width="500">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="32"/> <RowDefinition Height="32"/>
@ -12,6 +12,7 @@
<RowDefinition Height="32"/> <RowDefinition Height="32"/>
<RowDefinition Height="32"/> <RowDefinition Height="32"/>
<RowDefinition Height="32"/> <RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="16"/> <RowDefinition Height="16"/>
@ -60,19 +61,26 @@
<Label x:Name="txtInto" VerticalAlignment="Center"/> <Label x:Name="txtInto" VerticalAlignment="Center"/>
</StackPanel> </StackPanel>
<CheckBox Grid.Row="5" Grid.Column="1" <Label Grid.Row="5" Grid.Column="0" HorizontalAlignment="Right" Content="Recurse Submodules :"/>
<StackPanel Grid.Row="5" Grid.Column="1" Orientation="Horizontal">
<RadioButton x:Name="RbtnRrsSubModYes" Content="Yes" GroupName="RecurseSubmodules"/>
<RadioButton x:Name="RbtnRrsSubModDemand" Content="On-Demand" Margin="8,0,0,0" GroupName="RecurseSubmodules" IsChecked="True"/>
<RadioButton x:Name="RbtnRrsSubModNo" Content="No" Margin="8,0,0,0" GroupName="RecurseSubmodules"/>
</StackPanel>
<CheckBox Grid.Row="6" Grid.Column="1"
x:Name="chkRebase" x:Name="chkRebase"
IsChecked="True" IsChecked="True"
VerticalAlignment="Center" VerticalAlignment="Center"
Content="Use rebase instead of merge"/> Content="Use rebase instead of merge"/>
<CheckBox Grid.Row="6" Grid.Column="1" <CheckBox Grid.Row="7" Grid.Column="1"
x:Name="chkAutoStash" x:Name="chkAutoStash"
IsChecked="True" IsChecked="True"
VerticalAlignment="Center" VerticalAlignment="Center"
Content="Stash &amp; reapply local changes"/> Content="Stash &amp; reapply local changes"/>
<Grid Grid.Row="8" Grid.ColumnSpan="2"> <Grid Grid.Row="9" Grid.ColumnSpan="2">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="80"/> <ColumnDefinition Width="80"/>

View file

@ -76,8 +76,17 @@ namespace SourceGit.UI {
if (remote == null || branch == null) return; if (remote == null || branch == null) return;
string subMod;
if (RbtnRrsSubModYes.IsChecked == true) {
subMod = "--recurse-submodules=yes";
} else if (RbtnRrsSubModNo.IsChecked == true) {
subMod = "--recurse-submodules=no";
} else {
subMod = "--recurse-submodules=on-demand";
}
PopupManager.Lock(); PopupManager.Lock();
await Task.Run(() => repo.Pull(remote, branch.Substring(branch.IndexOf('/')+1), PopupManager.UpdateStatus, rebase, autoStash)); await Task.Run(() => repo.Pull(remote, branch.Substring(branch.IndexOf('/')+1), subMod, PopupManager.UpdateStatus, rebase, autoStash));
PopupManager.Close(true); PopupManager.Close(true);
} }

View file

@ -5,7 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:git="clr-namespace:SourceGit.Git" xmlns:git="clr-namespace:SourceGit.Git"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="248" d:DesignWidth="500" Height="248" Width="500"> d:DesignHeight="248" d:DesignWidth="500" Height="280" Width="500">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="32"/> <RowDefinition Height="32"/>
@ -13,6 +13,7 @@
<RowDefinition Height="32"/> <RowDefinition Height="32"/>
<RowDefinition Height="32"/> <RowDefinition Height="32"/>
<RowDefinition Height="32"/> <RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="28"/> <RowDefinition Height="28"/>
<RowDefinition Height="16"/> <RowDefinition Height="16"/>
@ -70,17 +71,25 @@
</ComboBox.ItemTemplate> </ComboBox.ItemTemplate>
</ComboBox> </ComboBox>
<CheckBox Grid.Row="5" Grid.Column="1" <Label Grid.Row="5" Grid.Column="0" HorizontalAlignment="Right" Content="Recurse Submodules :"/>
<StackPanel Grid.Row="5" Grid.Column="1" Orientation="Horizontal">
<RadioButton x:Name="RbtnRrsSubModCheck" Content="Check" GroupName="RecurseSubmodules"/>
<RadioButton x:Name="RbtnRrsSubModDemand" Content="On-Demand" Margin="8,0,0,0" GroupName="RecurseSubmodules" />
<RadioButton x:Name="RbtnRrsSubModOnly" Content="Only" Margin="8,0,0,0" GroupName="RecurseSubmodules"/>
<RadioButton x:Name="RbtnRrsSubModNo" Content="No" Margin="8,0,0,0" GroupName="RecurseSubmodules" IsChecked="True"/>
</StackPanel>
<CheckBox Grid.Row="6" Grid.Column="1"
x:Name="chkTags" x:Name="chkTags"
VerticalAlignment="Center" VerticalAlignment="Center"
Content="Push all tags"/> Content="Push all tags"/>
<CheckBox Grid.Row="6" Grid.Column="1" <CheckBox Grid.Row="7" Grid.Column="1"
x:Name="chkForce" x:Name="chkForce"
VerticalAlignment="Center" VerticalAlignment="Center"
Content="Force push"/> Content="Force push"/>
<Grid Grid.Row="8" Grid.ColumnSpan="2"> <Grid Grid.Row="9" Grid.ColumnSpan="2">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="80"/> <ColumnDefinition Width="80"/>

View file

@ -53,7 +53,7 @@ namespace SourceGit.UI {
var remoteBranch = upstream.Substring(remoteIdx + 1); var remoteBranch = upstream.Substring(remoteIdx + 1);
Task.Run(() => { Task.Run(() => {
repo.Push(remote, current.Name, remoteBranch, PopupManager.UpdateStatus); repo.Push(remote, current.Name, remoteBranch, "--recurse-submodules=no", PopupManager.UpdateStatus);
push.Dispatcher.Invoke(() => { push.Dispatcher.Invoke(() => {
PopupManager.Close(true); PopupManager.Close(true);
}); });
@ -91,13 +91,25 @@ namespace SourceGit.UI {
var tags = chkTags.IsChecked == true; var tags = chkTags.IsChecked == true;
var force = chkForce.IsChecked == true; var force = chkForce.IsChecked == true;
string subMod;
if (RbtnRrsSubModCheck.IsChecked == true) {
subMod = "--recurse-submodules=check";
} else if (RbtnRrsSubModDemand.IsChecked == true) {
subMod = "--recurse-submodules=on-demand";
}
else if (RbtnRrsSubModOnly.IsChecked == true) {
subMod = "--recurse-submodules=only";
} else{
subMod = "--recurse-submodules=no";
}
remoteBranch = remoteBranch.Substring($"{remote}/".Length); remoteBranch = remoteBranch.Substring($"{remote}/".Length);
if (remoteBranch.Contains(" (new)")) { if (remoteBranch.Contains(" (new)")) {
remoteBranch = remoteBranch.Substring(0, remoteBranch.Length - 6); remoteBranch = remoteBranch.Substring(0, remoteBranch.Length - 6);
} }
PopupManager.Lock(); PopupManager.Lock();
await Task.Run(() => repo.Push(remote, localBranch.Name, remoteBranch, PopupManager.UpdateStatus, tags, track, force)); await Task.Run(() => repo.Push(remote, localBranch.Name, remoteBranch, subMod, PopupManager.UpdateStatus, tags, track, force));
PopupManager.Close(true); PopupManager.Close(true);
} }