public void RepoNameExtractorTest_ValidCurrentRemote(string remote, string url, string expProject, string expRepo) { _module.GetCurrentRemote().Returns(x => remote); _module.GetRemotes().Returns(x => new[] { remote, " ", "\t" }); _module.GetSetting(string.Format(SettingKeyString.RemoteUrl, remote)).Returns(x => url); _repoNameExtractor.Get(out string project, out string repo); project.Should().Be(expProject); repo.Should().Be(expRepo); }
public void LoadRemotes_should_not_populate_remotes_if_none() { _module.GetRemotes().Returns(x => Enumerable.Empty <string>()); _controller.LoadRemotes(true); _controller.Remotes.Count.Should().Be(0); _module.Received(1).GetRemotes(); _module.DidNotReceive().GetSetting(Arg.Any <string>()); _module.DidNotReceive().GetSettings(Arg.Any <string>()); }
/// <summary> /// Returns all relevant github-remotes for the current working directory /// </summary> /// <returns></returns> public List <IHostedRemote> GetHostedRemotesForModule(IGitModule aModule) { var repoInfos = new List <IHostedRemote>(); string[] remotes = aModule.GetRemotes(false); foreach (string remote in remotes) { var url = aModule.GetISetting(string.Format(SettingKeyString.RemoteUrl, remote)); if (string.IsNullOrEmpty(url)) { continue; } var m = Regex.Match(url, @"git(?:@|://)github.com[:/]([^/]+)/([\w_\.\-]+)\.git"); if (!m.Success) { m = Regex.Match(url, @"https?://(?:[^@:]+)?(?::[^/@:]+)?@?github.com/([^/]+)/([\w_\.\-]+)(?:.git)?"); } if (m.Success) { var hostedRemote = new GithubHostedRemote(remote, m.Groups[1].Value, m.Groups[2].Value.Replace(".git", "")); if (!repoInfos.Contains(hostedRemote)) { repoInfos.Add(hostedRemote); } } } return(repoInfos); }
/// <summary> /// Loads the remotes from the .git/config. /// </summary> // TODO: candidate for Async implementations public void LoadRemotes() { if (_module == null) { return; } lock (SyncRoot) { Remotes.Clear(); var gitRemotes = _module.GetRemotes().Where(x => !string.IsNullOrWhiteSpace(x)).ToList(); if (gitRemotes.Any()) { var remotes = gitRemotes.Select(remote => new GitRemote { Name = remote, Url = _module.GetSetting(string.Format(SettingKeyString.RemoteUrl, remote)), Push = _module.GetSettings(string.Format(SettingKeyString.RemotePush, remote)).ToList(), PushUrl = _module.GetSetting(string.Format(SettingKeyString.RemotePushUrl, remote)), PuttySshKey = _module.GetSetting(string.Format(SettingKeyString.RemotePuttySshKey, remote)), }).ToList(); Remotes.AddAll(remotes.OrderBy(x => x.Name)); } } }
private bool IsValid() { if ( string.IsNullOrEmpty(Host) && string.IsNullOrEmpty(Project) ) { return(false); } var remotes = Module.GetRemotes(true); return(remotes.Contains(DefaultRemote)); }
private void Validate() { if (string.IsNullOrEmpty(Host)) { throw new GerritSettingsException(_settingsErrorHostNotEntered.Text); } if (string.IsNullOrEmpty(Project)) { throw new GerritSettingsException(_settingsErrorProjectNotEntered.Text); } var remotes = Module.GetRemotes(true); if (!remotes.Contains(DefaultRemote)) { throw new GerritSettingsException(String.Format(_settingsErrorDefaultRemoteNotPresent.Text, DefaultRemote)); } }
/// <summary> /// Returns all relevant github-remotes for the current working directory /// </summary> /// <returns></returns> public List<IHostedRemote> GetHostedRemotesForModule(IGitModule aModule) { var repoInfos = new List<IHostedRemote>(); string[] remotes = aModule.GetRemotes(false); foreach (string remote in remotes) { var url = aModule.GetSetting(string.Format(SettingKeyString.RemoteUrl, remote)); if (string.IsNullOrEmpty(url)) continue; var m = Regex.Match(url, @"git(?:@|://)github.com[:/]([^/]+)/([\w_\.\-]+)\.git"); if (!m.Success) m = Regex.Match(url, @"https?://(?:[^@:]+)?(?::[^/@:]+)?@?github.com/([^/]+)/([\w_\.\-]+)(?:.git)?"); if (m.Success) { var hostedRemote = new GithubHostedRemote(remote, m.Groups[1].Value, m.Groups[2].Value.Replace(".git", "")); if (!repoInfos.Contains(hostedRemote)) repoInfos.Add(hostedRemote); } } return repoInfos; }