Пример #1
0
        public void Visit()
        {
            var repoBuilder = new RepoBuilder(@"c:\temp\");
            var git         = repoBuilder.BuildEmptyRepo();

            repoBuilder.AddFile(@"FeatureVolvo\car.txt", "car");
            repoBuilder.AddFile(@"FeatureGarden\tree.txt", "tree");
            repoBuilder.AddFile(@"FeatureGarden\shovel.txt", "shovel");
            repoBuilder.AddFile(@"FeatureGarden\Suburb\grass.txt", "grass");
            string buf = "";

            git.FileSystemScanFolder(git.CodeFolder).Visit(x =>
            {
                if (x is TreeTreeLine t)
                {
                    buf += $"visittree {t.Path}\r\n";
                }
                if (x is BlobTreeLine b)
                {
                    buf += $"visitblob {b.Path}\r\n";
                }
            });

            Assert.Equal(@"visittree 
visittree FeatureGarden
visitblob FeatureGarden\shovel.txt
visitblob FeatureGarden\tree.txt
visittree FeatureGarden\Suburb
visitblob FeatureGarden\Suburb\grass.txt
visittree FeatureVolvo
visitblob FeatureVolvo\car.txt
", buf);
        }
Пример #2
0
        public void Get_folders_and_files()
        {
            var repoBuilder = new RepoBuilder(@"c:\temp\");
            var git         = repoBuilder.BuildEmptyRepo();

            repoBuilder.AddFile(@"FeatureVolvo\car.txt", "car");
            repoBuilder.AddFile(@"FeatureGarden\tree.txt", "tree");
            repoBuilder.AddFile(@"FeatureGarden\shovel.txt", "shovel");
            repoBuilder.AddFile(@"FeatureGarden\Suburb\grass.txt", "grass");
            repoBuilder.AddFile(@"FeatureGarden\Suburb\mover.txt", "mover");

            var files = FileSystemScanFolder(git);

            Assert.Equal(
                @"tree 2 
tree 3 FeatureGarden
blob FeatureGarden\shovel.txt
blob FeatureGarden\tree.txt
tree 2 FeatureGarden\Suburb
blob FeatureGarden\Suburb\grass.txt
blob FeatureGarden\Suburb\mover.txt
tree 1 FeatureVolvo
blob FeatureVolvo\car.txt"
                , files);
        }
Пример #3
0
        public void When_committing_Then_set_parent_to_previous_head()
        {
            var parentId = repoBuilder.EmptyRepo().AddFile("a.txt").Commit();

            var commitId = repoBuilder.AddFile("a.txt").Commit();

            Assert.Equal(parentId, repoBuilder.Git.Hd.Commits[commitId].Parents.First());
        }
Пример #4
0
        public void Given_two_toplevel_files_Then_()
        {
            repoBuilder = new RepoBuilder(@"c:\temp\");
            var git = repoBuilder.BuildEmptyRepo();

            repoBuilder.AddFile("car.txt", "car");
            repoBuilder.AddFile("door.txt", "door");

            var files = FileSystemScanFolder(git);

            Assert.Equal(@"tree 2 
blob car.txt
blob door.txt", files);
        }
Пример #5
0
        public void Given_two_files_in_subfolder_Then_()
        {
            repoBuilder = new RepoBuilder(@"c:\temp\");
            var git = repoBuilder.BuildEmptyRepo();

            repoBuilder.AddFile(@"FeatureVolvo\car.txt", "car");
            repoBuilder.AddFile(@"FeatureVolvo\door.txt", "door");

            var files = FileSystemScanFolder(git);

            Assert.Equal(
                @"tree 1 
tree 2 FeatureVolvo
blob FeatureVolvo\car.txt
blob FeatureVolvo\door.txt", files);
        }
Пример #6
0
        public void When_two_commits_on_master_and_one_on_feature_Then_log_both_branches()
        {
            var repoBuilder = new RepoBuilder(new Guid("186d2ac8-1e9c-4e86-b1ac-b18208adead4"))
                              .EmptyRepo()
                              .AddFile("a.txt", "some content");

            repoBuilder.Git.Commit("Add a.txt", "kasper graversen", new DateTime(2018, 3, 1, 12, 22, 33));
            repoBuilder.AddFile("a.txt", "changed a...");
            repoBuilder.Git.Commit("Changed a.txt", "kasper graversen", new DateTime(2018, 3, 2, 13, 24, 34));
            repoBuilder
            .NewBranch("feature/speed")
            .AddFile("a.txt", "speedup!")
            .Git.Commit("Speedup a.txt", "kasper graversen", new DateTime(2018, 4, 3, 15, 26, 37));

            var actual = repoBuilder.Git.Log();

            Assert.Equal(@"
Log for master
* dd3044753fdb212c9248da29005a6d4765e3bbe302efff96a9321bf8ea710b83 - Changed a.txt (2018/03/02 01:24:34) <kasper graversen> 
* 06cd57d8d2feececc9eb48adda4cea5b57482324267f1e9632c16079ac6d793e - Add a.txt (2018/03/01 12:22:33) <kasper graversen> 

Log for feature/speed
* fafcd20734eda4c9849aea8cb831c87f225909e32686637c54d3896513ecfca0 - Speedup a.txt (2018/04/03 03:26:37) <kasper graversen> 
", actual);
        }
Пример #7
0
        public void When_detached_head_and_commit_move_Then_update_head()
        {
            var detachedId = repoBuilder
                             .EmptyRepo()
                             .AddFile("a.txt")
                             .Commit();

            repoBuilder
            .AddFile("b.txt")
            .Commit();
            repoBuilder.Git.Checkout(detachedId);
            var detachedId2 = repoBuilder
                              .AddFile("a.txt")
                              .Commit();

            Assert.Null(repoBuilder.Git.Hd.Head.Branch);
            Assert.Equal(detachedId2, repoBuilder.Git.Hd.Head.Id);
            Assert.Equal(detachedId2, repoBuilder.Git.Hd.Head.GetId(repoBuilder.Git.Hd));
        }
Пример #8
0
        public void CommitWhenHeadless()
        {
            repoBuilder = new RepoBuilder(@"c:\temp\");
            var git = repoBuilder.Build2Files3Commits();

            git.Checkout(git.HeadRef(1));
            repoBuilder.AddFile("newfile", "dslfk");

            var id = git.Commit("headless commit", "a", new DateTime(2010, 11, 12), git.ScanFileSystem());

            Assert.Equal("48a24325bf46e633d025dbb88167e0ba867213d9c61f7ab7cb24b2af15450c00", id.ToString());
        }
Пример #9
0
        public void CommitWhenHeadless()
        {
            repoBuilder = new RepoBuilder(@"c:\temp\");
            var git = repoBuilder.Build2Files3Commits();

            git.Branches.Checkout(git.HeadRef(1));
            repoBuilder.AddFile("newfile", "dslfk");

            var id = git.Commit("headless commit", "a", new DateTime(2010, 11, 12));

            Assert.Equal("f4982f442bf946c3678bc68761a1da953ff1f61020311d1802167288b5514087", id.ToString());
        }
Пример #10
0
        public void When_two_commits_Then_log_twoline()
        {
            var repoBuilder = new RepoBuilder(new Guid("b3b12f1c-f455-4987-b2d7-5db08d9e1ee4"))
                              .EmptyRepo()
                              .AddFile("a.txt", "some content");

            repoBuilder.Git.Commit("Add a.txt", "kasper graversen", new DateTime(2018, 3, 1, 12, 22, 33));
            repoBuilder.AddFile("a.txt", "changed a...");
            repoBuilder.Git.Commit("Changed a.txt", "kasper graversen", new DateTime(2018, 3, 2, 13, 24, 34));

            Assert.Equal(@"Log for master
* dd30447 - Changed a.txt (2018/03/02 01:24:34) <kasper graversen> 
* 06cd57d - Add a.txt (2018/03/01 12:22:33) <kasper graversen> 
", repoBuilder.Git.Log());
        }
Пример #11
0
        public void When_detached_head_Then_git_branches_shows_detached_as_branch()
        {
            repoBuilder = new RepoBuilder(@"c:\temp\");
            var detachedId = repoBuilder
                             .EmptyRepo()
                             .AddFile("a.txt")
                             .Commit();

            repoBuilder
            .AddFile("b.txt")
            .Commit();

            repoBuilder.Git.Checkout(detachedId);

            Assert.Equal($@"* (HEAD detached at {detachedId.ToString().Substring(0, 7)})
  master", repoBuilder.Git.Branch());
        }
Пример #12
0
        public void When_Commit_Then_content_is_stored()
        {
            var filename = "a.txt";
            var id1      = repoBuilder
                           .EmptyRepo()
                           .AddFile(filename, "version 1 a")
                           .Commit();
            var id2 = repoBuilder
                      .AddFile(filename, "version 2 a")
                      .Commit();

            repoBuilder.Git.Checkout(id1);
            Assert.Equal("version 1 a", repoBuilder.ReadFile(filename));

            repoBuilder.Git.Checkout(id2);
            Assert.Equal("version 2 a", repoBuilder.ReadFile(filename));
        }
Пример #13
0
        public void When_two_commits_Then_log_twoline()
        {
            var repoBuilder = new RepoBuilder(new Guid("b3b12f1c-f455-4987-b2d7-5db08d9e1ee4"))
                              .EmptyRepo()
                              .AddFile("a.txt", "some content");

            repoBuilder.Git.Commit("Add a.txt", "kasper graversen", new DateTime(2018, 3, 1, 12, 22, 33));
            repoBuilder.AddFile("a.txt", "changed a...");
            repoBuilder.Git.Commit("Changed a.txt", "kasper graversen", new DateTime(2018, 3, 2, 13, 24, 34));

            var actual = repoBuilder.Git.Log();

            Assert.Equal(@"
Log for master
* dd3044753fdb212c9248da29005a6d4765e3bbe302efff96a9321bf8ea710b83 - Changed a.txt (2018/03/02 01:24:34) <kasper graversen> 
* 06cd57d8d2feececc9eb48adda4cea5b57482324267f1e9632c16079ac6d793e - Add a.txt (2018/03/01 12:22:33) <kasper graversen> 
", actual);
        }
Пример #14
0
        public void When_two_commits_on_master_and_one_on_feature_Then_log_both_branches()
        {
            var repoBuilder = new RepoBuilder(new Guid("186d2ac8-1e9c-4e86-b1ac-b18208adead4"))
                              .EmptyRepo()
                              .AddFile("a.txt", "some content");

            repoBuilder.Git.Commit("Add a.txt", "kasper graversen", new DateTime(2018, 3, 1, 12, 22, 33));
            repoBuilder.AddFile("a.txt", "changed a...");
            repoBuilder.Git.Commit("Changed a.txt", "kasper graversen", new DateTime(2018, 3, 2, 13, 24, 34));
            repoBuilder
            .NewBranch("feature/speed")
            .AddFile("a.txt", "speedup!")
            .Git.Commit("Speedup a.txt", "kasper graversen", new DateTime(2018, 4, 3, 15, 26, 37));

            Assert.Equal(@"Log for master
* dd30447 - Changed a.txt (2018/03/02 01:24:34) <kasper graversen> 
* 06cd57d - Add a.txt (2018/03/01 12:22:33) <kasper graversen> 
Log for feature/speed
* fafcd20 - Speedup a.txt (2018/04/03 03:26:37) <kasper graversen> 
* dd30447 - Changed a.txt (2018/03/02 01:24:34) <kasper graversen> 
* 06cd57d - Add a.txt (2018/03/01 12:22:33) <kasper graversen> 
", repoBuilder.Git.Log());
        }