Exemplo n.º 1
0
        public void ClonePublic()
        {
            string repos = GetTempPath();
            using (GitClient git = new GitClient())
            {
                GitCloneArgs ca = new GitCloneArgs();
                ca.Synchronous = true;

                git.Clone(new Uri("https://github.com/libgit2/TestGitRepository.git"), repos, ca);

                List<string> found = new List<string>();

                GitStatusArgs sa = new GitStatusArgs();
                sa.IncludeUnmodified = true;
                sa.UseGlobPath = true;

                git.Status(repos, sa,
                    delegate(object sender, GitStatusEventArgs e)
                    {
                        found.Add(e.RelativePath);
                    });

                Assert.That(found.Count, Is.EqualTo(8));
                Assert.That(found, Is.All.Not.Null);
                Assert.That(found, Is.Unique);

                found.Clear();

                git.Status(repos + "/a/*", sa,
                    delegate(object sender, GitStatusEventArgs e)
                    {
                        found.Add(e.RelativePath);
                    });

                Assert.That(found.Count, Is.EqualTo(3));
                Assert.That(found, Is.All.Not.Null);
                Assert.That(found, Is.Unique);

                GitFetchArgs fa = new GitFetchArgs();
                fa.All = true;
                git.Fetch(repos, fa);

                using (GitRepository repo = new GitRepository(repos))
                {
                    Assert.That(repo.HeadBranch, Is.Not.Null);

                    Assert.That(repo.HeadBranch.Name, Is.EqualTo("refs/heads/master"));
                    Assert.That(repo.HeadBranch.UpstreamReference, Is.Not.Null);
                    Assert.That(repo.HeadBranch.UpstreamReference.Name, Is.EqualTo("refs/remotes/origin/master"));
                    Assert.That(repo.HeadBranch.IsHead, "Head knows that it is head");
                    //Assert.That(repo.HeadBranch.TrackedBranch, Is.Null);

                    Assert.That(repo.HeadBranch.Name, Is.EqualTo("refs/heads/master"));
                    Assert.That(repo.HeadBranch.IsRemote, Is.False, "Local branch");
                    Assert.That(repo.HeadBranch.RemoteName, Is.EqualTo("origin"));

                    foreach (GitBranch b in repo.Branches.Remote)
                    {
                        Assert.That(b.IsRemote, "Remote branch");
                        Assert.That(b.IsLocal, Is.False, "Not local");
                        Assert.That(b.Name, Is.StringStarting("refs/remotes/origin/"));
                        Assert.That(b.IsHead, Is.False);
                        Assert.That(b.UpstreamReference, Is.Null);
                        Assert.That(b.LocalUpstreamName, Is.Null);
                        Assert.That(b.RemoteName, Is.EqualTo("origin"));
                    }

                    foreach (GitBranch b in repo.Branches.Local)
                    {
                        Assert.That(b.IsLocal, "Local branch");
                        Assert.That(b.IsRemote, Is.False, "Not remote");
                        Assert.That(b.Name, Is.StringStarting("refs/").Or.EqualTo("master"));
                        Assert.That(b.IsHead, Is.EqualTo(b.ShortName == "master"));
                        Assert.That(b.RemoteName, Is.EqualTo("origin"));
                        if (!b.IsHead)
                        {
                            Assert.That(b.LocalUpstreamName, Is.Not.Null);

                            GitBranch tracked = b.TrackedBranch;
                            Assert.That(tracked, Is.Not.Null, "Have tracked");

                            Assert.That(b.RemoteName, Is.Not.Null);
                        }
                    }

                    foreach (GitRemote r in repo.Remotes)
                    {
                        Assert.That(r.Name, Is.Not.Null);
                        Assert.That(r.TagSynchronize, Is.EqualTo(GitTagSynchronize.Auto));
                        //Assert.That(r.Save(new GitFetchArgs()));

                        foreach (GitRefSpec rs in r.FetchRefSpecs)
                        {

                        }

                        foreach (GitRefSpec rs in r.PushRefSpecs)
                        {

                        }
                    }
                }

                git.Pull(repos);

                // libgit2's local push code only supports bare repositories at
                // this time, so we use a few more clones to test the real push

                string cloneDir = GetTempPath();
                GitCloneArgs cca = new GitCloneArgs();
                cca.InitArgs.CreateBareRepository = true;
                git.Clone(repos, cloneDir, cca);

                string clone2Dir = GetTempPath();

                git.Clone(cloneDir, clone2Dir);

                GitPushArgs pa = new GitPushArgs();
                pa.Mode = GitPushMode.All;
                git.Push(clone2Dir, pa);
            }
        }
