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 Setup()
        {
            if (_referenceRepository is null)
            {
                _referenceRepository = new ReferenceRepository();
            }
            else
            {
                _referenceRepository.Reset();
            }

            _uiCommands = new GitUICommands(_referenceRepository.Module);

            _module = Substitute.For <IGitModule>();
            _module.GetCurrentRemote().ReturnsForAnyArgs("origin");
            _module.GetCurrentCheckout().ReturnsForAnyArgs(ObjectId.WorkTreeId);
            _exampleScript = ScriptManager.GetScript(_keyOfExampleScript);
            _exampleScript.AskConfirmation = false; // avoid any dialogs popping up
            _exampleScript.RunInBackground = true;  // avoid any dialogs popping up

            if (_miRunScript is null)
            {
                throw new InvalidOperationException();
            }
        }
        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);
        }
Exemple #4
0
        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 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);
        }