public void GetCurrentRevision_should_return_null_if_scriptHostControl_unset_bare_or_empty_repo() { // bare repo has no current checkout, empty repo has no commits _module.GetCurrentCheckout().Returns(x => null); var result = ScriptOptionsParser.GetTestAccessor() .GetCurrentRevision(module: _module, scriptHostControl: null, currentTags: null, currentLocalBranches: null, currentRemoteBranches: null, currentBranches: null); result.Should().Be(null); }
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 void RunScript_with_arguments_with_c_option_without_revision_shall_display_error_and_return_false() { _exampleScript.Command = "cmd"; _exampleScript.Arguments = "/c echo {cHash}"; _module.GetCurrentCheckout().Returns((ObjectId)null); string errorMessage = null; var result = ScriptRunner.RunScript(null, _module, _keyOfExampleScript, uiCommands: null, revisionGrid: null, error => errorMessage = error); result.Should().BeEquivalentTo(new CommandStatus(executed: false, needsGridRefresh: false)); errorMessage.Should().Be($"There must be a revision in order to substitute the argument option(s) for the script to run."); }
public void RunScript_with_arguments_with_c_option_without_revision_shall_display_error_and_return_false() { _exampleScript.Command = "cmd"; _exampleScript.Arguments = "/c echo {cHash}"; _module.GetCurrentCheckout().Returns((ObjectId)null); var ex = ((Action)(() => ExecuteRunScript(null, _module, _keyOfExampleScript, uiCommands: null, revisionGrid: null))).Should() .Throw <UserExternalOperationException>(); ex.And.Context.Should().Be($"Script: '{_keyOfExampleScript}'\r\nA valid revision is required to substitute the argument options"); ex.And.Command.Should().Be(_exampleScript.Command); ex.And.Arguments.Should().Be(_exampleScript.Arguments); ex.And.WorkingDirectory.Should().Be(_module.WorkingDir); }
private static GitRevision GetCurrentRevision( IGitModule module, [CanBeNull] RevisionGridControl revisionGrid, List <IGitRef> currentTags, List <IGitRef> currentLocalBranches, List <IGitRef> currentRemoteBranches, List <IGitRef> currentBranches, [CanBeNull] GitRevision currentRevision) { if (currentRevision == null) { IEnumerable <IGitRef> refs; if (revisionGrid == null) { var currentRevisionGuid = module.GetCurrentCheckout(); currentRevision = new GitRevision(currentRevisionGuid); refs = module.GetRefs(true, true).Where(gitRef => gitRef.ObjectId == currentRevisionGuid).ToList(); } else { currentRevision = revisionGrid.GetCurrentRevision(); refs = currentRevision.Refs; } foreach (var gitRef in refs) { if (gitRef.IsTag) { currentTags.Add(gitRef); } else if (gitRef.IsHead || gitRef.IsRemote) { currentBranches.Add(gitRef); if (gitRef.IsRemote) { currentRemoteBranches.Add(gitRef); } else { currentLocalBranches.Add(gitRef); } } } } return(currentRevision); }
private static GitRevision GetCurrentRevision( [NotNull] IGitModule module, [CanBeNull] IScriptHostControl scriptHostControl, List <IGitRef> currentTags, List <IGitRef> currentLocalBranches, List <IGitRef> currentRemoteBranches, List <IGitRef> currentBranches) { GitRevision currentRevision; IEnumerable <IGitRef> refs; if (scriptHostControl == null) { var currentRevisionGuid = module.GetCurrentCheckout(); currentRevision = currentRevisionGuid == null ? null : new GitRevision(currentRevisionGuid); refs = module.GetRefs(true, true).Where(gitRef => gitRef.ObjectId == currentRevisionGuid); } else { currentRevision = scriptHostControl.GetCurrentRevision(); refs = currentRevision?.Refs ?? Array.Empty <IGitRef>(); } foreach (var gitRef in refs) { if (gitRef.IsTag) { currentTags.Add(gitRef); } else if (gitRef.IsHead || gitRef.IsRemote) { currentBranches.Add(gitRef); if (gitRef.IsRemote) { currentRemoteBranches.Add(gitRef); } else { currentLocalBranches.Add(gitRef); } } } return(currentRevision); }