fix<Native>: fix wrong file filter on macOS platform.

This commit is contained in:
leo 2024-02-21 11:29:28 +08:00
parent dbd91c9b58
commit 353557ec10
10 changed files with 41 additions and 45 deletions

View file

@ -26,7 +26,7 @@ namespace SourceGit.Commands {
public bool Exec() { public bool Exec() {
var start = new ProcessStartInfo(); var start = new ProcessStartInfo();
start.FileName = Native.OS.GitExecutableFile; start.FileName = Native.OS.GitInstallPath;
start.Arguments = "--no-pager -c core.quotepath=off " + Args; start.Arguments = "--no-pager -c core.quotepath=off " + Args;
start.UseShellExecute = false; start.UseShellExecute = false;
start.CreateNoWindow = true; start.CreateNoWindow = true;
@ -106,7 +106,7 @@ namespace SourceGit.Commands {
public ReadToEndResult ReadToEnd() { public ReadToEndResult ReadToEnd() {
var start = new ProcessStartInfo(); var start = new ProcessStartInfo();
start.FileName = Native.OS.GitExecutableFile; start.FileName = Native.OS.GitInstallPath;
start.Arguments = "--no-pager -c core.quotepath=off " + Args; start.Arguments = "--no-pager -c core.quotepath=off " + Args;
start.UseShellExecute = false; start.UseShellExecute = false;
start.CreateNoWindow = true; start.CreateNoWindow = true;

View file

@ -18,7 +18,7 @@ namespace SourceGit.Commands {
private static bool ProcessSingleChange(string repo, Models.DiffOption opt, FileStream writer) { private static bool ProcessSingleChange(string repo, Models.DiffOption opt, FileStream writer) {
var starter = new ProcessStartInfo(); var starter = new ProcessStartInfo();
starter.WorkingDirectory = repo; starter.WorkingDirectory = repo;
starter.FileName = Native.OS.GitExecutableFile; starter.FileName = Native.OS.GitInstallPath;
starter.Arguments = $"diff --ignore-cr-at-eol --unified=4 {opt}"; starter.Arguments = $"diff --ignore-cr-at-eol --unified=4 {opt}";
starter.UseShellExecute = false; starter.UseShellExecute = false;
starter.CreateNoWindow = true; starter.CreateNoWindow = true;

View file

@ -20,7 +20,7 @@ namespace SourceGit.Commands {
private static bool ExecCmd(string repo, string args, string outputFile, string inputFile = null) { private static bool ExecCmd(string repo, string args, string outputFile, string inputFile = null) {
var starter = new ProcessStartInfo(); var starter = new ProcessStartInfo();
starter.WorkingDirectory = repo; starter.WorkingDirectory = repo;
starter.FileName = Native.OS.GitExecutableFile; starter.FileName = Native.OS.GitInstallPath;
starter.Arguments = args; starter.Arguments = args;
starter.UseShellExecute = false; starter.UseShellExecute = false;
starter.CreateNoWindow = true; starter.CreateNoWindow = true;

View file

@ -6,8 +6,8 @@ using System.Text;
namespace SourceGit.Native { namespace SourceGit.Native {
[SupportedOSPlatform("macOS")] [SupportedOSPlatform("macOS")]
internal class MacOS : OS.IBackend { internal class MacOS : OS.IBackend {
public string FindGitInstallDir() { public string FindGitExecutable() {
if (File.Exists("/usr/bin/git")) return "/usr"; if (File.Exists("/usr/bin/git")) return "/usr/bin/git";
return string.Empty; return string.Empty;
} }

View file

@ -5,7 +5,7 @@ using System.IO;
namespace SourceGit.Native { namespace SourceGit.Native {
public static class OS { public static class OS {
public interface IBackend { public interface IBackend {
string FindGitInstallDir(); string FindGitExecutable();
string FindVSCode(); string FindVSCode();
void OpenTerminal(string workdir); void OpenTerminal(string workdir);
@ -14,15 +14,11 @@ namespace SourceGit.Native {
void OpenWithDefaultEditor(string file); void OpenWithDefaultEditor(string file);
} }
public static string GitInstallDir { public static string GitInstallPath {
get; get;
set; set;
} }
public static string GitExecutableFile {
get => Path.Combine(GitInstallDir, "bin", OperatingSystem.IsWindows() ? "git.exe" : "git");
}
public static string VSCodeExecutableFile { public static string VSCodeExecutableFile {
get; get;
set; set;
@ -40,8 +36,8 @@ namespace SourceGit.Native {
} }
} }
public static string FindGitInstallDir() { public static string FindGitExecutable() {
return _backend?.FindGitInstallDir(); return _backend?.FindGitExecutable();
} }
public static void OpenInFileManager(string path, bool select = false) { public static void OpenInFileManager(string path, bool select = false) {

View file

@ -11,14 +11,14 @@ namespace SourceGit.Native {
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode, SetLastError = false)] [DllImport("shlwapi.dll", CharSet = CharSet.Unicode, SetLastError = false)]
private static extern bool PathFindOnPath([In, Out] StringBuilder pszFile, [In] string[] ppszOtherDirs); private static extern bool PathFindOnPath([In, Out] StringBuilder pszFile, [In] string[] ppszOtherDirs);
public string FindGitInstallDir() { public string FindGitExecutable() {
var reg = Microsoft.Win32.RegistryKey.OpenBaseKey( var reg = Microsoft.Win32.RegistryKey.OpenBaseKey(
Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryHive.LocalMachine,
Microsoft.Win32.RegistryView.Registry64); Microsoft.Win32.RegistryView.Registry64);
var git = reg.OpenSubKey("SOFTWARE\\GitForWindows"); var git = reg.OpenSubKey("SOFTWARE\\GitForWindows");
if (git != null) { if (git != null) {
return git.GetValue("InstallPath") as string; return Path.Combine(git.GetValue("InstallPath") as string, "bin", "git.exe");
} }
var builder = new StringBuilder("git.exe", 259); var builder = new StringBuilder("git.exe", 259);
@ -29,15 +29,7 @@ namespace SourceGit.Native {
var exePath = builder.ToString(); var exePath = builder.ToString();
if (string.IsNullOrEmpty(exePath)) return null; if (string.IsNullOrEmpty(exePath)) return null;
var binDir = Path.GetDirectoryName(exePath); return exePath;
var bashPath = Path.Combine(binDir, "bash.exe");
if (File.Exists(bashPath)) return Path.GetDirectoryName(binDir);
binDir = Path.Combine(Path.GetDirectoryName(binDir), "bin");
bashPath = Path.Combine(binDir, "bash.exe");
if (File.Exists(bashPath)) return Path.GetDirectoryName(binDir);
return null;
} }
public string FindVSCode() { public string FindVSCode() {
@ -75,9 +67,9 @@ namespace SourceGit.Native {
} }
public void OpenTerminal(string workdir) { public void OpenTerminal(string workdir) {
var bash = Path.Combine(ViewModels.Preference.Instance.GitInstallDir, "bin", "bash.exe"); var bash = Path.Combine(Path.GetDirectoryName(OS.GitInstallPath), "bash.exe");
if (!File.Exists(bash)) { if (!File.Exists(bash)) {
App.RaiseException("", $"Can NOT found bash.exe under '{ViewModels.Preference.Instance.GitInstallDir}'"); App.RaiseException(string.IsNullOrEmpty(workdir) ? "" : workdir, $"Can NOT found bash.exe under '{Path.GetDirectoryName(OS.GitInstallPath)}'");
return; return;
} }

View file

@ -26,7 +26,7 @@ namespace SourceGit.ViewModels {
_instance.Repositories.RemoveAll(x => !Directory.Exists(x.FullPath)); _instance.Repositories.RemoveAll(x => !Directory.Exists(x.FullPath));
if (!_instance.IsGitConfigured) { if (!_instance.IsGitConfigured) {
_instance.GitInstallDir = Native.OS.FindGitInstallDir(); _instance.GitInstallPath = Native.OS.FindGitExecutable();
} }
return _instance; return _instance;
@ -93,15 +93,15 @@ namespace SourceGit.ViewModels {
[JsonIgnore] [JsonIgnore]
public bool IsGitConfigured { public bool IsGitConfigured {
get => !string.IsNullOrEmpty(GitInstallDir) && Directory.Exists(GitInstallDir); get => !string.IsNullOrEmpty(GitInstallPath) && File.Exists(GitInstallPath);
} }
public string GitInstallDir { public string GitInstallPath {
get => Native.OS.GitInstallDir; get => Native.OS.GitInstallPath;
set { set {
if (Native.OS.GitInstallDir != value) { if (Native.OS.GitInstallPath != value) {
Native.OS.GitInstallDir = value; Native.OS.GitInstallPath = value;
OnPropertyChanged(nameof(GitInstallDir)); OnPropertyChanged(nameof(GitInstallPath));
} }
} }
} }

View file

@ -16,8 +16,11 @@ namespace SourceGit.Views {
var pageId = page.Node.Id.Replace("\\", "/"); var pageId = page.Node.Id.Replace("\\", "/");
if (pageId == ctx) { if (pageId == ctx) {
page.Notifications.Add(notice); page.Notifications.Add(notice);
return;
} }
} }
if (vm.ActivePage != null) vm.ActivePage.Notifications.Add(notice);
} }
} }

View file

@ -139,8 +139,8 @@
<TextBox Grid.Column="0" <TextBox Grid.Column="0"
Height="28" Height="28"
CornerRadius="3" CornerRadius="3"
Text="{Binding GitInstallDir, Mode=TwoWay}"/> Text="{Binding GitInstallPath, Mode=TwoWay}"/>
<Button Grid.Column="1" Classes="icon_button" Width="32" Height="32" Margin="4,0,0,0" Click="SelectGitInstallDir"> <Button Grid.Column="1" Classes="icon_button" Width="32" Height="32" Margin="4,0,0,0" Click="SelectGitExecutable">
<Path Data="{StaticResource Icons.Folder.Open}"/> <Path Data="{StaticResource Icons.Folder.Open}"/>
</Button> </Button>
</Grid> </Grid>

View file

@ -81,16 +81,20 @@ namespace SourceGit.Views {
Close(); Close();
} }
private async void SelectGitInstallDir(object sender, RoutedEventArgs e) { private async void SelectGitExecutable(object sender, RoutedEventArgs e) {
var options = new FolderPickerOpenOptions() { AllowMultiple = false }; var pattern = OperatingSystem.IsWindows() ? "git.exe" : "git";
var selected = await StorageProvider.OpenFolderPickerAsync(options); var options = new FilePickerOpenOptions() {
FileTypeFilter = [new FilePickerFileType("Git Executable") { Patterns = [ pattern ] }],
AllowMultiple = false,
};
var selected = await StorageProvider.OpenFilePickerAsync(options);
if (selected.Count == 1) { if (selected.Count == 1) {
var testExec = Path.Combine(selected[0].Path.LocalPath, "bin", OperatingSystem.IsWindows() ? "git.exe" : "git"); ViewModels.Preference.Instance.GitInstallPath = selected[0].Path.LocalPath;
if (File.Exists(testExec)) { txtVersion.Text = new Commands.Version().Query();
ViewModels.Preference.Instance.GitInstallDir = selected[0].Path.LocalPath;
txtVersion.Text = new Commands.Version().Query();
}
} }
e.Handled = true;
} }
private async void SelectDefaultCloneDir(object sender, RoutedEventArgs e) { private async void SelectDefaultCloneDir(object sender, RoutedEventArgs e) {
@ -102,8 +106,9 @@ namespace SourceGit.Views {
} }
private async void SelectGPGExecutable(object sender, RoutedEventArgs e) { private async void SelectGPGExecutable(object sender, RoutedEventArgs e) {
var pattern = OperatingSystem.IsWindows() ? "gpg.exe" : "gpg";
var options = new FilePickerOpenOptions() { var options = new FilePickerOpenOptions() {
FileTypeFilter = [new FilePickerFileType("GPG Executable") { Patterns = ["gpg.exe"] }], FileTypeFilter = [new FilePickerFileType("GPG Executable") { Patterns = [ pattern ] }],
AllowMultiple = false, AllowMultiple = false,
}; };