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 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 Setup() { if (_referenceRepository == null) { _referenceRepository = new ReferenceRepository(); } else { _referenceRepository.Reset(); } _uiCommands = new GitUICommands(_referenceRepository.Module); _module = Substitute.For <IVsrModule>(); _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 }
private static GitRevision GetCurrentRevision( [NotNull] IVsrModule 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); }