Exemplo n.º 2
0
        public void ClonePublic()
        {
            string repos = GetTempPath();

            using (GitClient git = new GitClient())
            {
                GitCloneArgs ca = new GitCloneArgs();
                ca.Synchronous = true;

                git.Clone(new Uri("https://github.com/libgit2/TestGitRepository.git"), repos, ca);

                List <string> found = new List <string>();

                GitStatusArgs sa = new GitStatusArgs();
                sa.IncludeUnmodified = true;
                sa.UseGlobPath       = true;

                git.Status(repos, sa,
                           delegate(object sender, GitStatusEventArgs e)
                {
                    found.Add(e.RelativePath);
                });

                Assert.That(found.Count, Is.EqualTo(8));
                Assert.That(found, Is.All.Not.Null);
                Assert.That(found, Is.Unique);

                found.Clear();

                git.Status(repos + "/a/*", sa,
                           delegate(object sender, GitStatusEventArgs e)
                {
                    found.Add(e.RelativePath);
                });

                Assert.That(found.Count, Is.EqualTo(3));
                Assert.That(found, Is.All.Not.Null);
                Assert.That(found, Is.Unique);

                GitFetchArgs fa = new GitFetchArgs();
                fa.All = true;
                git.Fetch(repos, fa);

                using (GitRepository repo = new GitRepository(repos))
                {
                    Assert.That(repo.HeadBranch, Is.Not.Null);

                    Assert.That(repo.HeadBranch.Name, Is.EqualTo("refs/heads/master"));
                    Assert.That(repo.HeadBranch.UpstreamReference, Is.Not.Null);
                    Assert.That(repo.HeadBranch.UpstreamReference.Name, Is.EqualTo("refs/remotes/origin/master"));
                    Assert.That(repo.HeadBranch.IsHead, "Head knows that it is head");
                    //Assert.That(repo.HeadBranch.TrackedBranch, Is.Null);

                    Assert.That(repo.HeadBranch.Name, Is.EqualTo("refs/heads/master"));
                    Assert.That(repo.HeadBranch.IsRemote, Is.False, "Local branch");
                    Assert.That(repo.HeadBranch.RemoteName, Is.EqualTo("origin"));

                    foreach (GitBranch b in repo.Branches.Remote)
                    {
                        Assert.That(b.IsRemote, "Remote branch");
                        Assert.That(b.IsLocal, Is.False, "Not local");
                        Assert.That(b.Name, Is.SubPathOf("refs/remotes/origin/"));
                        Assert.That(b.IsHead, Is.False);
                        Assert.That(b.UpstreamReference, Is.Null);
                        Assert.That(b.LocalUpstreamName, Is.Null);
                        Assert.That(b.RemoteName, Is.EqualTo("origin"));
                    }

                    foreach (GitBranch b in repo.Branches.Local)
                    {
                        Assert.That(b.IsLocal, "Local branch");
                        Assert.That(b.IsRemote, Is.False, "Not remote");
                        Assert.That(b.Name, Is.SubPathOf("refs/").Or.EqualTo("master"));
                        Assert.That(b.IsHead, Is.EqualTo(b.ShortName == "master"));
                        Assert.That(b.RemoteName, Is.EqualTo("origin"));
                        if (!b.IsHead)
                        {
                            Assert.That(b.LocalUpstreamName, Is.Not.Null);

                            GitBranch tracked = b.TrackedBranch;
                            Assert.That(tracked, Is.Not.Null, "Have tracked");

                            Assert.That(b.RemoteName, Is.Not.Null);
                        }
                    }

                    foreach (GitRemote r in repo.Remotes)
                    {
                        Assert.That(r.Name, Is.Not.Null);
                        Assert.That(r.TagSynchronize, Is.EqualTo(GitTagSynchronize.Auto));
                        //Assert.That(r.Save(new GitFetchArgs()));

                        foreach (GitRefSpec rs in r.FetchRefSpecs)
                        {
                        }

                        foreach (GitRefSpec rs in r.PushRefSpecs)
                        {
                        }
                    }
                }

                git.Pull(repos);

                // libgit2's local push code only supports bare repositories at
                // this time, so we use a few more clones to test the real push

                string       cloneDir = GetTempPath();
                GitCloneArgs cca      = new GitCloneArgs();
                cca.InitArgs.CreateBareRepository = true;
                git.Clone(repos, cloneDir, cca);

                string clone2Dir = GetTempPath();

                git.Clone(cloneDir, clone2Dir);

                GitPushArgs pa = new GitPushArgs();
                pa.Mode = GitPushMode.All;
                git.Push(clone2Dir, pa);
            }
        }