public void TwoBranches_NoConflictMerge_RenameFileInFeatureBranch()
        {
            var repoName = Guid.NewGuid().ToString();

            using (var repo = RepoBuilder.InitNewRepository(repoName))
            {
                repo.AddFile("A.txt");
                repo.Commit("Add A");

                repo.CreateBranch("Feature");
                repo.Checkout("Feature");

                repo.Rename("A.txt", "A_renamed.txt");
                repo.Commit("Renamed A.txt -> A_renamed.txt");


                repo.Checkout("master");


                repo.Merge("Feature");


                repo.ModifyFileAppend("A_renamed.txt", "Modify in master");
                var c = repo.Commit("Modify A_renamed after merge");


                var history = GetRawHistory(repoName);

                Assert.AreEqual(4, history.ChangeSets.Count);


                //                           C  A  M  D  R  C  Final
                AssertFile(history, "A.txt", 3, 1, 1, 0, 1, 0, "A_renamed.txt");
            }
        }
        public void SingleBranch_AddModifyRemove()
        {
            var repoName = Guid.NewGuid().ToString();

            using (var repo = RepoBuilder.InitNewRepository(repoName))
            {
                repo.AddFile("A.txt");
                repo.Commit("Add A");

                repo.ModifyFileAppend("A.txt", "M");
                repo.Commit("Modify A");

                repo.DeleteFile("A.txt");
                repo.Commit();


                var history = GetRawHistory(repoName);

                Assert.AreEqual(3, history.ChangeSets.Count);

                //                           C  A  M  D  R  C  Final
                AssertFile(history, "A.txt", 3, 1, 1, 1, 0, 0, "A.txt");


                // Empty history after cleanup
                var cleanHistory = GetCleanHistory(repoName);
                Assert.AreEqual(0, cleanHistory.ChangeSets.Count);
            }
        }
        public void SingleBranch_AddModifyRenameModify()
        {
            var repoName = Guid.NewGuid().ToString();

            using (var repo = RepoBuilder.InitNewRepository(repoName))
            {
                repo.AddFile("A.txt");
                repo.Commit("Add A");

                repo.ModifyFileAppend("A.txt", "M");
                repo.Commit("Modify A");

                repo.Rename("A.txt", "A_renamed.txt");
                repo.Commit();

                repo.ModifyFileAppend("A_renamed.txt", "M");
                repo.Commit("Modify A");


                var history = GetRawHistory(repoName);

                Assert.AreEqual(4, history.ChangeSets.Count);

                //                           C  A  M  D  R  C  Final
                AssertFile(history, "A.txt", 4, 1, 2, 0, 1, 0, "A_renamed.txt");
            }
        }
 private ChangeSetHistory GetRawHistory(string repoName)
 {
     using (var cache = new Cache())
     {
         var provider = new GitProvider();
         provider.Initialize(RepoBuilder.GetRepoPath(repoName), cache.ToString(), null);
         var(history, graph) = provider.GetRawHistory(null);
         return(history);
     }
 }
 private ChangeSetHistory GetCleanHistory(string repoName)
 {
     using (var cache = new Cache())
     {
         var provider = new GitProvider();
         provider.Initialize(RepoBuilder.GetRepoPath(repoName), cache.ToString(), null);
         provider.UpdateCache(null, false, null);
         return(provider.QueryChangeSetHistory());
     }
 }
        public void SingleBranch_SingleAdd()
        {
            var repoName = Guid.NewGuid().ToString();

            using (var repo = RepoBuilder.InitNewRepository(repoName))
            {
                repo.AddFile("A.txt");
                repo.Commit("Add A");


                var history = GetCleanHistory(repoName);

                Assert.AreEqual(1, history.ChangeSets.Count);

                //                           C  A  M  D  R  C  Final
                AssertFile(history, "A.txt", 1, 1, 0, 0, 0, 0, "A.txt");
            }
        }
        public void TwoBranches_NoConflictMerge_ModifyAfterMerge()
        {
            var repoName = Guid.NewGuid().ToString();

            using (var repo = RepoBuilder.InitNewRepository(repoName))
            {
                repo.AddFile("A.txt");
                repo.Commit("Add A");

                repo.CreateBranch("Feature");
                repo.Checkout("Feature");

                repo.AddFile("B.txt"); // Just add something to the Feature branch
                repo.Commit("Add B");


                repo.Checkout("master");


                repo.ModifyFileAppend("A.txt", "Modify in master");
                repo.Commit("Modify A");

                repo.Merge("Feature");


                repo.ModifyFileAppend("B.txt", "Modify in master");
                var c = repo.Commit("Modify B after merge");


                var history = GetRawHistory(repoName);

                Assert.AreEqual(5, history.ChangeSets.Count);

                //                           C  A  M  D  R  C  Final
                AssertFile(history, "A.txt", 2, 1, 1, 0, 0, 0, "A.txt");

                //                           C  A  M  D  R  C  Final
                AssertFile(history, "B.txt", 2, 1, 1, 0, 0, 0, "B.txt");
            }
        }