예제 #1
0
        public void WhenUsingIOption_ThenAutoBootstrapingOneBrancheInAdditionToMaster()
        {
            int ChangesetIdToTrickFetch = 1;

            h.SetupFake(r =>
            {
                r.Changeset(ChangesetIdToTrickFetch, "UseLess! Just to have the same changeset Id that the commit already in repo (and fetch nothing)", DateTime.Parse("2012-01-01 12:12:12 -05:00"))
                .Change(TfsChangeType.Add, TfsItemType.Folder, "$/MyProject");
            });

            string c1 = null;
            string c2 = null;

            h.SetupGitRepo("repo", g =>
            {
                c1 = g.Commit("A sample commit from TFS.\n\ngit-tfs-id: [http://server/tfs]$/MyProject/trunk;C" + ChangesetIdToTrickFetch);
                g.CreateBranch("branch");
                c2 = g.Commit("A sample commit from TFS.\n\ngit-tfs-id: [http://server/tfs]$/MyProject/branch;C" + ChangesetIdToTrickFetch);
            });

            using (var repo = h.Repository("repo"))
            {
                LibGit2Sharp.Commands.Checkout(repo, "master");
                h.AssertNoRef("repo", "tfs/default");
                h.RunIn("repo", "fetch");
                h.AssertRef("repo", "tfs/default", c1);

                LibGit2Sharp.Commands.Checkout(repo, "branch");
                h.AssertNoRef("repo", "tfs/branch");
                h.RunIn("repo", "fetch");
                h.AssertRef("repo", "tfs/branch", c2);
            }
        }
예제 #2
0
        public void GetLastParentTfsCommits_WhenThereIsMoreThanTfsChangeset_ThenReturnTheLast()
        {
            h.SetupFake(r =>
            {
                r.Changeset(42, "UseLess! Just to have the same changeset Id that the commit already in repo (and fetch nothing)", DateTime.Parse("2012-01-01 12:12:12 -05:00"))
                .Change(TfsChangeType.Add, TfsItemType.Folder, "$/MyProject");
            });

            string c1 = null;
            string c2 = null;
            string c3 = null;

            h.SetupGitRepo("repo", g =>
            {
                c1 = g.Commit("A sample commit from TFS.\n\ngit-tfs-id: [http://server/tfs]$/MyProject/trunk;C1");
                c2 = g.Commit("A sample commit from TFS.\n\ngit-tfs-id: [http://server/tfs]$/MyProject/trunk;C2");
                c3 = g.Commit("A sample commit from TFS.\n\ngit-tfs-id: [http://server/tfs]$/MyProject/trunk;C3");
            });

            using (var repo = h.Repository("repo"))
            {
                var gitRepository = new GitRepository(repo.Info.WorkingDirectory, new Container(), null, new RemoteConfigConverter());
                var changesets    = gitRepository.GetLastParentTfsCommits("HEAD");
                Assert.Single(changesets);
                Assert.Equal(c3, changesets.First().GitCommit);
            }
        }
예제 #3
0
        public void WhenNoValueIsSet_ThenDefaultValueIsReturned()
        {
            h.SetupGitRepo("repo", g =>
            {
                g.Commit("A sample commit from TFS.\n\ngit-tfs-id: [http://server/tfs]$/MyProject/trunk;C1");
            });

            using (var repo = h.Repository("repo"))
            {
                var gitRepository    = new GitRepository(repo.Info.WorkingDirectory, new Container(), null, new RemoteConfigConverter());
                var configProperties = new ConfigProperties(new ConfigPropertyLoader(new Globals()
                {
                    Repository = gitRepository
                }));
                Assert.Equal(100, configProperties.BatchSize);
            }
        }
예제 #4
0
        public void GetCommit_WhenNoCommitIsFound_ThenReturnsNull()
        {
            h.SetupGitRepo("repo", g => { });

            using (var repo = h.Repository("repo"))
            {
                var gitRepository = new GitRepository(repo.Info.WorkingDirectory, new Container(), null, new RemoteConfigConverter());

                Assert.Null(gitRepository.GetCommit("b1accc619681b0348aaec303f0fce6f463890c74"));
            }
        }
예제 #5
0
        public void CloneWithAllBranchesShouldHandleFolderDeletedAndRecreatedAsBranch()
        {
            h.SetupFake(r =>
            {
                r.SetRootBranch("$/MyTeamProject/Root");

                r.Changeset(1, "Create initial team project.", DateTime.Now)
                .Change(TfsChangeType.Add, TfsItemType.Folder, "$/MyTeamProject");

                r.Changeset(2, "Create root branch.", DateTime.Now)
                .Change(TfsChangeType.Add, TfsItemType.Folder, "$/MyTeamProject/Root");

                r.Changeset(3, @"Create ""branch"" (as a folder).", DateTime.Now)
                .Change(TfsChangeType.Add, TfsItemType.Folder, "$/MyTeamProject/Branch");

                r.Changeset(4, @"Delete the ""branch"" folder.", DateTime.Now)
                .Change(TfsChangeType.Delete, TfsItemType.Folder, "$/MyTeamProject/Branch");

                r.BranchChangeset(5, "Create a proper branch (though, with the same name as the previously deleted folder)",
                                  DateTime.Now, "$/MyTeamProject/Root", "$/MyTeamProject/Branch", 2)
                .Change(TfsChangeType.Branch, TfsItemType.Folder, "$/MyTeamProject/Branch");
            });

            h.Run("clone", h.TfsUrl, "$/MyTeamProject/Root", "MyTeamProject", "--branches=all");

            h.AssertGitRepo("MyTeamProject");

            var branchCollection = h.Repository("MyTeamProject").Branches.Cast <Branch>().ToList();
            var branch           = branchCollection.FirstOrDefault(b => b.FriendlyName == "Branch");

            Assert.NotNull(branch);

            // So, it turns out GetRootChangesetForBranch is really the unit under test here.
            // Because it's faked out for unit tests, this test is worthless except as an
            // illustration of expected behavior in the actual implementation.

            // Ensure we didn't migrate our branch from the "folder creation" point of
            // $/MyTeamProject/Branch (e.g. C2 -> C3, C4...
            Assert.DoesNotContain(branch.Commits, c => c.Message.IndexOf(@"Create ""branch"" (as a folder).", StringComparison.InvariantCultureIgnoreCase) >= 0);

            // Ensure we migrated the branch from it's creation point, e.g. C2 immediately followed by C5 (C2 -> C5)
            var expectedBranchChangesetParentCommit = branch.Commits.Where(c => c.Message.IndexOf("Create root branch.", StringComparison.InvariantCultureIgnoreCase) >= 0).FirstOrDefault();

            Assert.NotNull(expectedBranchChangesetParentCommit);

            var branchChangesetCommit = branch.Commits.Where(c => c.Message.IndexOf("Create a proper branch (though, with the same name as the previously deleted folder)", StringComparison.InvariantCultureIgnoreCase) >= 0).FirstOrDefault();

            Assert.NotNull(branchChangesetCommit);

            // This wasn't part of the original test by @jeremy-sylvis-tmg, but this does ensure the relationship
            // C2 -> C5; it may not be enough to just ensure C5 exists.
            Assert.Contains(expectedBranchChangesetParentCommit, branchChangesetCommit.Parents);

            var refs = new[]
            {
                "HEAD",
                "refs/remotes/tfs/default",
                "refs/heads/master",
                "refs/heads/tfs/branch",
                "refs/heads/Branch"
            };

            AssertNewClone("MyTeamProject", refs);
        }