From 275a52eb5cc83ee0f457fd96d73a47b8a614fa9a Mon Sep 17 00:00:00 2001 From: leo Date: Sat, 11 Jan 2025 11:28:37 +0800 Subject: [PATCH] refactor: add repository --- src/ViewModels/Clone.cs | 3 +-- src/ViewModels/Init.cs | 3 +-- src/ViewModels/Launcher.cs | 3 +-- src/ViewModels/Preference.cs | 10 +++++++--- src/Views/Welcome.axaml.cs | 3 +-- src/Views/WelcomeToolbar.axaml.cs | 3 +-- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/ViewModels/Clone.cs b/src/ViewModels/Clone.cs index 79dce87e..e7d3e8ef 100644 --- a/src/ViewModels/Clone.cs +++ b/src/ViewModels/Clone.cs @@ -129,8 +129,7 @@ namespace SourceGit.ViewModels CallUIThread(() => { - var normalizedPath = path.Replace("\\", "/"); - var node = Preference.Instance.FindOrAddNodeByRepositoryPath(normalizedPath, null, true); + var node = Preference.Instance.FindOrAddNodeByRepositoryPath(path, null, true); var launcher = App.GetLauncer(); var page = null as LauncherPage; foreach (var one in launcher.Pages) diff --git a/src/ViewModels/Init.cs b/src/ViewModels/Init.cs index 06e522c0..e22d1289 100644 --- a/src/ViewModels/Init.cs +++ b/src/ViewModels/Init.cs @@ -38,8 +38,7 @@ namespace SourceGit.ViewModels CallUIThread(() => { - var normalizedPath = _targetPath.Replace("\\", "/"); - Preference.Instance.FindOrAddNodeByRepositoryPath(normalizedPath, _parentNode, true); + Preference.Instance.FindOrAddNodeByRepositoryPath(_targetPath, _parentNode, true); Welcome.Instance.Refresh(); }); diff --git a/src/ViewModels/Launcher.cs b/src/ViewModels/Launcher.cs index 24d2c0b9..da487b21 100644 --- a/src/ViewModels/Launcher.cs +++ b/src/ViewModels/Launcher.cs @@ -103,8 +103,7 @@ namespace SourceGit.ViewModels } else { - var normalized = test.StdOut.Trim().Replace("\\", "/"); - var node = pref.FindOrAddNodeByRepositoryPath(normalized, null, false); + var node = pref.FindOrAddNodeByRepositoryPath(test.StdOut.Trim(), null, false); Welcome.Instance.Refresh(); OpenRepositoryInTab(node, null); } diff --git a/src/ViewModels/Preference.cs b/src/ViewModels/Preference.cs index efd446df..00bd3a44 100644 --- a/src/ViewModels/Preference.cs +++ b/src/ViewModels/Preference.cs @@ -405,13 +405,17 @@ namespace SourceGit.ViewModels public RepositoryNode FindOrAddNodeByRepositoryPath(string repo, RepositoryNode parent, bool shouldMoveNode) { - var node = FindNodeRecursive(repo, RepositoryNodes); + var normalized = repo.Replace('\\', '/'); + if (normalized.EndsWith("/")) + normalized = normalized.TrimEnd('/'); + + var node = FindNodeRecursive(normalized, RepositoryNodes); if (node == null) { node = new RepositoryNode() { - Id = repo, - Name = Path.GetFileName(repo), + Id = normalized, + Name = Path.GetFileName(normalized), Bookmark = 0, IsRepository = true, }; diff --git a/src/Views/Welcome.axaml.cs b/src/Views/Welcome.axaml.cs index a292a6ef..500bc571 100644 --- a/src/Views/Welcome.axaml.cs +++ b/src/Views/Welcome.axaml.cs @@ -307,8 +307,7 @@ namespace SourceGit.Views return; } - var normalizedPath = test.StdOut.Trim().Replace("\\", "/"); - var node = ViewModels.Preference.Instance.FindOrAddNodeByRepositoryPath(normalizedPath, parent, true); + var node = ViewModels.Preference.Instance.FindOrAddNodeByRepositoryPath(test.StdOut.Trim(), parent, true); ViewModels.Welcome.Instance.Refresh(); var launcher = this.FindAncestorOfType()?.DataContext as ViewModels.Launcher; diff --git a/src/Views/WelcomeToolbar.axaml.cs b/src/Views/WelcomeToolbar.axaml.cs index 0a9e4822..19be5500 100644 --- a/src/Views/WelcomeToolbar.axaml.cs +++ b/src/Views/WelcomeToolbar.axaml.cs @@ -63,8 +63,7 @@ namespace SourceGit.Views return; } - var normalizedPath = test.StdOut.Trim().Replace("\\", "/"); - var node = ViewModels.Preference.Instance.FindOrAddNodeByRepositoryPath(normalizedPath, parent, false); + var node = ViewModels.Preference.Instance.FindOrAddNodeByRepositoryPath(test.StdOut.Trim(), parent, false); ViewModels.Welcome.Instance.Refresh(); var launcher = this.FindAncestorOfType()?.DataContext as ViewModels.Launcher;