Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public static IStorageProvider GetStorageProvider()
return null;
}

public static ViewModels.Launcher GetLauncer()
public static ViewModels.Launcher GetLauncher()
{
return Current is App app ? app._launcher : null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Models/Watcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private void OnRepositoryChanged(object o, FileSystemEventArgs e)
if (string.IsNullOrEmpty(e.Name))
return;

var name = e.Name.Replace("\\", "/");
var name = e.Name.Replace('\\', '/').TrimEnd('/');
if (name.Contains("fsmonitor--daemon/", StringComparison.Ordinal) ||
name.EndsWith(".lock", StringComparison.Ordinal) ||
name.StartsWith("lfs/", StringComparison.Ordinal))
Expand Down Expand Up @@ -205,7 +205,7 @@ private void OnWorkingCopyChanged(object o, FileSystemEventArgs e)
if (string.IsNullOrEmpty(e.Name))
return;

var name = e.Name.Replace("\\", "/");
var name = e.Name.Replace('\\', '/').TrimEnd('/');
if (name.Equals(".git", StringComparison.Ordinal) ||
name.StartsWith(".git/", StringComparison.Ordinal) ||
name.EndsWith("/.git", StringComparison.Ordinal))
Expand Down
2 changes: 1 addition & 1 deletion src/ViewModels/Blame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Blame(string repo, string file, string revision)

public void NavigateToCommit(string commitSHA)
{
var launcher = App.GetLauncer();
var launcher = App.GetLauncher();
if (launcher == null)
return;

Expand Down
2 changes: 1 addition & 1 deletion src/ViewModels/BranchCompare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public BranchCompare(string repo, Models.Branch baseBranch, Models.Branch toBran

public void NavigateTo(string commitSHA)
{
var launcher = App.GetLauncer();
var launcher = App.GetLauncher();
if (launcher == null)
return;

Expand Down
2 changes: 1 addition & 1 deletion src/ViewModels/Clone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public override Task<bool> Sure()
CallUIThread(() =>
{
var node = Preferences.Instance.FindOrAddNodeByRepositoryPath(path, null, true);
var launcher = App.GetLauncer();
var launcher = App.GetLauncher();
var page = null as LauncherPage;
foreach (var one in launcher.Pages)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ViewModels/DiffContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private void LoadDiffContent()
if (count <= 3)
{
var submoduleDiff = new Models.SubmoduleDiff();
var submoduleRoot = $"{_repo}/{_option.Path}".Replace("\\", "/");
var submoduleRoot = $"{_repo}/{_option.Path}".Replace('\\', '/').TrimEnd('/');
isSubmodule = true;
for (int i = 1; i < count; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ViewModels/Launcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ public void DispatchNotification(string pageId, string message, bool isError)

foreach (var page in Pages)
{
var id = page.Node.Id.Replace("\\", "/");
var id = page.Node.Id.Replace('\\', '/').TrimEnd('/');
if (id == pageId)
{
page.Notifications.Add(notification);
Expand Down
43 changes: 25 additions & 18 deletions src/ViewModels/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,16 +430,26 @@ public void AddNode(RepositoryNode node, RepositoryNode to, bool save)
{
var collection = to == null ? RepositoryNodes : to.SubNodes;
collection.Add(node);
collection.Sort((l, r) =>
SortNodes(collection);

if (save)
Save();
}

public void SortNodes(List<RepositoryNode> collection)
{
collection?.Sort((l, r) =>
{
if (l.IsRepository != r.IsRepository)
return l.IsRepository ? 1 : -1;

return string.Compare(l.Name, r.Name, StringComparison.Ordinal);
return string.Compare(l.Name, r.Name, StringComparison.OrdinalIgnoreCase);
});
}

if (save)
Save();
public void SortAllNodes()
{
SortNodesRecursive(RepositoryNodes);
}

public RepositoryNode FindNode(string id)
Expand All @@ -449,9 +459,7 @@ public RepositoryNode FindNode(string id)

public RepositoryNode FindOrAddNodeByRepositoryPath(string repo, RepositoryNode parent, bool shouldMoveNode)
{
var normalized = repo.Replace('\\', '/');
if (normalized.EndsWith("/"))
normalized = normalized.TrimEnd('/');
var normalized = repo.Replace('\\', '/').TrimEnd('/');

var node = FindNodeRecursive(normalized, RepositoryNodes);
if (node == null)
Expand Down Expand Up @@ -499,22 +507,14 @@ public void RemoveNode(RepositoryNode node, bool save)
public void SortByRenamedNode(RepositoryNode node)
{
var container = FindNodeContainer(node, RepositoryNodes);
container?.Sort((l, r) =>
{
if (l.IsRepository != r.IsRepository)
return l.IsRepository ? 1 : -1;

return string.Compare(l.Name, r.Name, StringComparison.Ordinal);
});
SortNodes(container);

Save();
}

public void AutoRemoveInvalidNode()
public bool AutoRemoveInvalidNode()
{
var changed = RemoveInvalidRepositoriesRecursive(RepositoryNodes);
if (changed)
Save();
return RemoveInvalidRepositoriesRecursive(RepositoryNodes);
}

public void Save()
Expand Down Expand Up @@ -584,6 +584,13 @@ private void PrepareWorkspaces()
}
}

private void SortNodesRecursive(List<RepositoryNode> collection)
{
SortNodes(collection);
foreach (var node in collection)
SortNodesRecursive(node.SubNodes);
}

private RepositoryNode FindNodeRecursive(string id, List<RepositoryNode> collection)
{
foreach (var node in collection)
Expand Down
15 changes: 8 additions & 7 deletions src/ViewModels/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public string FullPath
{
if (value != null)
{
var normalized = value.Replace('\\', '/');
var normalized = value.Replace('\\', '/').TrimEnd('/');
SetProperty(ref _fullpath, normalized);
}
else
Expand Down Expand Up @@ -499,7 +499,7 @@ public void Open()
{
// For worktrees, we need to watch the $GIT_COMMON_DIR instead of the $GIT_DIR.
var gitDirForWatcher = _gitDir;
if (_gitDir.Replace("\\", "/").IndexOf("/worktrees/", StringComparison.Ordinal) > 0)
if (_gitDir.Replace('\\', '/').IndexOf("/worktrees/", StringComparison.Ordinal) > 0)
{
var commonDir = new Commands.QueryGitCommonDir(_fullpath).Result();
if (!string.IsNullOrEmpty(commonDir))
Expand Down Expand Up @@ -1120,7 +1120,8 @@ public void RefreshBranches()
if (_workingCopy != null)
_workingCopy.HasRemotes = remotes.Count > 0;

GetOwnerPage()?.ChangeDirtyState(Models.DirtyState.HasPendingPullOrPush, !CurrentBranch.TrackStatus.IsVisible);
var hasPendingPullOrPush = CurrentBranch?.TrackStatus.IsVisible ?? false;
GetOwnerPage()?.ChangeDirtyState(Models.DirtyState.HasPendingPullOrPush, !hasPendingPullOrPush);
});
}

Expand Down Expand Up @@ -1387,7 +1388,7 @@ public void OpenSubmodule(string submodule)
return;

var root = Path.GetFullPath(Path.Combine(_fullpath, submodule));
var normalizedPath = root.Replace("\\", "/");
var normalizedPath = root.Replace('\\', '/').TrimEnd('/');

var node = Preferences.Instance.FindNode(normalizedPath);
if (node == null)
Expand All @@ -1401,7 +1402,7 @@ public void OpenSubmodule(string submodule)
};
}

App.GetLauncer().OpenRepositoryInTab(node, null);
App.GetLauncher().OpenRepositoryInTab(node, null);
}

public void AddWorktree()
Expand Down Expand Up @@ -1430,7 +1431,7 @@ public void OpenWorktree(Models.Worktree worktree)
};
}

App.GetLauncer()?.OpenRepositoryInTab(node, null);
App.GetLauncher()?.OpenRepositoryInTab(node, null);
}

public List<Models.OpenAIService> GetPreferedOpenAIServices()
Expand Down Expand Up @@ -2588,7 +2589,7 @@ public ContextMenu CreateContextMenuForWorktree(Models.Worktree worktree)

private LauncherPage GetOwnerPage()
{
var launcher = App.GetLauncer();
var launcher = App.GetLauncher();
if (launcher == null)
return null;

Expand Down
8 changes: 4 additions & 4 deletions src/ViewModels/RepositoryNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public string Id
get => _id;
set
{
var normalized = value.Replace('\\', '/');
var normalized = value.Replace('\\', '/').TrimEnd('/');
SetProperty(ref _id, normalized);
}
}
Expand Down Expand Up @@ -70,14 +70,14 @@ public List<RepositoryNode> SubNodes

public void Edit()
{
var activePage = App.GetLauncer().ActivePage;
var activePage = App.GetLauncher().ActivePage;
if (activePage != null && activePage.CanCreatePopup())
activePage.Popup = new EditRepositoryNode(this);
}

public void AddSubFolder()
{
var activePage = App.GetLauncer().ActivePage;
var activePage = App.GetLauncher().ActivePage;
if (activePage != null && activePage.CanCreatePopup())
activePage.Popup = new CreateGroup(this);
}
Expand All @@ -98,7 +98,7 @@ public void OpenTerminal()

public void Delete()
{
var activePage = App.GetLauncer().ActivePage;
var activePage = App.GetLauncher().ActivePage;
if (activePage != null && activePage.CanCreatePopup())
activePage.Popup = new DeleteRepositoryNode(this);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ViewModels/RevisionCompare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void Dispose()

public void NavigateTo(string commitSHA)
{
var launcher = App.GetLauncer();
var launcher = App.GetLauncher();
if (launcher == null)
return;

Expand Down
27 changes: 13 additions & 14 deletions src/ViewModels/ScanRepositories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public override Task<bool> Sure()
watch.Start();

var rootDir = new DirectoryInfo(RootDir);
var founded = new List<FoundRepository>();
GetUnmanagedRepositories(rootDir, founded, new EnumerationOptions()
var found = new List<FoundRepository>();
GetUnmanagedRepositories(rootDir, found, new EnumerationOptions()
{
AttributesToSkip = FileAttributes.Hidden | FileAttributes.System,
IgnoreInaccessible = true,
Expand All @@ -46,11 +46,11 @@ public override Task<bool> Sure()

Dispatcher.UIThread.Invoke(() =>
{
var normalizedRoot = rootDir.FullName.Replace("\\", "/");
var normalizedRoot = rootDir.FullName.Replace('\\', '/').TrimEnd('/');

foreach (var f in founded)
foreach (var f in found)
{
var parent = new DirectoryInfo(f.Path).Parent!.FullName.Replace("\\", "/");
var parent = new DirectoryInfo(f.Path).Parent!.FullName.Replace('\\', '/').TrimEnd('/');
if (parent.Equals(normalizedRoot, StringComparison.Ordinal))
{
Preferences.Instance.FindOrAddNodeByRepositoryPath(f.Path, null, false);
Expand All @@ -64,6 +64,11 @@ public override Task<bool> Sure()
}

Preferences.Instance.AutoRemoveInvalidNode();

// Sort & Save unconditionally after a complete rescan.
Preferences.Instance.SortAllNodes();
Preferences.Instance.Save();

Welcome.Instance.Refresh();
});

Expand Down Expand Up @@ -93,7 +98,7 @@ private void GetUnmanagedRepositories(DirectoryInfo dir, List<FoundRepository> o

CallUIThread(() => ProgressDescription = $"Scanning {subdir.FullName}...");

var normalizedSelf = subdir.FullName.Replace("\\", "/");
var normalizedSelf = subdir.FullName.Replace('\\', '/').TrimEnd('/');
if (_managed.Contains(normalizedSelf))
continue;

Expand All @@ -103,7 +108,7 @@ private void GetUnmanagedRepositories(DirectoryInfo dir, List<FoundRepository> o
var test = new Commands.QueryRepositoryRootPath(subdir.FullName).ReadToEnd();
if (test.IsSuccess && !string.IsNullOrEmpty(test.StdOut))
{
var normalized = test.StdOut.Trim().Replace("\\", "/");
var normalized = test.StdOut.Trim().Replace('\\', '/').TrimEnd('/');
if (!_managed.Contains(normalized))
outs.Add(new FoundRepository(normalized, false));
}
Expand Down Expand Up @@ -151,13 +156,7 @@ private RepositoryNode FindOrCreateGroup(List<RepositoryNode> collection, string
IsExpanded = true,
};
collection.Add(added);
collection.Sort((l, r) =>
{
if (l.IsRepository != r.IsRepository)
return l.IsRepository ? 1 : -1;

return string.Compare(l.Name, r.Name, StringComparison.Ordinal);
});
Preferences.Instance.SortNodes(collection);

return added;
}
Expand Down
Loading
Loading