Esempio n. 1
0
        public void PushChanges()
        {
            string master = GetTempPath();
            using (GitClient git = new GitClient())
            {
                GitInitArgs ia = new GitInitArgs();
                ia.CreateBareRepository = true;
                ia.Description = "Harry & Sally root";

                git.Init(master, ia);
            }

            Uri masterUri = new Uri(master);

            string harry = GetTempPath();
            string sally = GetTempPath();

            using (GitClient git = new GitClient()) // Harry
            {
                git.Clone(masterUri, harry);

                using (GitRepository harryRepo = new GitRepository(harry))
                {
                    harryRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.name", "Harry");
                    harryRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.email", "*****@*****.**");
                }

                string src = Path.Combine(harry, "src");
                Directory.CreateDirectory(src);

                string index = Path.Combine(src, "index.txt");

                File.WriteAllText(index, "This is index.txt\n");

                string appCode = Path.Combine(harry, "app.c");
                File.WriteAllText(appCode, @"
            #include <stdio.h>

            int main(int argc, const char **argv)
            {
            printf(""hello world\n"");
            return 0;
            }
            ");

                git.Add(index);
                git.Add(appCode);
                GitId result;
                GitCommitArgs cma = new GitCommitArgs();
                cma.Signature.When = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                cma.Author.When = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                git.Commit(harry, cma, out result);

                using (GitRepository harryRepo = new GitRepository(harry))
                {
                    GitCommit commit;
                    Assert.That(harryRepo.Lookup(result, out commit));

                    Assert.That(commit.Author.Name, Is.EqualTo("Harry"));
                }
            }

            using (GitClient git = new GitClient()) // Sally
            {
                git.Clone(masterUri, sally);

                using (GitRepository sallyRepo = new GitRepository(sally))
                {
                    sallyRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.name", "Sally");
                    sallyRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.email", "*****@*****.**");
                }

                string src = Path.Combine(sally, "src");
                string index = Path.Combine(src, "index.txt");

                Assert.That(File.Exists(index), Is.False);
            }

            using (GitClient git = new GitClient()) // Harry
            {
                GitPushArgs pa = new GitPushArgs();
                pa.Mode = GitPushMode.All;
                git.Push(harry, pa);
            }

            using (GitClient git = new GitClient()) // Sally
            {
                GitPullArgs pa = new GitPullArgs();
                pa.FetchArgs.All = true;

                git.Pull(sally, pa);

                string src = Path.Combine(sally, "src");
                string index = Path.Combine(src, "index.txt");

                Assert.That(File.Exists(index), Is.True);

                string appCode = Path.Combine(sally, "app.c");
                File.WriteAllText(appCode, @"
            #include <stdio.h>

            int main(int argc, const char **argv)
            {
            int i;

            if (argc != 1)
            {
            fprintf(stderr, ""Usage %s <int>\n"", argv[0]);
            return 1;
            }
            for (i = 0; i < atoi(argv[1]); i++
            printf(""hello world %d\n"", i);

            return 0;
            }
            ");
                git.Add(appCode);

                GitId result;
                GitCommitArgs cma = new GitCommitArgs();
                cma.Signature.When = new DateTime(2000, 1, 2, 0, 0, 0, DateTimeKind.Utc);
                cma.Author.When = new DateTime(2000, 1, 2, 0, 0, 0, DateTimeKind.Utc);
                git.Commit(sally, cma, out result);

                GitPushArgs ph = new GitPushArgs();
                ph.Mode = GitPushMode.All;
                git.Push(sally, ph);
            }

            using (GitClient git = new GitClient()) // Harry
            {
                string appCode = Path.Combine(harry, "app.c");
                File.WriteAllText(appCode, @"
            #include <stdio.h>

            int main(int argc, const char **argv)
            {
            if (argc > 0 && strcmp(argv[1], ""-V"")
            {
            printf(""%s version 1.0 (c) QQn\n"");
            return 0;
            }
            printf(""hello world\n"");
            return 0;
            }
            ");

                git.Add(appCode);

                GitId result;
                GitCommitArgs cma = new GitCommitArgs();
                cma.Signature.When = new DateTime(2000, 1, 3, 0, 0, 0, DateTimeKind.Utc);
                cma.Author.When = new DateTime(2000, 1, 3, 0, 0, 0, DateTimeKind.Utc);
                git.Commit(harry, cma, out result); // Local commit will succeed

                GitPushArgs ph = new GitPushArgs();
                ph.Mode = GitPushMode.All;
                try
                {
                    git.Push(harry, ph); // But push fails, as it conflicts
                    Assert.Fail("Should have failed"); // ###
                }
                catch(GitException ge)
                {
                    Assert.That(ge.Message, Is.StringContaining("Cannot push"));
                }

                GitPullArgs pa = new GitPullArgs();
                pa.FetchArgs.All = true;

                git.Pull(harry, pa);

                bool gotConflict = false;
                git.Status(harry,
                    delegate(object sender, GitStatusEventArgs e)
                    {
                        switch (e.RelativePath)
                        {
                            case "app.c":
                                gotConflict = true;
                                Assert.That(e.WorkingDirectoryStatus, Is.EqualTo(GitStatus.Normal));
                                Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.Normal));
                                Assert.That(e.Conflicted, Is.True, "Conflicted");
                                break;
                            default:
                                Assert.Fail("Unexpected path: {0}", e.RelativePath);
                                break;
                        }
                    });

                Assert.That(gotConflict, "Found conflict status");

                try
                {
                    git.Push(harry, ph); // But push fails, as it conflicts
                    Assert.Fail("Should still fail");
                }
                catch (GitException ge)
                {
                    Assert.That(ge.Message, Is.StringContaining("Cannot push"));
                }

                GitResetArgs ra = new GitResetArgs();
                ra.Mode = GitResetMode.Hard;
                git.Reset(harry, ra);
            }
        }
Esempio n. 2
0
        public void DualStart()
        {
            string master = GetTempPath();

            using (GitClient git = new GitClient())
            {
                GitInitArgs ia = new GitInitArgs();
                ia.CreateBareRepository = true;
                ia.Description          = "Harry & Sally root";

                git.Init(master, ia);
            }

            Uri masterUri = new Uri(master);

            string harry = GetTempPath();
            string sally = GetTempPath();

            using (GitClient git = new GitClient()) // Harry
            {
                git.Clone(masterUri, harry);

                using (GitRepository harryRepo = new GitRepository(harry))
                {
                    harryRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.name", "Harry");
                    harryRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.email", "*****@*****.**");
                }

                string src = Path.Combine(harry, "src");
                Directory.CreateDirectory(src);

                string index = Path.Combine(src, "index.txt");

                File.WriteAllText(index, "This is index.txt\n");

                git.Add(index);
                GitId         result;
                GitCommitArgs cma = new GitCommitArgs();
                cma.Signature.When = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                cma.Author.When    = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                git.Commit(harry, cma, out result);

                using (GitRepository harryRepo = new GitRepository(harry))
                {
                    GitCommit commit;
                    Assert.That(harryRepo.Lookup(result, out commit));

                    Assert.That(commit.Author.Name, Is.EqualTo("Harry"));
                }
            }

            using (GitClient git = new GitClient()) // Sally
            {
                git.Clone(masterUri, sally);

                using (GitRepository sallyRepo = new GitRepository(sally))
                {
                    sallyRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.name", "Sally");
                    sallyRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.email", "*****@*****.**");
                }

                string iota = Path.Combine(sally, "iota.txt");

                File.WriteAllText(iota, "This is iota\n");

                git.Stage(iota);

                GitCommitArgs cma = new GitCommitArgs();
                cma.Signature.When = new DateTime(2001, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                cma.Author.When    = new DateTime(2001, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                git.Commit(sally, cma);

                string src   = Path.Combine(sally, "src");
                string index = Path.Combine(src, "index.txt");

                Assert.That(File.Exists(index), Is.False);
            }

            using (GitClient git = new GitClient()) // Harry
            {
                GitPushArgs pa = new GitPushArgs();
                pa.Mode = GitPushMode.All;
                git.Push(harry, pa);
            }

            using (GitClient git = new GitClient()) // Sally
            {
                GitPullArgs pa = new GitPullArgs();
                pa.FetchArgs.All = true;

                git.Pull(sally, pa);

                string src   = Path.Combine(sally, "src");
                string index = Path.Combine(src, "index.txt");

                Assert.That(File.Exists(index), Is.True);
            }
        }
Esempio n. 3
0
        public void DualStart()
        {
            string master = GetTempPath();
            using (GitClient git = new GitClient())
            {
                GitInitArgs ia = new GitInitArgs();
                ia.CreateBareRepository = true;
                ia.Description = "Harry & Sally root";

                git.Init(master, ia);
            }

            Uri masterUri = new Uri(master);

            string harry = GetTempPath();
            string sally = GetTempPath();

            using (GitClient git = new GitClient()) // Harry
            {
                git.Clone(masterUri, harry);

                using (GitRepository harryRepo = new GitRepository(harry))
                {
                    harryRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.name", "Harry");
                    harryRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.email", "*****@*****.**");
                }

                string src = Path.Combine(harry, "src");
                Directory.CreateDirectory(src);

                string index = Path.Combine(src, "index.txt");

                File.WriteAllText(index, "This is index.txt\n");

                git.Add(index);
                GitId result;
                GitCommitArgs cma = new GitCommitArgs();
                cma.Signature.When = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                cma.Author.When = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                git.Commit(harry, cma, out result);

                using (GitRepository harryRepo = new GitRepository(harry))
                {
                    GitCommit commit;
                    Assert.That(harryRepo.Lookup(result, out commit));

                    Assert.That(commit.Author.Name, Is.EqualTo("Harry"));
                }
            }

            using (GitClient git = new GitClient()) // Sally
            {
                git.Clone(masterUri, sally);

                using (GitRepository sallyRepo = new GitRepository(sally))
                {
                    sallyRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.name", "Sally");
                    sallyRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.email", "*****@*****.**");
                }

                string iota = Path.Combine(sally, "iota.txt");

                File.WriteAllText(iota, "This is iota\n");

                git.Stage(iota);

                GitCommitArgs cma = new GitCommitArgs();
                cma.Signature.When = new DateTime(2001, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                cma.Author.When = new DateTime(2001, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                git.Commit(sally, cma);

                string src = Path.Combine(sally, "src");
                string index = Path.Combine(src, "index.txt");

                Assert.That(File.Exists(index), Is.False);
            }

            using (GitClient git = new GitClient()) // Harry
            {
                GitPushArgs pa = new GitPushArgs();
                pa.Mode = GitPushMode.All;
                git.Push(harry, pa);
            }

            using (GitClient git = new GitClient()) // Sally
            {
                GitPullArgs pa = new GitPullArgs();
                pa.FetchArgs.All = true;

                git.Pull(sally, pa);

                string src = Path.Combine(sally, "src");
                string index = Path.Combine(src, "index.txt");

                Assert.That(File.Exists(index), Is.True);
            }
        }
Esempio n. 4
0
        public void PushChanges()
        {
            string master = GetTempPath();

            using (GitClient git = new GitClient())
            {
                GitInitArgs ia = new GitInitArgs();
                ia.CreateBareRepository = true;
                ia.Description          = "Harry & Sally root";

                git.Init(master, ia);
            }

            Uri masterUri = new Uri(master);

            string harry = GetTempPath();
            string sally = GetTempPath();

            using (GitClient git = new GitClient()) // Harry
            {
                git.Clone(masterUri, harry);

                using (GitRepository harryRepo = new GitRepository(harry))
                {
                    harryRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.name", "Harry");
                    harryRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.email", "*****@*****.**");
                }

                string src = Path.Combine(harry, "src");
                Directory.CreateDirectory(src);

                string index = Path.Combine(src, "index.txt");

                File.WriteAllText(index, "This is index.txt\n");

                string appCode = Path.Combine(harry, "app.c");
                File.WriteAllText(appCode, @"
#include <stdio.h>

int main(int argc, const char **argv)
{
    printf(""hello world\n"");
    return 0;
}
");

                git.Add(index);
                git.Add(appCode);
                GitId         result;
                GitCommitArgs cma = new GitCommitArgs();
                cma.Signature.When = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                cma.Author.When    = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                git.Commit(harry, cma, out result);

                using (GitRepository harryRepo = new GitRepository(harry))
                {
                    GitCommit commit;
                    Assert.That(harryRepo.Lookup(result, out commit));

                    Assert.That(commit.Author.Name, Is.EqualTo("Harry"));
                }
            }

            using (GitClient git = new GitClient()) // Sally
            {
                git.Clone(masterUri, sally);

                using (GitRepository sallyRepo = new GitRepository(sally))
                {
                    sallyRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.name", "Sally");
                    sallyRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.email", "*****@*****.**");
                }

                string src   = Path.Combine(sally, "src");
                string index = Path.Combine(src, "index.txt");

                Assert.That(File.Exists(index), Is.False);
            }

            using (GitClient git = new GitClient()) // Harry
            {
                GitPushArgs pa = new GitPushArgs();
                pa.Mode = GitPushMode.All;
                git.Push(harry, pa);
            }

            using (GitClient git = new GitClient()) // Sally
            {
                GitPullArgs pa = new GitPullArgs();
                pa.FetchArgs.All = true;

                git.Pull(sally, pa);

                string src   = Path.Combine(sally, "src");
                string index = Path.Combine(src, "index.txt");

                Assert.That(File.Exists(index), Is.True);

                string appCode = Path.Combine(sally, "app.c");
                File.WriteAllText(appCode, @"
#include <stdio.h>

int main(int argc, const char **argv)
{
    int i;

    if (argc != 1)
    {
        fprintf(stderr, ""Usage %s <int>\n"", argv[0]);
        return 1;
    }
    for (i = 0; i < atoi(argv[1]); i++
        printf(""hello world %d\n"", i);

    return 0;
}
");
                git.Add(appCode);

                GitId         result;
                GitCommitArgs cma = new GitCommitArgs();
                cma.Signature.When = new DateTime(2000, 1, 2, 0, 0, 0, DateTimeKind.Utc);
                cma.Author.When    = new DateTime(2000, 1, 2, 0, 0, 0, DateTimeKind.Utc);
                git.Commit(sally, cma, out result);

                GitPushArgs ph = new GitPushArgs();
                ph.Mode = GitPushMode.All;
                git.Push(sally, ph);
            }

            using (GitClient git = new GitClient()) // Harry
            {
                string appCode = Path.Combine(harry, "app.c");
                File.WriteAllText(appCode, @"
#include <stdio.h>

int main(int argc, const char **argv)
{
    if (argc > 0 && strcmp(argv[1], ""-V"")
    {
        printf(""%s version 1.0 (c) QQn\n"");
        return 0;
    }
    printf(""hello world\n"");
    return 0;
}
");

                git.Add(appCode);

                GitId         result;
                GitCommitArgs cma = new GitCommitArgs();
                cma.Signature.When = new DateTime(2000, 1, 3, 0, 0, 0, DateTimeKind.Utc);
                cma.Author.When    = new DateTime(2000, 1, 3, 0, 0, 0, DateTimeKind.Utc);
                git.Commit(harry, cma, out result); // Local commit will succeed

                GitPushArgs ph = new GitPushArgs();
                ph.Mode = GitPushMode.All;
                try
                {
                    git.Push(harry, ph);               // But push fails, as it conflicts
                    Assert.Fail("Should have failed"); // ###
                }
                catch (GitException ge)
                {
                    Assert.That(ge.Message, Contains.Substring(/*C*/ "annot push"));
                }

                GitPullArgs pa = new GitPullArgs();
                pa.FetchArgs.All = true;

                git.Pull(harry, pa);

                bool gotConflict = false;
                git.Status(harry,
                           delegate(object sender, GitStatusEventArgs e)
                {
                    switch (e.RelativePath)
                    {
                    case "app.c":
                        gotConflict = true;
                        Assert.That(e.WorkingDirectoryStatus, Is.EqualTo(GitStatus.Normal));
                        Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.Normal));
                        Assert.That(e.Conflicted, Is.True, "Conflicted");
                        break;

                    default:
                        Assert.Fail("Unexpected path: {0}", e.RelativePath);
                        break;
                    }
                });

                Assert.That(gotConflict, "Found conflict status");

                try
                {
                    git.Push(harry, ph); // But push fails, as it conflicts
                    Assert.Fail("Should still fail");
                }
                catch (GitException ge)
                {
                    Assert.That(ge.Message, Contains.Substring(/*C*/ "annot push"));
                }

                GitResetArgs ra = new GitResetArgs();
                ra.Mode = GitResetMode.Hard;
                git.Reset(harry, ra);
            }
        }