mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
feature<Preference>: query git version after selecting git path
This commit is contained in:
parent
1a5fdc540c
commit
ebc2fc6b91
6 changed files with 70 additions and 33 deletions
18
src/Commands/Version.cs
Normal file
18
src/Commands/Version.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
|
||||
namespace SourceGit.Commands {
|
||||
/// <summary>
|
||||
/// 检测git是否可用,并获取git版本信息
|
||||
/// </summary>
|
||||
public class Version : Command {
|
||||
const string GitVersionPrefix = "git version ";
|
||||
public string Query() {
|
||||
Args = $"--version";
|
||||
var result = ReadToEnd();
|
||||
if (!result.IsSuccess || string.IsNullOrEmpty(result.Output)) return null;
|
||||
var version = result.Output.Trim();
|
||||
if (!version.StartsWith(GitVersionPrefix, StringComparison.Ordinal)) return null;
|
||||
return version.Substring(GitVersionPrefix.Length);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -198,9 +198,7 @@ namespace SourceGit.Models {
|
|||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public bool IsReady {
|
||||
get {
|
||||
return !string.IsNullOrEmpty(Git.Path) && File.Exists(Git.Path);
|
||||
}
|
||||
get => File.Exists(Git.Path) && new Commands.Version().Query() != null;
|
||||
}
|
||||
|
||||
#region DATA
|
||||
|
|
|
@ -364,6 +364,7 @@
|
|||
<sys:String x:Key="Text.Preference.Git">GIT SETTING</sys:String>
|
||||
<sys:String x:Key="Text.Preference.Git.Path">Install Path</sys:String>
|
||||
<sys:String x:Key="Text.Preference.Git.Path.Placeholder">Input path for git.exe</sys:String>
|
||||
<sys:String x:Key="Text.Preference.Git.Version">Git version</sys:String>
|
||||
<sys:String x:Key="Text.Preference.Git.Dir">Default Clone Dir</sys:String>
|
||||
<sys:String x:Key="Text.Preference.Git.Dir.Placeholder">Default path to clone repo into</sys:String>
|
||||
<sys:String x:Key="Text.Preference.Git.User">User Name</sys:String>
|
||||
|
|
|
@ -363,6 +363,7 @@
|
|||
<sys:String x:Key="Text.Preference.Git">GIT配置</sys:String>
|
||||
<sys:String x:Key="Text.Preference.Git.Path">安装路径</sys:String>
|
||||
<sys:String x:Key="Text.Preference.Git.Path.Placeholder">填写git.exe所在位置</sys:String>
|
||||
<sys:String x:Key="Text.Preference.Git.Version">Git 版本</sys:String>
|
||||
<sys:String x:Key="Text.Preference.Git.Dir">默认克隆路径</sys:String>
|
||||
<sys:String x:Key="Text.Preference.Git.Dir.Placeholder">默认的仓库本地存放位置</sys:String>
|
||||
<sys:String x:Key="Text.Preference.Git.User">用户名</sys:String>
|
||||
|
|
|
@ -73,6 +73,7 @@
|
|||
<RowDefinition Height="28"/>
|
||||
<RowDefinition Height="28"/>
|
||||
<RowDefinition Height="28"/>
|
||||
<RowDefinition Height="28"/>
|
||||
<RowDefinition Height="8"/>
|
||||
<RowDefinition Height="36"/>
|
||||
<RowDefinition Height="28"/>
|
||||
|
@ -230,13 +231,24 @@
|
|||
Icon="{StaticResource Icon.Folder.Open}"/>
|
||||
</Grid>
|
||||
|
||||
<!-- Default Clone Dir -->
|
||||
<!-- Git Version -->
|
||||
<TextBlock
|
||||
Grid.Row="13" Grid.Column="0"
|
||||
Text="{DynamicResource Text.Preference.Git.Version}"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,0,8,0"/>
|
||||
<TextBlock
|
||||
Grid.Row="13" Grid.Column="1"
|
||||
x:Name="textGitVersion"
|
||||
Text="{Binding ElementName=me, Path=Version}"/>
|
||||
|
||||
<!-- Default Clone Dir -->
|
||||
<TextBlock
|
||||
Grid.Row="14" Grid.Column="0"
|
||||
Text="{DynamicResource Text.Preference.Git.Dir}"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,0,8,0"/>
|
||||
<Grid Grid.Row="13" Grid.Column="1">
|
||||
<Grid Grid.Row="14" Grid.Column="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
|
@ -259,12 +271,12 @@
|
|||
|
||||
<!-- User -->
|
||||
<TextBlock
|
||||
Grid.Row="14" Grid.Column="0"
|
||||
Grid.Row="15" Grid.Column="0"
|
||||
Text="{DynamicResource Text.Preference.Git.User}"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,0,8,0"/>
|
||||
<controls:TextEdit
|
||||
Grid.Row="14" Grid.Column="1"
|
||||
Grid.Row="15" Grid.Column="1"
|
||||
x:Name="editGitUser"
|
||||
Height="24"
|
||||
Text="{Binding ElementName=me, Path=User, Mode=TwoWay}"
|
||||
|
@ -272,12 +284,12 @@
|
|||
|
||||
<!-- Email -->
|
||||
<TextBlock
|
||||
Grid.Row="15" Grid.Column="0"
|
||||
Grid.Row="16" Grid.Column="0"
|
||||
Text="{DynamicResource Text.Preference.Git.Email}"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,0,8,0"/>
|
||||
<controls:TextEdit
|
||||
Grid.Row="15" Grid.Column="1"
|
||||
Grid.Row="16" Grid.Column="1"
|
||||
x:Name="editGitEmail"
|
||||
Height="24"
|
||||
Text="{Binding ElementName=me, Path=Email, Mode=TwoWay}"
|
||||
|
@ -285,12 +297,12 @@
|
|||
|
||||
<!-- CRLF -->
|
||||
<TextBlock
|
||||
Grid.Row="16" Grid.Column="0"
|
||||
Grid.Row="17" Grid.Column="0"
|
||||
Text="{DynamicResource Text.Preference.Git.CRLF}"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,0,8,0"/>
|
||||
<ComboBox
|
||||
Grid.Row="16" Grid.Column="1"
|
||||
Grid.Row="17" Grid.Column="1"
|
||||
x:Name="editGitCrlf"
|
||||
Height="24"
|
||||
ItemsSource="{Binding Source={x:Static models:CRLFOption.Supported}}"
|
||||
|
@ -308,19 +320,19 @@
|
|||
|
||||
<!-- Merge Tool Group -->
|
||||
<TextBlock
|
||||
Grid.Row="18" Grid.Column="0" Grid.ColumnSpan="2"
|
||||
Grid.Row="19" Grid.Column="0" Grid.ColumnSpan="2"
|
||||
Text="{DynamicResource Text.Preference.Merger}"
|
||||
FontSize="17" FontWeight="DemiBold"
|
||||
Foreground="{DynamicResource Brush.FG2}"/>
|
||||
|
||||
<!-- Merge Tool Type -->
|
||||
<TextBlock
|
||||
Grid.Row="19" Grid.Column="0"
|
||||
Grid.Row="20" Grid.Column="0"
|
||||
Text="{DynamicResource Text.Preference.Merger.Type}"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,0,8,0"/>
|
||||
<ComboBox
|
||||
Grid.Row="19" Grid.Column="1"
|
||||
Grid.Row="20" Grid.Column="1"
|
||||
Height="24"
|
||||
ItemsSource="{Binding Source={x:Static models:MergeTool.Supported}}"
|
||||
DisplayMemberPath="Name"
|
||||
|
@ -330,11 +342,11 @@
|
|||
|
||||
<!-- Merge Tool Executable Path -->
|
||||
<TextBlock
|
||||
Grid.Row="20" Grid.Column="0"
|
||||
Grid.Row="21" Grid.Column="0"
|
||||
Text="{DynamicResource Text.Preference.Merger.Path}"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,0,8,0"/>
|
||||
<Grid Grid.Row="20" Grid.Column="1">
|
||||
<Grid Grid.Row="21" Grid.Column="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
|
|
|
@ -15,6 +15,7 @@ namespace SourceGit.Views {
|
|||
public string User { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string CRLF { get; set; }
|
||||
public string Version { get; set; }
|
||||
|
||||
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathfindonpathw
|
||||
// https://www.pinvoke.net/default.aspx/shlwapi.PathFindOnPath
|
||||
|
@ -24,11 +25,7 @@ namespace SourceGit.Views {
|
|||
public bool EnableWindowsTerminal { get; set; } = PathFindOnPath(new StringBuilder("wt.exe"), null);
|
||||
|
||||
public Preference() {
|
||||
if (!UpdateGitInfoIfReady()) {
|
||||
User = "";
|
||||
Email = "";
|
||||
CRLF = "false";
|
||||
}
|
||||
UpdateGitInfo(false);
|
||||
|
||||
if (!EnableWindowsTerminal) {
|
||||
Models.Preference.Instance.General.UseWindowsTerminal = false;
|
||||
|
@ -37,13 +34,27 @@ namespace SourceGit.Views {
|
|||
InitializeComponent();
|
||||
}
|
||||
|
||||
private bool UpdateGitInfoIfReady() {
|
||||
if (!Models.Preference.Instance.IsReady) return false;
|
||||
private bool UpdateGitInfo(bool updateUi) {
|
||||
var isReady = Models.Preference.Instance.IsReady;
|
||||
if (isReady) {
|
||||
User = new Commands.Config().Get("user.name");
|
||||
Email = new Commands.Config().Get("user.email");
|
||||
CRLF = new Commands.Config().Get("core.autocrlf");
|
||||
Version = new Commands.Version().Query();
|
||||
if (string.IsNullOrEmpty(CRLF)) CRLF = "false";
|
||||
return true;
|
||||
} else {
|
||||
User = "";
|
||||
Email = "";
|
||||
CRLF = "false";
|
||||
Version = "Unknown";
|
||||
}
|
||||
if (updateUi) {
|
||||
editGitUser?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
|
||||
editGitEmail?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
|
||||
editGitCrlf?.GetBindingExpression(ComboBox.SelectedValueProperty).UpdateTarget();
|
||||
textGitVersion?.GetBindingExpression(TextBlock.TextProperty).UpdateTarget();
|
||||
}
|
||||
return isReady;
|
||||
}
|
||||
|
||||
#region EVENTS
|
||||
|
@ -69,11 +80,7 @@ namespace SourceGit.Views {
|
|||
if (dialog.ShowDialog() == true) {
|
||||
Models.Preference.Instance.Git.Path = dialog.FileName;
|
||||
editGitPath?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
|
||||
if (UpdateGitInfoIfReady()) {
|
||||
editGitUser?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
|
||||
editGitEmail?.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
|
||||
editGitCrlf?.GetBindingExpression(ComboBox.SelectedValueProperty).UpdateTarget();
|
||||
}
|
||||
UpdateGitInfo(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue