mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07:00
refactor: update submodule (#287)
This commit is contained in:
parent
58c685627f
commit
7bfb684bde
7 changed files with 127 additions and 17 deletions
|
@ -13,36 +13,46 @@ namespace SourceGit.Commands
|
||||||
public bool Add(string url, string relativePath, bool recursive, Action<string> outputHandler)
|
public bool Add(string url, string relativePath, bool recursive, Action<string> outputHandler)
|
||||||
{
|
{
|
||||||
_outputHandler = outputHandler;
|
_outputHandler = outputHandler;
|
||||||
Args = $"submodule add {url} {relativePath}";
|
Args = $"submodule add {url} \"{relativePath}\"";
|
||||||
if (!Exec())
|
if (!Exec())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (recursive)
|
if (recursive)
|
||||||
{
|
{
|
||||||
Args = $"submodule update --init --recursive -- {relativePath}";
|
Args = $"submodule update --init --recursive -- \"{relativePath}\"";
|
||||||
return Exec();
|
return Exec();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Args = $"submodule update --init -- {relativePath}";
|
Args = $"submodule update --init -- \"{relativePath}\"";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Update(Action<string> outputHandler)
|
public bool Update(string module, bool init, bool recursive, bool useRemote, Action<string> outputHandler)
|
||||||
{
|
{
|
||||||
Args = $"submodule update --rebase --remote";
|
Args = "submodule update";
|
||||||
|
|
||||||
|
if (init)
|
||||||
|
Args += " --init";
|
||||||
|
if (recursive)
|
||||||
|
Args += " --recursive";
|
||||||
|
if (useRemote)
|
||||||
|
Args += " --remote";
|
||||||
|
if (!string.IsNullOrEmpty(module))
|
||||||
|
Args += $" -- \"{module}\"";
|
||||||
|
|
||||||
_outputHandler = outputHandler;
|
_outputHandler = outputHandler;
|
||||||
return Exec();
|
return Exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Delete(string relativePath)
|
public bool Delete(string relativePath)
|
||||||
{
|
{
|
||||||
Args = $"submodule deinit -f {relativePath}";
|
Args = $"submodule deinit -f \"{relativePath}\"";
|
||||||
if (!Exec())
|
if (!Exec())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Args = $"rm -rf {relativePath}";
|
Args = $"rm -rf \"{relativePath}\"";
|
||||||
return Exec();
|
return Exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -545,7 +545,11 @@
|
||||||
<x:String x:Key="Text.TagCM.Push" xml:space="preserve">Push ${0}$...</x:String>
|
<x:String x:Key="Text.TagCM.Push" xml:space="preserve">Push ${0}$...</x:String>
|
||||||
<x:String x:Key="Text.URL" xml:space="preserve">URL:</x:String>
|
<x:String x:Key="Text.URL" xml:space="preserve">URL:</x:String>
|
||||||
<x:String x:Key="Text.UpdateSubmodules" xml:space="preserve">Update Submodules</x:String>
|
<x:String x:Key="Text.UpdateSubmodules" xml:space="preserve">Update Submodules</x:String>
|
||||||
<x:String x:Key="Text.UpdateSubmodules.Tip" xml:space="preserve">Run `submodule update` command for this repository.</x:String>
|
<x:String x:Key="Text.UpdateSubmodules.All" xml:space="preserve">All submodules</x:String>
|
||||||
|
<x:String x:Key="Text.UpdateSubmodules.Init" xml:space="preserve">Initialize as needed</x:String>
|
||||||
|
<x:String x:Key="Text.UpdateSubmodules.Recursive" xml:space="preserve">Recursively</x:String>
|
||||||
|
<x:String x:Key="Text.UpdateSubmodules.Target" xml:space="preserve">Submodule:</x:String>
|
||||||
|
<x:String x:Key="Text.UpdateSubmodules.UseRemote" xml:space="preserve">Use --remote option</x:String>
|
||||||
<x:String x:Key="Text.Warn" xml:space="preserve">Warning</x:String>
|
<x:String x:Key="Text.Warn" xml:space="preserve">Warning</x:String>
|
||||||
<x:String x:Key="Text.Welcome.AddRootFolder" xml:space="preserve">Create Group</x:String>
|
<x:String x:Key="Text.Welcome.AddRootFolder" xml:space="preserve">Create Group</x:String>
|
||||||
<x:String x:Key="Text.Welcome.AddSubFolder" xml:space="preserve">Create Sub-Group</x:String>
|
<x:String x:Key="Text.Welcome.AddSubFolder" xml:space="preserve">Create Sub-Group</x:String>
|
||||||
|
|
|
@ -547,7 +547,11 @@
|
||||||
<x:String x:Key="Text.TagCM.Push" xml:space="preserve">推送 ${0}$...</x:String>
|
<x:String x:Key="Text.TagCM.Push" xml:space="preserve">推送 ${0}$...</x:String>
|
||||||
<x:String x:Key="Text.URL" xml:space="preserve">仓库地址 :</x:String>
|
<x:String x:Key="Text.URL" xml:space="preserve">仓库地址 :</x:String>
|
||||||
<x:String x:Key="Text.UpdateSubmodules" xml:space="preserve">更新子模块</x:String>
|
<x:String x:Key="Text.UpdateSubmodules" xml:space="preserve">更新子模块</x:String>
|
||||||
<x:String x:Key="Text.UpdateSubmodules.Tip" xml:space="preserve">为此仓库执行`submodule update`命令,更新所有的子模块。</x:String>
|
<x:String x:Key="Text.UpdateSubmodules.All" xml:space="preserve">更新所有子模块</x:String>
|
||||||
|
<x:String x:Key="Text.UpdateSubmodules.Init" xml:space="preserve">启用 '--init'</x:String>
|
||||||
|
<x:String x:Key="Text.UpdateSubmodules.Recursive" xml:space="preserve">启用 '--recursive'</x:String>
|
||||||
|
<x:String x:Key="Text.UpdateSubmodules.Target" xml:space="preserve">子模块 :</x:String>
|
||||||
|
<x:String x:Key="Text.UpdateSubmodules.UseRemote" xml:space="preserve">启用 '--remote'</x:String>
|
||||||
<x:String x:Key="Text.Warn" xml:space="preserve">警告</x:String>
|
<x:String x:Key="Text.Warn" xml:space="preserve">警告</x:String>
|
||||||
<x:String x:Key="Text.Welcome.AddRootFolder" xml:space="preserve">新建分组</x:String>
|
<x:String x:Key="Text.Welcome.AddRootFolder" xml:space="preserve">新建分组</x:String>
|
||||||
<x:String x:Key="Text.Welcome.AddSubFolder" xml:space="preserve">新建子分组</x:String>
|
<x:String x:Key="Text.Welcome.AddSubFolder" xml:space="preserve">新建子分组</x:String>
|
||||||
|
|
|
@ -547,7 +547,11 @@
|
||||||
<x:String x:Key="Text.TagCM.Push" xml:space="preserve">推送 ${0}$...</x:String>
|
<x:String x:Key="Text.TagCM.Push" xml:space="preserve">推送 ${0}$...</x:String>
|
||||||
<x:String x:Key="Text.URL" xml:space="preserve">倉庫地址 :</x:String>
|
<x:String x:Key="Text.URL" xml:space="preserve">倉庫地址 :</x:String>
|
||||||
<x:String x:Key="Text.UpdateSubmodules" xml:space="preserve">更新子模組</x:String>
|
<x:String x:Key="Text.UpdateSubmodules" xml:space="preserve">更新子模組</x:String>
|
||||||
<x:String x:Key="Text.UpdateSubmodules.Tip" xml:space="preserve">本操作將執行 `submodule update` 。</x:String>
|
<x:String x:Key="Text.UpdateSubmodules.All" xml:space="preserve">更新所有子模組</x:String>
|
||||||
|
<x:String x:Key="Text.UpdateSubmodules.Init" xml:space="preserve">啟用『--init』選項</x:String>
|
||||||
|
<x:String x:Key="Text.UpdateSubmodules.Recursive" xml:space="preserve">啟用『--recursive』選項</x:String>
|
||||||
|
<x:String x:Key="Text.UpdateSubmodules.Target" xml:space="preserve">子模組 :</x:String>
|
||||||
|
<x:String x:Key="Text.UpdateSubmodules.UseRemote" xml:space="preserve">啟用『--remote』選項</x:String>
|
||||||
<x:String x:Key="Text.Warn" xml:space="preserve">警告</x:String>
|
<x:String x:Key="Text.Warn" xml:space="preserve">警告</x:String>
|
||||||
<x:String x:Key="Text.Welcome.AddRootFolder" xml:space="preserve">新建分組</x:String>
|
<x:String x:Key="Text.Welcome.AddRootFolder" xml:space="preserve">新建分組</x:String>
|
||||||
<x:String x:Key="Text.Welcome.AddSubFolder" xml:space="preserve">新建子分組</x:String>
|
<x:String x:Key="Text.Welcome.AddSubFolder" xml:space="preserve">新建子分組</x:String>
|
||||||
|
|
|
@ -863,7 +863,7 @@ namespace SourceGit.ViewModels
|
||||||
public void UpdateSubmodules()
|
public void UpdateSubmodules()
|
||||||
{
|
{
|
||||||
if (PopupHost.CanCreatePopup())
|
if (PopupHost.CanCreatePopup())
|
||||||
PopupHost.ShowAndStartPopup(new UpdateSubmodules(this));
|
PopupHost.ShowPopup(new UpdateSubmodules(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenSubmodule(string submodule)
|
public void OpenSubmodule(string submodule)
|
||||||
|
|
|
@ -1,28 +1,82 @@
|
||||||
using System.Threading.Tasks;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace SourceGit.ViewModels
|
namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
public class UpdateSubmodules : Popup
|
public class UpdateSubmodules : Popup
|
||||||
{
|
{
|
||||||
|
public List<string> Submodules
|
||||||
|
{
|
||||||
|
get => _repo.Submodules;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string SelectedSubmodule
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UpdateAll
|
||||||
|
{
|
||||||
|
get => _updateAll;
|
||||||
|
set => SetProperty(ref _updateAll, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool EnableInit
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
} = true;
|
||||||
|
|
||||||
|
public bool EnableRecursive
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
} = true;
|
||||||
|
|
||||||
|
public bool EnableRemote
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
} = false;
|
||||||
|
|
||||||
public UpdateSubmodules(Repository repo)
|
public UpdateSubmodules(Repository repo)
|
||||||
{
|
{
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
|
SelectedSubmodule = repo.Submodules.Count > 0 ? repo.Submodules[0] : string.Empty;
|
||||||
View = new Views.UpdateSubmodules() { DataContext = this };
|
View = new Views.UpdateSubmodules() { DataContext = this };
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<bool> Sure()
|
public override Task<bool> Sure()
|
||||||
{
|
{
|
||||||
_repo.SetWatcherEnabled(false);
|
_repo.SetWatcherEnabled(false);
|
||||||
|
|
||||||
|
string target = string.Empty;
|
||||||
|
if (_updateAll)
|
||||||
|
{
|
||||||
ProgressDescription = "Updating submodules ...";
|
ProgressDescription = "Updating submodules ...";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
target = SelectedSubmodule;
|
||||||
|
ProgressDescription = $"Updating submodule {target} ...";
|
||||||
|
}
|
||||||
|
|
||||||
return Task.Run(() =>
|
return Task.Run(() =>
|
||||||
{
|
{
|
||||||
new Commands.Submodule(_repo.FullPath).Update(SetProgressDescription);
|
new Commands.Submodule(_repo.FullPath).Update(
|
||||||
|
target,
|
||||||
|
EnableInit,
|
||||||
|
EnableRecursive,
|
||||||
|
EnableRemote,
|
||||||
|
SetProgressDescription);
|
||||||
|
|
||||||
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly Repository _repo = null;
|
private readonly Repository _repo = null;
|
||||||
|
private bool _updateAll = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,42 @@
|
||||||
<TextBlock FontSize="18"
|
<TextBlock FontSize="18"
|
||||||
Classes="bold"
|
Classes="bold"
|
||||||
Text="{DynamicResource Text.UpdateSubmodules}"/>
|
Text="{DynamicResource Text.UpdateSubmodules}"/>
|
||||||
<TextBlock Text="{DynamicResource Text.UpdateSubmodules.Tip}"
|
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32,32,32" ColumnDefinitions="120,*">
|
||||||
Margin="0,16,0,0"
|
<TextBlock Grid.Row="0" Grid.Column="0"
|
||||||
HorizontalAlignment="Center"/>
|
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||||
|
Margin="0,0,8,0"
|
||||||
|
Text="{DynamicResource Text.UpdateSubmodules.Target}"/>
|
||||||
|
<ComboBox Grid.Row="0" Grid.Column="1"
|
||||||
|
Height="28" Padding="8,0"
|
||||||
|
VerticalAlignment="Center" HorizontalAlignment="Stretch"
|
||||||
|
ItemsSource="{Binding Submodules}"
|
||||||
|
SelectedItem="{Binding SelectedSubmodule, Mode=TwoWay}"
|
||||||
|
IsEnabled="{Binding !UpdateAll}">
|
||||||
|
<ComboBox.ItemTemplate>
|
||||||
|
<DataTemplate x:DataType="x:String">
|
||||||
|
<StackPanel Orientation="Horizontal" Height="20" VerticalAlignment="Center">
|
||||||
|
<Path Margin="0,0,8,0" Width="14" Height="14" Fill="{DynamicResource Brush.FG1}" Data="{StaticResource Icons.Submodule}"/>
|
||||||
|
<TextBlock Text="{Binding}"/>
|
||||||
|
</StackPanel>
|
||||||
|
</DataTemplate>
|
||||||
|
</ComboBox.ItemTemplate>
|
||||||
|
</ComboBox>
|
||||||
|
|
||||||
|
<CheckBox Grid.Row="1" Grid.Column="1"
|
||||||
|
Content="{DynamicResource Text.UpdateSubmodules.All}"
|
||||||
|
IsChecked="{Binding UpdateAll, Mode=TwoWay}"/>
|
||||||
|
|
||||||
|
<CheckBox Grid.Row="2" Grid.Column="1"
|
||||||
|
Content="{DynamicResource Text.UpdateSubmodules.Init}"
|
||||||
|
IsChecked="{Binding EnableInit, Mode=TwoWay}"/>
|
||||||
|
|
||||||
|
<CheckBox Grid.Row="3" Grid.Column="1"
|
||||||
|
Content="{DynamicResource Text.UpdateSubmodules.Recursive}"
|
||||||
|
IsChecked="{Binding EnableRecursive, Mode=TwoWay}"/>
|
||||||
|
|
||||||
|
<CheckBox Grid.Row="4" Grid.Column="1"
|
||||||
|
Content="{DynamicResource Text.UpdateSubmodules.UseRemote}"
|
||||||
|
IsChecked="{Binding EnableRemote, Mode=TwoWay}"/>
|
||||||
|
</Grid>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|
Loading…
Reference in a new issue