mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-10-31 13:03:20 -07:00
fix<Native>: fix wrong file filter on macOS platform.
This commit is contained in:
parent
dbd91c9b58
commit
353557ec10
10 changed files with 41 additions and 45 deletions
|
@ -26,7 +26,7 @@ namespace SourceGit.Commands {
|
|||
|
||||
public bool Exec() {
|
||||
var start = new ProcessStartInfo();
|
||||
start.FileName = Native.OS.GitExecutableFile;
|
||||
start.FileName = Native.OS.GitInstallPath;
|
||||
start.Arguments = "--no-pager -c core.quotepath=off " + Args;
|
||||
start.UseShellExecute = false;
|
||||
start.CreateNoWindow = true;
|
||||
|
@ -106,7 +106,7 @@ namespace SourceGit.Commands {
|
|||
|
||||
public ReadToEndResult ReadToEnd() {
|
||||
var start = new ProcessStartInfo();
|
||||
start.FileName = Native.OS.GitExecutableFile;
|
||||
start.FileName = Native.OS.GitInstallPath;
|
||||
start.Arguments = "--no-pager -c core.quotepath=off " + Args;
|
||||
start.UseShellExecute = false;
|
||||
start.CreateNoWindow = true;
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace SourceGit.Commands {
|
|||
private static bool ProcessSingleChange(string repo, Models.DiffOption opt, FileStream writer) {
|
||||
var starter = new ProcessStartInfo();
|
||||
starter.WorkingDirectory = repo;
|
||||
starter.FileName = Native.OS.GitExecutableFile;
|
||||
starter.FileName = Native.OS.GitInstallPath;
|
||||
starter.Arguments = $"diff --ignore-cr-at-eol --unified=4 {opt}";
|
||||
starter.UseShellExecute = false;
|
||||
starter.CreateNoWindow = true;
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace SourceGit.Commands {
|
|||
private static bool ExecCmd(string repo, string args, string outputFile, string inputFile = null) {
|
||||
var starter = new ProcessStartInfo();
|
||||
starter.WorkingDirectory = repo;
|
||||
starter.FileName = Native.OS.GitExecutableFile;
|
||||
starter.FileName = Native.OS.GitInstallPath;
|
||||
starter.Arguments = args;
|
||||
starter.UseShellExecute = false;
|
||||
starter.CreateNoWindow = true;
|
||||
|
|
|
@ -6,8 +6,8 @@ using System.Text;
|
|||
namespace SourceGit.Native {
|
||||
[SupportedOSPlatform("macOS")]
|
||||
internal class MacOS : OS.IBackend {
|
||||
public string FindGitInstallDir() {
|
||||
if (File.Exists("/usr/bin/git")) return "/usr";
|
||||
public string FindGitExecutable() {
|
||||
if (File.Exists("/usr/bin/git")) return "/usr/bin/git";
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ using System.IO;
|
|||
namespace SourceGit.Native {
|
||||
public static class OS {
|
||||
public interface IBackend {
|
||||
string FindGitInstallDir();
|
||||
string FindGitExecutable();
|
||||
string FindVSCode();
|
||||
|
||||
void OpenTerminal(string workdir);
|
||||
|
@ -14,15 +14,11 @@ namespace SourceGit.Native {
|
|||
void OpenWithDefaultEditor(string file);
|
||||
}
|
||||
|
||||
public static string GitInstallDir {
|
||||
public static string GitInstallPath {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public static string GitExecutableFile {
|
||||
get => Path.Combine(GitInstallDir, "bin", OperatingSystem.IsWindows() ? "git.exe" : "git");
|
||||
}
|
||||
|
||||
public static string VSCodeExecutableFile {
|
||||
get;
|
||||
set;
|
||||
|
@ -40,8 +36,8 @@ namespace SourceGit.Native {
|
|||
}
|
||||
}
|
||||
|
||||
public static string FindGitInstallDir() {
|
||||
return _backend?.FindGitInstallDir();
|
||||
public static string FindGitExecutable() {
|
||||
return _backend?.FindGitExecutable();
|
||||
}
|
||||
|
||||
public static void OpenInFileManager(string path, bool select = false) {
|
||||
|
|
|
@ -11,14 +11,14 @@ namespace SourceGit.Native {
|
|||
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode, SetLastError = false)]
|
||||
private static extern bool PathFindOnPath([In, Out] StringBuilder pszFile, [In] string[] ppszOtherDirs);
|
||||
|
||||
public string FindGitInstallDir() {
|
||||
public string FindGitExecutable() {
|
||||
var reg = Microsoft.Win32.RegistryKey.OpenBaseKey(
|
||||
Microsoft.Win32.RegistryHive.LocalMachine,
|
||||
Microsoft.Win32.RegistryView.Registry64);
|
||||
|
||||
var git = reg.OpenSubKey("SOFTWARE\\GitForWindows");
|
||||
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);
|
||||
|
@ -29,15 +29,7 @@ namespace SourceGit.Native {
|
|||
var exePath = builder.ToString();
|
||||
if (string.IsNullOrEmpty(exePath)) return null;
|
||||
|
||||
var binDir = Path.GetDirectoryName(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;
|
||||
return exePath;
|
||||
}
|
||||
|
||||
public string FindVSCode() {
|
||||
|
@ -75,9 +67,9 @@ namespace SourceGit.Native {
|
|||
}
|
||||
|
||||
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)) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace SourceGit.ViewModels {
|
|||
_instance.Repositories.RemoveAll(x => !Directory.Exists(x.FullPath));
|
||||
|
||||
if (!_instance.IsGitConfigured) {
|
||||
_instance.GitInstallDir = Native.OS.FindGitInstallDir();
|
||||
_instance.GitInstallPath = Native.OS.FindGitExecutable();
|
||||
}
|
||||
|
||||
return _instance;
|
||||
|
@ -93,15 +93,15 @@ namespace SourceGit.ViewModels {
|
|||
|
||||
[JsonIgnore]
|
||||
public bool IsGitConfigured {
|
||||
get => !string.IsNullOrEmpty(GitInstallDir) && Directory.Exists(GitInstallDir);
|
||||
get => !string.IsNullOrEmpty(GitInstallPath) && File.Exists(GitInstallPath);
|
||||
}
|
||||
|
||||
public string GitInstallDir {
|
||||
get => Native.OS.GitInstallDir;
|
||||
public string GitInstallPath {
|
||||
get => Native.OS.GitInstallPath;
|
||||
set {
|
||||
if (Native.OS.GitInstallDir != value) {
|
||||
Native.OS.GitInstallDir = value;
|
||||
OnPropertyChanged(nameof(GitInstallDir));
|
||||
if (Native.OS.GitInstallPath != value) {
|
||||
Native.OS.GitInstallPath = value;
|
||||
OnPropertyChanged(nameof(GitInstallPath));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,11 @@ namespace SourceGit.Views {
|
|||
var pageId = page.Node.Id.Replace("\\", "/");
|
||||
if (pageId == ctx) {
|
||||
page.Notifications.Add(notice);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (vm.ActivePage != null) vm.ActivePage.Notifications.Add(notice);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -139,8 +139,8 @@
|
|||
<TextBox Grid.Column="0"
|
||||
Height="28"
|
||||
CornerRadius="3"
|
||||
Text="{Binding GitInstallDir, Mode=TwoWay}"/>
|
||||
<Button Grid.Column="1" Classes="icon_button" Width="32" Height="32" Margin="4,0,0,0" Click="SelectGitInstallDir">
|
||||
Text="{Binding GitInstallPath, Mode=TwoWay}"/>
|
||||
<Button Grid.Column="1" Classes="icon_button" Width="32" Height="32" Margin="4,0,0,0" Click="SelectGitExecutable">
|
||||
<Path Data="{StaticResource Icons.Folder.Open}"/>
|
||||
</Button>
|
||||
</Grid>
|
||||
|
|
|
@ -81,16 +81,20 @@ namespace SourceGit.Views {
|
|||
Close();
|
||||
}
|
||||
|
||||
private async void SelectGitInstallDir(object sender, RoutedEventArgs e) {
|
||||
var options = new FolderPickerOpenOptions() { AllowMultiple = false };
|
||||
var selected = await StorageProvider.OpenFolderPickerAsync(options);
|
||||
private async void SelectGitExecutable(object sender, RoutedEventArgs e) {
|
||||
var pattern = OperatingSystem.IsWindows() ? "git.exe" : "git";
|
||||
var options = new FilePickerOpenOptions() {
|
||||
FileTypeFilter = [new FilePickerFileType("Git Executable") { Patterns = [ pattern ] }],
|
||||
AllowMultiple = false,
|
||||
};
|
||||
|
||||
var selected = await StorageProvider.OpenFilePickerAsync(options);
|
||||
if (selected.Count == 1) {
|
||||
var testExec = Path.Combine(selected[0].Path.LocalPath, "bin", OperatingSystem.IsWindows() ? "git.exe" : "git");
|
||||
if (File.Exists(testExec)) {
|
||||
ViewModels.Preference.Instance.GitInstallDir = selected[0].Path.LocalPath;
|
||||
txtVersion.Text = new Commands.Version().Query();
|
||||
}
|
||||
ViewModels.Preference.Instance.GitInstallPath = selected[0].Path.LocalPath;
|
||||
txtVersion.Text = new Commands.Version().Query();
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private async void SelectDefaultCloneDir(object sender, RoutedEventArgs e) {
|
||||
|
@ -102,8 +106,9 @@ namespace SourceGit.Views {
|
|||
}
|
||||
|
||||
private async void SelectGPGExecutable(object sender, RoutedEventArgs e) {
|
||||
var pattern = OperatingSystem.IsWindows() ? "gpg.exe" : "gpg";
|
||||
var options = new FilePickerOpenOptions() {
|
||||
FileTypeFilter = [new FilePickerFileType("GPG Executable") { Patterns = ["gpg.exe"] }],
|
||||
FileTypeFilter = [new FilePickerFileType("GPG Executable") { Patterns = [ pattern ] }],
|
||||
AllowMultiple = false,
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue