mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-23 10:22:13 +08:00
style<Repository>: normalize repository's path
This commit is contained in:
@@ -66,17 +66,15 @@ namespace SourceGit {
|
||||
|
||||
public static void RaiseException(string context, string message) {
|
||||
if (Current is App app && app._notificationReceiver != null) {
|
||||
var ctx = context.Replace('\\', '/');
|
||||
var notice = new Models.Notification() { IsError = true, Message = message };
|
||||
app._notificationReceiver.OnReceiveNotification(ctx, notice);
|
||||
app._notificationReceiver.OnReceiveNotification(context, notice);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SendNotification(string context, string message) {
|
||||
if (Current is App app && app._notificationReceiver != null) {
|
||||
var ctx = context.Replace('\\', '/');
|
||||
var notice = new Models.Notification() { IsError = false, Message = message };
|
||||
app._notificationReceiver.OnReceiveNotification(ctx, notice);
|
||||
app._notificationReceiver.OnReceiveNotification(context, notice);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -89,8 +89,8 @@ namespace SourceGit.ViewModels {
|
||||
CallUIThread(() => {
|
||||
var repo = Preference.AddRepository(path, Path.Combine(path, ".git"));
|
||||
var node = new RepositoryNode() {
|
||||
Id = path,
|
||||
Name = Path.GetFileName(path),
|
||||
Id = repo.FullPath,
|
||||
Name = Path.GetFileName(repo.FullPath),
|
||||
Bookmark = 0,
|
||||
IsRepository = true,
|
||||
};
|
||||
|
||||
@@ -25,8 +25,8 @@ namespace SourceGit.ViewModels {
|
||||
CallUIThread(() => {
|
||||
var repo = Preference.AddRepository(_targetPath, gitDir);
|
||||
var node = new RepositoryNode() {
|
||||
Id = _targetPath,
|
||||
Name = Path.GetFileName(_targetPath),
|
||||
Id = repo.FullPath,
|
||||
Name = Path.GetFileName(repo.FullPath),
|
||||
Bookmark = 0,
|
||||
IsRepository = true,
|
||||
};
|
||||
|
||||
@@ -209,23 +209,22 @@ namespace SourceGit.ViewModels {
|
||||
}
|
||||
|
||||
public static Repository FindRepository(string path) {
|
||||
var dir = new DirectoryInfo(path);
|
||||
foreach (var repo in _instance.Repositories) {
|
||||
if (repo.FullPath == dir.FullName) return repo;
|
||||
if (repo.FullPath == path) return repo;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Repository AddRepository(string rootDir, string gitDir) {
|
||||
var repo = FindRepository(rootDir);
|
||||
var normalized = rootDir.Replace('\\', '/');
|
||||
var repo = FindRepository(normalized);
|
||||
if (repo != null) {
|
||||
repo.GitDir = gitDir;
|
||||
return repo;
|
||||
}
|
||||
|
||||
var dir = new DirectoryInfo(rootDir);
|
||||
repo = new Repository() {
|
||||
FullPath = dir.FullName,
|
||||
FullPath = normalized,
|
||||
GitDir = gitDir
|
||||
};
|
||||
|
||||
|
||||
@@ -12,7 +12,14 @@ namespace SourceGit.ViewModels {
|
||||
public class Repository : ObservableObject, Models.IRepository {
|
||||
public string FullPath {
|
||||
get => _fullpath;
|
||||
set => SetProperty(ref _fullpath, value);
|
||||
set {
|
||||
if (value != null) {
|
||||
var normalized = value.Replace('\\', '/');
|
||||
SetProperty(ref _fullpath, normalized);
|
||||
} else {
|
||||
SetProperty(ref _fullpath, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GitDir {
|
||||
@@ -1009,8 +1016,8 @@ namespace SourceGit.ViewModels {
|
||||
var gitDir = new Commands.QueryGitDir(root).Result();
|
||||
var repo = Preference.AddRepository(root, gitDir);
|
||||
var node = new RepositoryNode() {
|
||||
Id = root,
|
||||
Name = Path.GetFileName(root),
|
||||
Id = repo.FullPath,
|
||||
Name = Path.GetFileName(repo.FullPath),
|
||||
Bookmark = 0,
|
||||
IsRepository = true,
|
||||
};
|
||||
|
||||
@@ -6,7 +6,10 @@ namespace SourceGit.ViewModels {
|
||||
public class RepositoryNode : ObservableObject {
|
||||
public string Id {
|
||||
get => _id;
|
||||
set => SetProperty(ref _id, value);
|
||||
set {
|
||||
var normalized = value.Replace('\\', '/');
|
||||
SetProperty(ref _id, normalized);
|
||||
}
|
||||
}
|
||||
|
||||
public string Name {
|
||||
|
||||
@@ -192,8 +192,8 @@ namespace SourceGit.Views {
|
||||
Dispatcher.UIThread.Invoke(() => {
|
||||
var repo = ViewModels.Preference.AddRepository(root, gitDir);
|
||||
var node = new ViewModels.RepositoryNode() {
|
||||
Id = root,
|
||||
Name = Path.GetFileName(root),
|
||||
Id = repo.FullPath,
|
||||
Name = Path.GetFileName(repo.FullPath),
|
||||
Bookmark = 0,
|
||||
IsRepository = true,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user