private void GetRemotes(List <GitRemote> allRemotes, bool enabled) { Func <string[]> func; if (enabled) { func = _module.GetRemotes; } else { func = GetDisabledRemotes; } var gitRemotes = func().Where(x => !string.IsNullOrWhiteSpace(x)).ToList(); if (gitRemotes.Any()) { allRemotes.AddRange(gitRemotes.Select(remote => new GitRemote { Disabled = !enabled, Name = remote, Url = _module.GetSetting(GetSettingKey(SettingKeyString.RemoteUrl, remote, enabled)), Push = _module.GetSettings(GetSettingKey(SettingKeyString.RemotePush, remote, enabled)).ToList(), PushUrl = _module.GetSetting(GetSettingKey(SettingKeyString.RemotePushUrl, remote, enabled)), PuttySshKey = _module.GetSetting(GetSettingKey(SettingKeyString.RemotePuttySshKey, remote, enabled)), })); } }
/// <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)); } } }
public static (string argument, bool abort) Parse(string argument, IGitModule module, IWin32Window owner, RevisionGridControl revisionGrid) { GitRevision selectedRevision = null; GitRevision currentRevision = null; IReadOnlyList <GitRevision> allSelectedRevisions = Array.Empty <GitRevision>(); var selectedLocalBranches = new List <IGitRef>(); var selectedRemoteBranches = new List <IGitRef>(); var selectedRemotes = new List <string>(); var selectedBranches = new List <IGitRef>(); var selectedTags = new List <IGitRef>(); var currentLocalBranches = new List <IGitRef>(); var currentRemoteBranches = new List <IGitRef>(); var currentRemote = ""; var currentBranches = new List <IGitRef>(); var currentTags = new List <IGitRef>(); foreach (string option in Options) { if (string.IsNullOrEmpty(argument) || !argument.Contains(option)) { continue; } if (option.StartsWith("{c") && currentRevision == null) { currentRevision = GetCurrentRevision(module, revisionGrid, currentTags, currentLocalBranches, currentRemoteBranches, currentBranches, currentRevision); if (currentLocalBranches.Count == 1) { currentRemote = module.GetSetting(string.Format(SettingKeyString.BranchRemote, currentLocalBranches[0].Name)); } else { currentRemote = module.GetCurrentRemote(); if (string.IsNullOrEmpty(currentRemote)) { currentRemote = module.GetSetting(string.Format(SettingKeyString.BranchRemote, AskToSpecify(currentLocalBranches, revisionGrid))); } } } else if (option.StartsWith("{s") && selectedRevision == null && revisionGrid != null) { allSelectedRevisions = revisionGrid.GetSelectedRevisions(); selectedRevision = CalculateSelectedRevision(revisionGrid, selectedRemoteBranches, selectedRemotes, selectedLocalBranches, selectedBranches, selectedTags); } argument = ParseScriptArguments(argument, option, owner, revisionGrid, module, allSelectedRevisions, selectedTags, selectedBranches, selectedLocalBranches, selectedRemoteBranches, selectedRemotes, selectedRevision, currentTags, currentBranches, currentLocalBranches, currentRemoteBranches, currentRevision, currentRemote); if (argument == null) { return(argument : null, abort : true); } } return(argument, abort : false); }
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 static (string?arguments, bool abort) Parse(string?arguments, IGitModule module, IWin32Window owner, IScriptHostControl?scriptHostControl) { if (string.IsNullOrWhiteSpace(arguments)) { return(arguments, abort : false); } module = module ?? throw new ArgumentNullException(nameof(module)); GitRevision?selectedRevision = null; GitRevision?currentRevision = null; IReadOnlyList <GitRevision> allSelectedRevisions = Array.Empty <GitRevision>(); List <IGitRef> selectedLocalBranches = new(); List <IGitRef> selectedRemoteBranches = new(); List <string> selectedRemotes = new(); List <IGitRef> selectedBranches = new(); List <IGitRef> selectedTags = new(); List <IGitRef> currentLocalBranches = new(); List <IGitRef> currentRemoteBranches = new(); var currentRemote = ""; List <IGitRef> currentBranches = new(); List <IGitRef> currentTags = new(); foreach (string option in Options) { if (!Contains(arguments, option)) { continue; } if (currentRevision is null && option.StartsWith("c")) { currentRevision = GetCurrentRevision(module, currentTags, currentLocalBranches, currentRemoteBranches, currentBranches, loadBody: Contains(arguments, currentMessage)); if (currentRevision is null) { return(arguments : null, abort : true); } if (currentLocalBranches.Count == 1) { currentRemote = module.GetSetting(string.Format(SettingKeyString.BranchRemote, currentLocalBranches[0].Name)); } else { currentRemote = module.GetCurrentRemote(); if (string.IsNullOrEmpty(currentRemote)) { currentRemote = module.GetSetting(string.Format(SettingKeyString.BranchRemote, AskToSpecify(currentLocalBranches, scriptHostControl))); } } }
public void ParseScriptArguments_resolve_cDefaultRemotePathFromUrl_currentRemote_set() { var currentRemote = "myRemote"; _module.GetSetting(string.Format(SettingKeyString.RemoteUrl, currentRemote)).Returns("https://gitlab.com/gitlabhq/gitlabhq.git"); var result = ScriptOptionsParser.GetTestAccessor().ParseScriptArguments( arguments: "{openUrl} https://gitlab.com{cDefaultRemotePathFromUrl}/tree/{sBranch}", option: "cDefaultRemotePathFromUrl", owner: null, scriptHostControl: null, _module, allSelectedRevisions: null, selectedTags: null, selectedBranches: null, selectedLocalBranches: null, selectedRemoteBranches: null, selectedRemotes: null, selectedRevision: null, currentTags: null, currentBranches: null, currentLocalBranches: null, currentRemoteBranches: null, currentRevision: null, currentRemote); result.Should().Be("{openUrl} https://gitlab.com/gitlabhq/gitlabhq/tree/{sBranch}"); }
/// <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); }
public void ScriptOptionsParser_resolve_cDefaultRemotePathFromUrl_currentRemote_set() { var currentRemote = "myRemote"; _module.GetSetting(string.Format(SettingKeyString.RemoteUrl, currentRemote)).Returns("https://gitlab.com/gitlabhq/gitlabhq.git"); var result = ScriptOptionsParser.GetTestAccessor().ParseScriptArguments("{openUrl} https://gitlab.com{cDefaultRemotePathFromUrl}/tree/{sBranch}", "cDefaultRemotePathFromUrl", null, null, _module, null, null, null, null, null, null, null, null, null, null, null, null, currentRemote); result.Should().Be("{openUrl} https://gitlab.com/gitlabhq/gitlabhq/tree/{sBranch}"); }
public void InitializeConfiguredParameters(IGitModule gitModule) { var firstRemoteName = gitModule.GetRemoteNames().FirstOrDefault(); var url = gitModule.GetSetting(string.Format(SettingKeyString.RemoteUrl, firstRemoteName)); var remoteHost = !string.IsNullOrEmpty(url) ? new Uri(url).Host : DefaultGitLabHost; var gitLabHostParsed = $"https://{remoteHost}"; GitLabClient = new Client.Client( gitLabHostParsed, Instance.OAuthToken.ValueOrDefault(Instance.Settings)); AskForMergeRequestAfterPushValue = AskForMergeRequestAfterPush.ValueOrDefault(Settings); }
/// <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; }
public static (string arguments, bool abort) Parse([CanBeNull] string arguments, [NotNull] IGitModule module, IWin32Window owner, IScriptHostControl scriptHostControl) { if (string.IsNullOrWhiteSpace(arguments)) { return(arguments, abort : false); } module = module ?? throw new ArgumentNullException(nameof(module)); GitRevision selectedRevision = null; GitRevision currentRevision = null; IReadOnlyList <GitRevision> allSelectedRevisions = Array.Empty <GitRevision>(); var selectedLocalBranches = new List <IGitRef>(); var selectedRemoteBranches = new List <IGitRef>(); var selectedRemotes = new List <string>(); var selectedBranches = new List <IGitRef>(); var selectedTags = new List <IGitRef>(); var currentLocalBranches = new List <IGitRef>(); var currentRemoteBranches = new List <IGitRef>(); var currentRemote = ""; var currentBranches = new List <IGitRef>(); var currentTags = new List <IGitRef>(); foreach (string option in Options) { if (!Contains(arguments, option)) { continue; } if (currentRevision == null && option.StartsWith("c")) { currentRevision = GetCurrentRevision(module, scriptHostControl, currentTags, currentLocalBranches, currentRemoteBranches, currentBranches); if (currentRevision == null) { return(arguments : null, abort : true); } if (currentLocalBranches.Count == 1) { currentRemote = module.GetSetting(string.Format(SettingKeyString.BranchRemote, currentLocalBranches[0].Name)); } else { currentRemote = module.GetCurrentRemote(); if (string.IsNullOrEmpty(currentRemote)) { currentRemote = module.GetSetting(string.Format(SettingKeyString.BranchRemote, AskToSpecify(currentLocalBranches, scriptHostControl))); } } } else if (selectedRevision == null && scriptHostControl != null && DependsOnSelectedRevision(option)) { allSelectedRevisions = scriptHostControl.GetSelectedRevisions() ?? Array.Empty <GitRevision>(); selectedRevision = CalculateSelectedRevision(scriptHostControl, selectedRemoteBranches, selectedRemotes, selectedLocalBranches, selectedBranches, selectedTags); if (selectedRevision == null) { return(arguments : null, abort : true); } } arguments = ParseScriptArguments(arguments, option, owner, scriptHostControl, module, allSelectedRevisions, selectedTags, selectedBranches, selectedLocalBranches, selectedRemoteBranches, selectedRemotes, selectedRevision, currentTags, currentBranches, currentLocalBranches, currentRemoteBranches, currentRevision, currentRemote); if (arguments == null) { return(arguments : null, abort : true); } } return(arguments, abort : false); }