Check the following conditions:
- Local repository exists at path
- Local repository has an 'origin' remote
- Local repository's URL matches selected repository
This commit is contained in:
Jamie Cansdale 2018-09-26 13:48:57 +01:00
Родитель 3172217b3f
Коммит 527b1d134f
4 изменённых файлов: 55 добавлений и 2 удалений

Просмотреть файл

@ -17,6 +17,7 @@ namespace GitHub.SampleData.Dialog.Clone
public string Path { get; set; }
public string PathError { get; set; }
public string PathWarning { get; set; }
public int SelectedTabIndex { get; set; }
public string Title => null;
public IObservable<object> Done => null;

Просмотреть файл

@ -23,12 +23,14 @@ namespace GitHub.ViewModels.Dialog.Clone
readonly IOperatingSystem os;
readonly IConnectionManager connectionManager;
readonly IRepositoryCloneService service;
readonly IGitService gitService;
readonly IUsageService usageService;
readonly IUsageTracker usageTracker;
readonly IReadOnlyList<IRepositoryCloneTabViewModel> tabs;
string path;
IRepositoryModel previousRepository;
ObservableAsPropertyHelper<string> pathError;
ObservableAsPropertyHelper<string> pathWarning;
int selectedTabIndex;
[ImportingConstructor]
@ -36,6 +38,7 @@ namespace GitHub.ViewModels.Dialog.Clone
IOperatingSystem os,
IConnectionManager connectionManager,
IRepositoryCloneService service,
IGitService gitService,
IUsageService usageService,
IUsageTracker usageTracker,
IRepositorySelectViewModel gitHubTab,
@ -45,6 +48,7 @@ namespace GitHub.ViewModels.Dialog.Clone
this.os = os;
this.connectionManager = connectionManager;
this.service = service;
this.gitService = gitService;
this.usageService = usageService;
this.usageTracker = usageTracker;
@ -62,9 +66,15 @@ namespace GitHub.ViewModels.Dialog.Clone
pathError = Observable.CombineLatest(
repository,
this.WhenAnyValue(x => x.Path),
ValidatePath)
ValidatePathError)
.ToProperty(this, x => x.PathError);
pathWarning = Observable.CombineLatest(
repository,
this.WhenAnyValue(x => x.Path),
ValidatePathWarning)
.ToProperty(this, x => x.PathWarning);
var canClone = Observable.CombineLatest(
repository, this.WhenAnyValue(x => x.Path), this.WhenAnyValue(x => x.PathError),
(repo, path, error) => repo != null && error == null && !service.DestinationDirectoryExists(path));
@ -94,6 +104,8 @@ namespace GitHub.ViewModels.Dialog.Clone
public string PathError => pathError.Value;
public string PathWarning => pathWarning.Value;
public int SelectedTabIndex
{
get => selectedTabIndex;
@ -235,7 +247,7 @@ namespace GitHub.ViewModels.Dialog.Clone
}
}
string ValidatePath(IRepositoryModel repository, string path)
string ValidatePathError(IRepositoryModel repository, string path)
{
if (repository != null)
{
@ -246,5 +258,36 @@ namespace GitHub.ViewModels.Dialog.Clone
return null;
}
string ValidatePathWarning(IRepositoryModel repositoryModel, string path)
{
if (repositoryModel != null)
{
if (service.DestinationDirectoryExists(path))
{
using (var repository = gitService.GetRepository(path))
{
if (repository == null)
{
return $"Can't find a repository at local path";
}
var localUrl = gitService.GetRemoteUri(repository)?.ToRepositoryUrl();
if (localUrl == null)
{
return $"Local repository doesn't have an 'origin' remote";
}
var targetUrl = repositoryModel.CloneUrl?.ToRepositoryUrl();
if (localUrl != targetUrl)
{
return $"Local repository has a remote of {localUrl}";
}
}
}
}
return null;
}
}
}

Просмотреть файл

@ -34,6 +34,11 @@ namespace GitHub.ViewModels.Dialog.Clone
/// </summary>
string PathError { get; }
/// <summary>
/// Gets a warning message that explains why <see cref="Path"/> is suspect.
/// </summary>
string PathWarning { get; }
/// <summary>
/// Gets the index of the selected tab.
/// </summary>

Просмотреть файл

@ -55,6 +55,10 @@
<TextBox Text="{Binding Path, UpdateSourceTrigger=PropertyChanged}"/>
</DockPanel>
<ghfvs:InfoPanel Message="{Binding PathWarning}"
DockPanel.Dock="Bottom"
Margin="0"/>
<TabControl SelectedIndex="{Binding SelectedTabIndex}"
Style="{StaticResource LightModalViewTabControl}">
<TabItem Header="GitHub.com"