mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07:00
style<Repository>: normalize repository's path
This commit is contained in:
parent
1c005983c7
commit
e3a7abe776
7 changed files with 26 additions and 19 deletions
|
@ -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,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue