Exemplo n.º 1
0
        public void GetSortedTags_should_throw_on_git_warning()
        {
            _gitExecutable.StageOutput("for-each-ref --sort=-taggerdate --format=\"%(refname)\" refs/tags/",
                                       "refs/heads/master\nwarning: message");

            ((Action)(() => _commitInfo.GetTestAccessor().GetSortedTags())).Should().Throw <RefsWarningException>();
        }
Exemplo n.º 2
0
        public void SetUp()
        {
            if (_referenceRepository == null)
            {
                _referenceRepository = new ReferenceRepository();
            }
            else
            {
                _referenceRepository.Reset();
            }

            _commands = new GitUICommands(_referenceRepository.Module);

            // mock git executable
            _gitExecutable = new MockExecutable();
            typeof(GitModule).GetField("_gitExecutable", BindingFlags.Instance | BindingFlags.NonPublic)
            .SetValue(_commands.Module, _gitExecutable);
            var cmdRunner = new GitCommandRunner(_gitExecutable, () => GitModule.SystemEncoding);

            typeof(GitModule).GetField("_gitCommandRunner", BindingFlags.Instance | BindingFlags.NonPublic)
            .SetValue(_commands.Module, cmdRunner);

            var uiCommandsSource = Substitute.For <IGitUICommandsSource>();

            uiCommandsSource.UICommands.Returns(x => _commands);

            // the following assignment of _commitInfo.UICommandsSource will already call this command
            _gitExecutable.StageOutput("for-each-ref --sort=-taggerdate --format=\"%(refname)\" refs/tags/", "");

            _commitInfo = new GitUI.CommitInfo.CommitInfo
            {
                UICommandsSource = uiCommandsSource
            };
        }
Exemplo n.º 3
0
        private IDisposable MockupGitOutput(string output, string encodedUrl = DummyUrlEncoded)
        {
            var gitArguments = new GitArgumentBuilder("ls-remote")
            {
                "--heads", encodedUrl
            };

            return(_gitExecutable.StageOutput(gitArguments.ToString(), output));
        }
Exemplo n.º 4
0
        public async Task Validate_GetRevisionCommitSignatureStatusAsync(CommitStatus expected, string gitCmdReturn)
        {
            var objectId = ObjectId.Random();

            var revision = new GitRevision(objectId);
            var args     = new GitArgumentBuilder("log")
            {
                "--pretty=\"format:%G?\"",
                "-1",
                revision.Guid
            };

            using var _ = _executable.StageOutput(args.ToString(), gitCmdReturn);

            var actual = await _gpgController.GetRevisionCommitSignatureStatusAsync(revision);

            Assert.AreEqual(expected, actual);
        }
        public void GetOutput_with_cache_miss()
        {
            const string arguments     = "abc";
            const string commandOutput = "Hello World!";

            // Empty cache
            CommandCache cache = new();

            using (_executable.StageOutput(arguments, commandOutput))
            {
                var output = _executable.GetOutput(arguments, cache: cache);

                Assert.AreEqual(commandOutput, output);
            }

            // Validate data stored in cache afterwards
            Assert.AreEqual(1, cache.GetCachedCommands().Count);
            Assert.IsTrue(cache.TryGet(arguments, out var outputBytes, out var errorBytes));
            Assert.AreEqual(GitModule.SystemEncoding.GetBytes(commandOutput), outputBytes);
            Assert.IsEmpty(errorBytes);
        }