private Repository GetClient(ISourceControlConnectionSettingsSource settings) { var repositoryFolder = GetLocalRepository(settings); if (IsRepositoryUriChanged(repositoryFolder, settings)) { repositoryFolder.Delete(); repositoryFolder = MercurialRepositoryFolder.Create(settings.Uri); _folder.ReplaceWith(repositoryFolder); } Repository repository; try { if (repositoryFolder.Exists()) { string path = repositoryFolder.GetAbsolutePath(); repository = new Repository(path, new NonPersistentClientFactory()); repository.Pull(settings.Uri); } else { string path = repositoryFolder.GetAbsolutePath(); Directory.CreateDirectory(path); CloneCommand cloneCommand = new CloneCommand().WithUpdate(false); repository = new Repository(path, new NonPersistentClientFactory()); repository.Clone(settings.Uri, cloneCommand); } } catch (ArgumentNullException e) { throw new ArgumentException( MercurialCheckConnectionErrorResolver.INVALID_URI_OR_INSUFFICIENT_ACCESS_RIGHTS_ERROR_MESSAGE, e); } catch (FileNotFoundException e) { throw new ArgumentException( MercurialCheckConnectionErrorResolver.INVALID_URI_OR_INSUFFICIENT_ACCESS_RIGHTS_ERROR_MESSAGE, e); } catch (MercurialMissingException e) { throw new ArgumentException( MercurialCheckConnectionErrorResolver.MERCURIAL_IS_NOT_INSTALLED_ERROR_MESSAGE, e); } return(repository); }
private MercurialRepositoryFolder GetLocalRepository(ISourceControlConnectionSettingsSource settings) { if (_folder.Empty()) { var repositoryFolder = MercurialRepositoryFolder.Create(settings.Uri); _folder.ReplaceWith(repositoryFolder); return(repositoryFolder); } MercurialRepositoryFolder folder = _folder.Single(); if (!folder.CheckFolder(_folder)) { var repositoryFolder = MercurialRepositoryFolder.Create(settings.Uri); _folder.ReplaceWith(repositoryFolder); return(repositoryFolder); } return(folder); }