public void RepoNameExtractorTest_ValidCurrentRemote(string remote, string url, string expProject, string expRepo) { _module.GetCurrentRemote().Returns(x => remote); _module.GetRemoteNames().Returns(x => new[] { remote, " ", "\t" }); _module.GetSetting(string.Format(SettingKeyString.RemoteUrl, remote)).Returns(x => url); var(project, repo) = _repoNameExtractor.Get(); project.Should().Be(expProject); repo.Should().Be(expRepo); }
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}"); }
public static (string arguments, bool abort) Parse([CanBeNull] string arguments, [NotNull] IVsrModule 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); }