Exemplo n.º 1
0
        public void CanFetchCustomRefSpecsIntoAnEmptyRepository(string url, string localBranchName, string remoteBranchName)
        {
            string path = InitNewRepository();

            using (var repo = new Repository(path))
            {
                Remote remote = repo.Network.Remotes.Add(remoteName, url);

                string refSpec = string.Format("refs/heads/{2}:refs/remotes/{0}/{1}", remoteName, localBranchName, remoteBranchName);

                // Set up structures for the expected results
                // and verifying the RemoteUpdateTips callback.
                TestRemoteInfo remoteInfo         = TestRemoteInfo.TestRemoteInstance;
                var            expectedFetchState = new ExpectedFetchState(remoteName);
                expectedFetchState.AddExpectedBranch(localBranchName, ObjectId.Zero, remoteInfo.BranchTips[remoteBranchName]);

                // Perform the actual fetch
                repo.Network.Fetch(remote, new string[] { refSpec }, new FetchOptions {
                    TagFetchMode = TagFetchMode.None,
                    OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler
                });

                // Verify the expected
                expectedFetchState.CheckUpdatedReferences(repo);

                // Verify the reflog entries
                var reflogEntry = repo.Refs.Log(string.Format("refs/remotes/{0}/{1}", remoteName, localBranchName)).Single();
                Assert.True(reflogEntry.Message.StartsWith("fetch "));
            }
        }
Exemplo n.º 2
0
        public void CanFetchAllTagsIntoAnEmptyRepository(string url)
        {
            var scd = BuildSelfCleaningDirectory();

            using (var repo = Repository.Init(scd.RootedDirectoryPath))
            {
                Remote remote = repo.Network.Remotes.Add(remoteName, url);

                // Set up structures for the expected results
                // and verifying the RemoteUpdateTips callback.
                TestRemoteInfo remoteInfo         = TestRemoteInfo.TestRemoteInstance;
                var            expectedFetchState = new ExpectedFetchState(remoteName);

                // Add expected tags only as no branches are expected to be fetched
                foreach (KeyValuePair <string, TestRemoteInfo.ExpectedTagInfo> kvp in remoteInfo.Tags)
                {
                    expectedFetchState.AddExpectedTag(kvp.Key, ObjectId.Zero, kvp.Value);
                }

                // Perform the actual fetch
                repo.Network.Fetch(remote, TagFetchMode.All, onUpdateTips: expectedFetchState.RemoteUpdateTipsHandler);

                // Verify the expected
                expectedFetchState.CheckUpdatedReferences(repo);
            }
        }
Exemplo n.º 3
0
        public void CanFetchAllTagsIntoAnEmptyRepository(string url)
        {
            using (var repo = InitIsolatedRepository())
            {
                Remote remote = repo.Network.Remotes.Add(remoteName, url);

                // Set up structures for the expected results
                // and verifying the RemoteUpdateTips callback.
                TestRemoteInfo remoteInfo         = TestRemoteInfo.TestRemoteInstance;
                var            expectedFetchState = new ExpectedFetchState(remoteName);

                // Add expected tags only as no branches are expected to be fetched
                foreach (KeyValuePair <string, TestRemoteInfo.ExpectedTagInfo> kvp in remoteInfo.Tags)
                {
                    expectedFetchState.AddExpectedTag(kvp.Key, ObjectId.Zero, kvp.Value);
                }

                // Perform the actual fetch
                repo.Network.Fetch(remote, new FetchOptions {
                    TagFetchMode = TagFetchMode.All,
                    OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler
                });

                // Verify the expected
                expectedFetchState.CheckUpdatedReferences(repo);

                // Verify the reflog entries
                Assert.Equal(0, repo.Refs.Log(string.Format("refs/remotes/{0}/master", remoteName)).Count()); // Only tags are retrieved
            }
        }
