Esempio n. 1
0
        public void Git_GetRemotes_OneRemoteFetchAndPull_ReturnsRemote()
        {
            string name     = "origin";
            string fetchUrl = "https://fetch.example.com";
            string pushUrl  = "https://push.example.com";
            string repoPath = CreateRepository(out string workDirPath);

            ExecGit(repoPath, workDirPath, $"remote add {name} {fetchUrl}");
            ExecGit(repoPath, workDirPath, $"remote set-url --push {name} {pushUrl}");

            string gitPath = GetGitPath();
            var    trace   = new NullTrace();

            var git = new GitProcess(trace, gitPath, workDirPath);

            GitRemote[] remotes = git.GetRemotes().ToArray();

            Assert.Single(remotes);
            AssertRemote(name, fetchUrl, pushUrl, remotes[0]);
        }
Esempio n. 2
0
        public void GitConfiguration_UnsetAll_UnsetsAllConfig()
        {
            string repoPath = CreateRepository(out string workDirPath);

            ExecGit(repoPath, workDirPath, "config --local --add core.foobar foo1").AssertSuccess();
            ExecGit(repoPath, workDirPath, "config --local --add core.foobar foo2").AssertSuccess();
            ExecGit(repoPath, workDirPath, "config --local --add core.foobar bar1").AssertSuccess();

            string            gitPath = GetGitPath();
            var               trace   = new NullTrace();
            var               env     = new TestEnvironment();
            var               git     = new GitProcess(trace, env, gitPath, repoPath);
            IGitConfiguration config  = git.GetConfiguration();

            config.UnsetAll(GitConfigurationLevel.Local, "core.foobar", "foo*");

            GitResult result = ExecGit(repoPath, workDirPath, "config --local --get-all core.foobar");

            Assert.Equal("bar1", result.StandardOutput.Trim());
        }
Esempio n. 3
0
        public void Git_GetRemotes_RemoteNoFetchOnlyPull_ReturnsRemote()
        {
            string name     = "origin";
            string pushUrl  = "https://example.com";
            string repoPath = CreateRepository(out string workDirPath);

            ExecGit(repoPath, workDirPath, $"remote add {name} {pushUrl}");
            ExecGit(repoPath, workDirPath, $"remote set-url --push {name} {pushUrl}");
            ExecGit(repoPath, workDirPath, $"config --unset --local remote.{name}.url");

            string gitPath = GetGitPath();
            var    trace   = new NullTrace();

            var git = new GitProcess(trace, gitPath, workDirPath);

            GitRemote[] remotes = git.GetRemotes().ToArray();

            Assert.Single(remotes);

            AssertRemote(name, null, pushUrl, remotes[0]);
        }
        public void LibGit2Configuration_Enumerate_CallbackReturnsTrue_InvokesCallbackForEachEntry()
        {
            string repoPath = CreateRepository(out string workDirPath);

            Git(repoPath, workDirPath, "config --local foo.name lancelot").AssertSuccess();
            Git(repoPath, workDirPath, "config --local foo.quest seek-holy-grail").AssertSuccess();
            Git(repoPath, workDirPath, "config --local foo.favcolor blue").AssertSuccess();

            var expectedVisitedEntries = new List <(string name, string value)>
            {
                ("foo.name", "lancelot"),
                ("foo.quest", "seek-holy-grail"),
                ("foo.favcolor", "blue")
            };

            var trace = new NullTrace();
            var git   = new LibGit2(trace);

            using (var config = git.GetConfiguration(repoPath))
            {
                var actualVisitedEntries = new List <(string name, string value)>();

                bool cb(string name, string value)
                {
                    if (name.StartsWith("foo."))
                    {
                        actualVisitedEntries.Add((name, value));
                    }

                    // Continue enumeration
                    return(true);
                }

                config.Enumerate(cb);

                Assert.Equal(expectedVisitedEntries, actualVisitedEntries);
            }
        }
