Example #1
0
        private IDisposable MockupGitOutput(string output, string encodedUrl = DummyUrlEncoded)
        {
            var gitArguments = new GitArgumentBuilder("ls-remote")
            {
                "--heads", encodedUrl
            };

            return(_gitExecutable.StageOutput(gitArguments.ToString(), output));
        }
        public void Validate_GetTagVerifyMessage(int usefulTagRefNumber, string expected)
        {
            var         objectId = ObjectId.Random();
            GitRevision revision = new(objectId);

            IDisposable validate = null;

            switch (usefulTagRefNumber)
            {
            case 0:
            {
                // Tag but not dereference
                GitRef gitRef = new(_module, objectId, "refs/tags/TagName");
                revision.Refs = new[] { gitRef };

                break;
            }

            case 1:
            {
                // One tag that's also IsDereference == true
                GitRef gitRef = new(_module, objectId, "refs/tags/TagName^{}");
                revision.Refs = new[] { gitRef };

                GitArgumentBuilder args = new("verify-tag") { gitRef.LocalName };
                validate = _executable.StageOutput(args.ToString(), gitRef.LocalName);

                break;
            }

            case 2:
            {
                // Two tag that's also IsDereference == true
                GitRef gitRef1 = new(_module, objectId, "refs/tags/FirstTag^{}");

                GitArgumentBuilder args = new("verify-tag") { gitRef1.LocalName };
                _executable.StageOutput(args.ToString(), gitRef1.LocalName);

                GitRef gitRef2 = new(_module, objectId, "refs/tags/SecondTag^{}");
                revision.Refs = new[] { gitRef1, gitRef2 };

                args = new GitArgumentBuilder("verify-tag")
                {
                    gitRef2.LocalName
                };
                validate = _executable.StageOutput(args.ToString(), gitRef2.LocalName);

                break;
            }
            }

            var actual = _gpgController.GetTagVerifyMessage(revision);

            Assert.AreEqual(expected, actual);

            validate?.Dispose();
        }
        public void Command_with_custom_config_item_already_quoted()
        {
            var args = new GitArgumentBuilder("foo")
            {
                new GitConfigItem("bar", "\"baz bax\"")
            };

            Assert.AreEqual(
                "-c bar=\"baz bax\" foo",
                args.ToString());
        }
        public void Command_with_custom_config_item()
        {
            var args = new GitArgumentBuilder("foo")
            {
                new GitConfigItem("bar", "baz")
            };

            Assert.AreEqual(
                "-c bar=baz foo",
                args.ToString());
        }
        public void Command_with_default_config_item()
        {
            var args = new GitArgumentBuilder("log")
            {
                "-n 1"
            };

            Assert.AreEqual(
                "-c log.showSignature=false log -n 1",
                args.ToString());
        }
        public void Command_with_custom_config_item_defined_after_argument()
        {
            var args = new GitArgumentBuilder("foo")
            {
                "--arg",
                new GitConfigItem("bar", "baz") // order doesn't matter
            };

            Assert.AreEqual(
                "-c bar=baz foo --arg",
                args.ToString());
        }
        public void Command_with_config_item_that_overrides_default_different_case()
        {
            var args = new GitArgumentBuilder("log")
            {
                new GitConfigItem("LOG.showSIGNATURE", "true"),
                "-n 1"
            };

            Assert.AreEqual(
                "-c LOG.showSIGNATURE=true log -n 1",
                args.ToString());
        }
        public void Command_with_config_item_that_overrides_default()
        {
            var args = new GitArgumentBuilder("log")
            {
                new GitConfigItem("log.showSignature", "true"),
                "-n 1"
            };

            Assert.AreEqual(
                "-c log.showSignature=true log -n 1",
                args.ToString());
        }
        public void Command_with_default_and_custom_config_items_and_argument()
        {
            var args = new GitArgumentBuilder("log")
            {
                new GitConfigItem("bar", "baz"),
                "-n 1"
            };

            Assert.AreEqual(
                "-c log.showSignature=false -c bar=baz log -n 1",
                args.ToString());
        }
Example #10
0
        public void Validate_GetCommitVerificationMessage(string returnString)
        {
            var objectId = ObjectId.Random();
            var revision = new GitRevision(objectId);
            var args     = new GitArgumentBuilder("log")
            {
                "--pretty=\"format:%GG\"",
                "-1",
                revision.Guid
            };

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

            var actual = _gpgController.GetCommitVerificationMessage(revision);

            Assert.AreEqual(returnString, actual);
        }
Example #11
0
        public void GetParents_calls_correct_command_and_parses_response()
        {
            var args = new GitArgumentBuilder("log")
            {
                "-n 1",
                "--format=format:%P",
                Sha1
            };

            using (_executable.StageOutput(
                       args.ToString(),
                       $"{Sha2} {Sha3}"))
            {
                var parents = _gitModule.GetParents(Sha1);

                Assert.AreEqual(parents, new[] { Sha2, Sha3 });
            }
        }
Example #12
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);
        }
Example #13
0
        public void Validate_GetCommitVerificationMessage(string returnString)
        {
            var objectId = ObjectId.Random();
            var revision = new GitRevision(objectId);
            var args     = new GitArgumentBuilder("log")
            {
                "--pretty=\"format:%GG\"",
                "-1",
                revision.Guid
            };

            _module().RunGitCmd(Arg.Is <ArgumentString>(arg => arg.Arguments.Equals(args.ToString())))
            .Returns(x => returnString);

            var actual = _gpgController.GetCommitVerificationMessage(revision);

            Assert.AreEqual(returnString, actual);
        }
Example #14
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
            };

            _module().RunGitCmd(Arg.Is <ArgumentString>(arg => arg.ToString().Equals(args.ToString())))
            .Returns(x => gitCmdReturn);

            var actual = await _gpgController.GetRevisionCommitSignatureStatusAsync(revision);

            Assert.AreEqual(expected, actual);
        }
Example #15
0
        public async Task Validate_GetRevisionTagSignatureStatusAsync_one_tag(TagStatus tagStatus, string gitCmdReturn)
        {
            var objectId = ObjectId.Random();

            var gitRef = new GitRef(_module, objectId, "refs/tags/FirstTag^{}");

            var revision = new GitRevision(objectId)
            {
                Refs = new[] { gitRef }
            };
            var args = new GitArgumentBuilder("verify-tag")
            {
                "--raw",
                gitRef.LocalName
            };

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

            var actual = await _gpgController.GetRevisionTagSignatureStatusAsync(revision);

            Assert.AreEqual(tagStatus, actual);
        }