Exemplo n.º 4
0
        public void CanFetchIntoAnEmptyRepository(string url)
        {
            var scd = BuildSelfCleaningDirectory();

            using (var repo = Repository.Init(scd.RootedDirectoryPath))
            {
                Remote remote = repo.Network.Remotes.Add(remoteName, url);

                // Set up structures for the expected results
                // and verifying the RemoteUpdateTips callback.
                TestRemoteInfo expectedResults    = TestRemoteInfo.TestRemoteInstance;
                var            expectedFetchState = new ExpectedFetchState(remoteName);

                // Add expected branch objects
                foreach (KeyValuePair <string, ObjectId> kvp in expectedResults.BranchTips)
                {
                    expectedFetchState.AddExpectedBranch(kvp.Key, ObjectId.Zero, kvp.Value);
                }

                // Add the expected tags
                string[] expectedTagNames = { "blob", "commit_tree", "annotated_tag" };
                foreach (string tagName in expectedTagNames)
                {
                    TestRemoteInfo.ExpectedTagInfo expectedTagInfo = expectedResults.Tags[tagName];
                    expectedFetchState.AddExpectedTag(tagName, ObjectId.Zero, expectedTagInfo);
                }

                // Perform the actual fetch
                repo.Network.Fetch(remote, onUpdateTips: expectedFetchState.RemoteUpdateTipsHandler);

                // Verify the expected
                expectedFetchState.CheckUpdatedReferences(repo);
            }
        }
        public void CustomSmartSubtransportTest(string scheme, string url)
        {
            string remoteName = "testRemote";

            var scd      = BuildSelfCleaningDirectory();
            var repoPath = Repository.Init(scd.RootedDirectoryPath);

            SmartSubtransportRegistration <MockSmartSubtransport> registration = null;

            try
            {
                // Disable server certificate validation for testing.
                // Do *NOT* enable this in production.
                ServicePointManager.ServerCertificateValidationCallback = certificateValidationCallback;

                registration = GlobalSettings.RegisterSmartSubtransport <MockSmartSubtransport>(scheme);
                Assert.NotNull(registration);

                using (var repo = new Repository(repoPath))
                {
                    repo.Network.Remotes.Add(remoteName, url);

                    // Set up structures for the expected results
                    // and verifying the RemoteUpdateTips callback.
                    TestRemoteInfo     expectedResults    = TestRemoteInfo.TestRemoteInstance;
                    ExpectedFetchState expectedFetchState = new ExpectedFetchState(remoteName);

                    // Add expected branch objects
                    foreach (KeyValuePair <string, ObjectId> kvp in expectedResults.BranchTips)
                    {
                        expectedFetchState.AddExpectedBranch(kvp.Key, ObjectId.Zero, kvp.Value);
                    }

                    // Add the expected tags
                    string[] expectedTagNames = { "blob", "commit_tree", "annotated_tag" };
                    foreach (string tagName in expectedTagNames)
                    {
                        TestRemoteInfo.ExpectedTagInfo expectedTagInfo = expectedResults.Tags[tagName];
                        expectedFetchState.AddExpectedTag(tagName, ObjectId.Zero, expectedTagInfo);
                    }

                    // Perform the actual fetch
                    Commands.Fetch(repo, remoteName, new string[0],
                                   new FetchOptions {
                        OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler, TagFetchMode = TagFetchMode.Auto
                    },
                                   null);

                    // Verify the expected
                    expectedFetchState.CheckUpdatedReferences(repo);
                }
            }
            finally
            {
                GlobalSettings.UnregisterSmartSubtransport(registration);

                ServicePointManager.ServerCertificateValidationCallback -= certificateValidationCallback;
            }
        }