Esempio n. 5
0
        public void GitConfiguration_Enumerate_CallbackReturnsTrue_InvokesCallbackForEachEntry()
        {
            string repoPath = CreateRepository(out string workDirPath);

            ExecGit(repoPath, workDirPath, "config --local foo.name lancelot").AssertSuccess();
            ExecGit(repoPath, workDirPath, "config --local foo.quest seek-holy-grail").AssertSuccess();
            ExecGit(repoPath, workDirPath, "config --local foo.favcolor blue").AssertSuccess();

            var expectedVisitedEntries = new List <(string name, string value)>
            {
                ("foo.name", "lancelot"),
                ("foo.quest", "seek-holy-grail"),
                ("foo.favcolor", "blue")
            };

            string            gitPath = GetGitPath();
            var               trace   = new NullTrace();
            var               env     = new TestEnvironment();
            var               git     = new GitProcess(trace, env, gitPath, repoPath);
            IGitConfiguration config  = git.GetConfiguration();

            var actualVisitedEntries = new List <(string name, string value)>();

            bool cb(GitConfigurationEntry entry)
            {
                if (entry.Key.StartsWith("foo."))
                {
                    actualVisitedEntries.Add((entry.Key, entry.Value));
                }

                // Continue enumeration
                return(true);
            }

            config.Enumerate(cb);

            Assert.Equal(expectedVisitedEntries, actualVisitedEntries);
        }
        public void LibGit2Configuration_GetRepositoryPath_ReturnsRepositoryPath()
        {
            string expectedRepoGitPath = CreateRepository(out string workDirPath) + "/";
            string fileL0Path          = Path.Combine(workDirPath, "file.txt");
            string directoryL0Path     = Path.Combine(workDirPath, "directory");
            string fileL1Path          = Path.Combine(directoryL0Path, "inner-file.txt");
            string directoryL1Path     = Path.Combine(directoryL0Path, "sub-directory");

            var trace = new NullTrace();
            var git   = new LibGit2(trace);

            // Create files and directories
            Directory.CreateDirectory(directoryL0Path);
            Directory.CreateDirectory(directoryL1Path);
            File.WriteAllText(fileL0Path, string.Empty);
            File.WriteAllText(fileL1Path, string.Empty);

            // Check from L0 file
            string fileL0RepoPath = git.GetRepositoryPath(fileL0Path);

            AssertPathsEquivalent(expectedRepoGitPath, fileL0RepoPath);

            // Check from L0 directory
            string dirL0RepoPath = git.GetRepositoryPath(directoryL0Path);

            AssertPathsEquivalent(expectedRepoGitPath, dirL0RepoPath);

            // Check from L1 file
            string fileL1RepoPath = git.GetRepositoryPath(fileL1Path);

            AssertPathsEquivalent(expectedRepoGitPath, fileL1RepoPath);

            // Check from L1 directory
            string dirL1RepoPath = git.GetRepositoryPath(directoryL1Path);

            AssertPathsEquivalent(expectedRepoGitPath, dirL1RepoPath);
        }
        public void AzureReposAuthorityCache_GetAuthority_CachedAuthority_ReturnsAuthority()
        {
            const string orgName           = "contoso";
            string       key               = CreateKey(orgName);
            const string expectedAuthority = "https://login.contoso.com";

            var git = new TestGit
            {
                Configuration =
                {
                    Global =
                    {
                        [key] = new[] { expectedAuthority }
                    }
                }
            };

            var trace = new NullTrace();
            var cache = new AzureDevOpsAuthorityCache(trace, git);

            string actualAuthority = cache.GetAuthority(orgName);

            Assert.Equal(expectedAuthority, actualAuthority);
        }
        public void GitConfiguration_Enumerate_CallbackReturnsFalse_InvokesCallbackForEachEntryUntilReturnsFalse()
        {
            string repoPath = CreateRepository(out string workDirPath);

            Git(repoPath, workDirPath, "config --local foo.name lancelot").AssertSuccess();
            Git(repoPath, workDirPath, "config --local foo.quest seek-holy-grail").AssertSuccess();
            Git(repoPath, workDirPath, "config --local foo.favcolor blue").AssertSuccess();

            var expectedVisitedEntries = new List <(string name, string value)>
            {
                ("foo.name", "lancelot"),
                ("foo.quest", "seek-holy-grail")
            };

            string            gitPath = GetGitPath();
            var               trace   = new NullTrace();
            var               git     = new GitProcess(trace, gitPath, repoPath);
            IGitConfiguration config  = git.GetConfiguration();

            var actualVisitedEntries = new List <(string name, string value)>();

            bool cb(string name, string value)
            {
                if (name.StartsWith("foo."))
                {
                    actualVisitedEntries.Add((name, value));
                }

                // Stop enumeration after 2 'foo' entries
                return(actualVisitedEntries.Count < 2);
            }

            config.Enumerate(cb);

            Assert.Equal(expectedVisitedEntries, actualVisitedEntries);
        }