Exemplo n.º 6
0
        public void CanFetchFromRemoteByName()
        {
            string remoteName = "testRemote";
            string url        = "http://github.com/libgit2/TestGitRepository";

            string repoPath = InitNewRepository();

            using (var repo = new Repository(repoPath))
            {
                Remote remote = repo.Network.Remotes.Add(remoteName, url);

                // We will first fetch without specifying any Tag options.
                // After we verify this fetch, we will perform a second fetch
                // where we will download all tags, and verify that the
                // nearly-dangling tag is now present.

                // Set up structures for the expected results
                // and verifying the RemoteUpdateTips callback.
                TestRemoteInfo     remoteInfo         = TestRemoteInfo.TestRemoteInstance;
                ExpectedFetchState expectedFetchState = new ExpectedFetchState(remoteName);

                // Add expected branch objects
                foreach (KeyValuePair <string, ObjectId> kvp in remoteInfo.BranchTips)
                {
                    expectedFetchState.AddExpectedBranch(kvp.Key, ObjectId.Zero, kvp.Value);
                }

                // Add the expected tags
                string[] expectedTagNames = { "blob", "commit_tree", "annotated_tag" };
                foreach (string tagName in expectedTagNames)
                {
                    TestRemoteInfo.ExpectedTagInfo expectedTagInfo = remoteInfo.Tags[tagName];
                    expectedFetchState.AddExpectedTag(tagName, ObjectId.Zero, expectedTagInfo);
                }

                // Perform the actual fetch
                repo.Fetch(remote.Name, new FetchOptions {
                    OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler
                });

                // Verify the expected state
                expectedFetchState.CheckUpdatedReferences(repo);

                // Now fetch the rest of the tags
                repo.Fetch(remote.Name, new FetchOptions {
                    TagFetchMode = TagFetchMode.All
                });

                // Verify that the "nearly-dangling" tag is now in the repo.
                Tag nearlyDanglingTag = repo.Tags["nearly-dangling"];
                Assert.NotNull(nearlyDanglingTag);
                Assert.Equal(remoteInfo.Tags["nearly-dangling"].TargetId, nearlyDanglingTag.Target.Id);
            }
        }
        public void CanUseCredentials(string scheme, string url, string user, string pass)
        {
            string remoteName = "testRemote";

            var scd = BuildSelfCleaningDirectory();

            Repository.Init(scd.RootedDirectoryPath);

            SmartSubtransportRegistration <MockSmartSubtransport> registration = null;

            try
            {
                // Disable server certificate validation for testing.
                // Do *NOT* enable this in production.
                ServicePointManager.ServerCertificateValidationCallback = certificateValidationCallback;

                registration = GlobalSettings.RegisterSmartSubtransport <MockSmartSubtransport>(scheme);
                Assert.NotNull(registration);

                using (var repo = new Repository(scd.DirectoryPath))
                {
                    repo.Network.Remotes.Add(remoteName, url);

                    // Set up structures for the expected results
                    // and verifying the RemoteUpdateTips callback.
                    TestRemoteInfo     expectedResults    = TestRemoteInfo.TestRemoteInstance;
                    ExpectedFetchState expectedFetchState = new ExpectedFetchState(remoteName);

                    // Add expected branch objects
                    foreach (KeyValuePair <string, ObjectId> kvp in expectedResults.BranchTips)
                    {
                        expectedFetchState.AddExpectedBranch(kvp.Key, ObjectId.Zero, kvp.Value);
                    }

                    // Perform the actual fetch
                    Commands.Fetch(repo, remoteName, new string[0], new FetchOptions {
                        OnUpdateTips        = expectedFetchState.RemoteUpdateTipsHandler, TagFetchMode = TagFetchMode.Auto,
                        CredentialsProvider = (_user, _valid, _hostname) => new UsernamePasswordCredentials()
                        {
                            Username = user, Password = pass
                        },
                    }, null);

                    // Verify the expected
                    expectedFetchState.CheckUpdatedReferences(repo);
                }
            }
            finally
            {
                GlobalSettings.UnregisterSmartSubtransport(registration);

                ServicePointManager.ServerCertificateValidationCallback -= certificateValidationCallback;
            }
        }
Exemplo n.º 8
0
        public void CanFetchCustomRefSpecsIntoAnEmptyRepository(string url, string localBranchName, string remoteBranchName)
        {
            string path = InitNewRepository();

            using (var repo = new Repository(path))
            {
                repo.Network.Remotes.Add(remoteName, url);

                string refSpec = string.Format("refs/heads/{2}:refs/remotes/{0}/{1}", remoteName, localBranchName, remoteBranchName);

                // Set up structures for the expected results
                // and verifying the RemoteUpdateTips callback.
                TestRemoteInfo remoteInfo         = TestRemoteInfo.TestRemoteInstance;
                var            expectedFetchState = new ExpectedFetchState(remoteName);
                expectedFetchState.AddExpectedBranch(localBranchName, ObjectId.Zero, remoteInfo.BranchTips[remoteBranchName]);

                // Let's account for opportunistic updates during the Fetch() call
                if (!string.Equals("master", localBranchName, StringComparison.OrdinalIgnoreCase))
                {
                    expectedFetchState.AddExpectedBranch("master", ObjectId.Zero, remoteInfo.BranchTips["master"]);
                }

                if (string.Equals("master", localBranchName, StringComparison.OrdinalIgnoreCase) &&
                    !string.Equals("master", remoteBranchName, StringComparison.OrdinalIgnoreCase))
                {
                    expectedFetchState.AddExpectedBranch(remoteBranchName, ObjectId.Zero, remoteInfo.BranchTips[remoteBranchName]);
                }

                // Perform the actual fetch
                Commands.Fetch(repo, remoteName, new string[] { refSpec }, new FetchOptions {
                    TagFetchMode = TagFetchMode.None,
                    OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler
                }, null);

                // Verify the expected
                expectedFetchState.CheckUpdatedReferences(repo);

                // Verify the reflog entries
                var reflogEntry = repo.Refs.Log(string.Format("refs/remotes/{0}/{1}", remoteName, localBranchName)).Single();
                Assert.StartsWith("fetch ", reflogEntry.Message);
            }
        }
Exemplo n.º 9
0
        public void CanFetchAllTagsIntoAnEmptyRepository(string url)
        {
            string path = InitNewRepository();

            using (var repo = new Repository(path))
            {
                repo.Network.Remotes.Add(remoteName, url);

                // Set up structures for the expected results
                // and verifying the RemoteUpdateTips callback.
                TestRemoteInfo remoteInfo         = TestRemoteInfo.TestRemoteInstance;
                var            expectedFetchState = new ExpectedFetchState(remoteName);

                // Add expected tags
                foreach (KeyValuePair <string, TestRemoteInfo.ExpectedTagInfo> kvp in remoteInfo.Tags)
                {
                    expectedFetchState.AddExpectedTag(kvp.Key, ObjectId.Zero, kvp.Value);
                }

                // Add expected branch objects
                foreach (KeyValuePair <string, ObjectId> kvp in remoteInfo.BranchTips)
                {
                    expectedFetchState.AddExpectedBranch(kvp.Key, ObjectId.Zero, kvp.Value);
                }

                // Perform the actual fetch
                Commands.Fetch(repo, remoteName, new string[0], new FetchOptions {
                    TagFetchMode = TagFetchMode.All,
                    OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler
                }, null);

                // Verify the expected
                expectedFetchState.CheckUpdatedReferences(repo);

                // Verify the reflog entries
                Assert.Equal(1, repo.Refs.Log(string.Format("refs/remotes/{0}/master", remoteName)).Count()); // Branches are also retrieved
            }
        }
Exemplo n.º 10
0
        public void CanFetchIntoAnEmptyRepository(string url)
        {
            string path = InitNewRepository();

            using (var repo = new Repository(path))
            {
                repo.Network.Remotes.Add(remoteName, url);

                // Set up structures for the expected results
                // and verifying the RemoteUpdateTips callback.
                TestRemoteInfo expectedResults    = TestRemoteInfo.TestRemoteInstance;
                var            expectedFetchState = new ExpectedFetchState(remoteName);

                // Add expected branch objects
                foreach (KeyValuePair <string, ObjectId> kvp in expectedResults.BranchTips)
                {
                    expectedFetchState.AddExpectedBranch(kvp.Key, ObjectId.Zero, kvp.Value);
                }

                // Add the expected tags
                string[] expectedTagNames = { "blob", "commit_tree", "annotated_tag" };
                foreach (string tagName in expectedTagNames)
                {
                    TestRemoteInfo.ExpectedTagInfo expectedTagInfo = expectedResults.Tags[tagName];
                    expectedFetchState.AddExpectedTag(tagName, ObjectId.Zero, expectedTagInfo);
                }

                // Perform the actual fetch
                Commands.Fetch(repo, remoteName, new string[0], new FetchOptions {
                    OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler
                }, null);

                // Verify the expected
                expectedFetchState.CheckUpdatedReferences(repo);
            }
        }