예제 #1
0
        public static List <GitData_Commit> gitData_Commits(this API_NGit nGit, int max_CommitsToShow, bool mapCommitTrees)
        {
            var gitData_Commits = new List <GitData_Commit>();

            foreach (var commit in nGit.commits().take(max_CommitsToShow))
            {
                var gitData_Commit = new GitData_Commit
                {
                    Author    = commit.author_Name(),
                    Committer = commit.committer_Name(),
                    Message   = commit.message(),
                    Sha1      = commit.sha1(),
                    When      = commit.when().toFileTimeUtc()
                };
                if (commit.ParentCount > 0)
                {
                    gitData_Commit.Parents = (from parent in commit.Parents select parent.Name).toList();
                }

                if (mapCommitTrees)
                {
                    gitData_Commit.Tree = commit.gitData_Files(nGit);
                }
                gitData_Commits.add(gitData_Commit);
            }
            return(gitData_Commits);
        }
        public void fetch()
        {
            var commits_BeforeFetch = nGit2.commits();
            var head_BeforeFetch    = nGit2.head();
            //repoPath2.startProcess();

            var fetchResult1       = nGit2.fetch(repoPath1, "master");
            var commits_AfterFetch = nGit2.commits();
            var head_AfterFetch    = nGit2.head();

            Assert.IsEmpty(commits_BeforeFetch);
            Assert.IsNotEmpty(commits_AfterFetch);
            Assert.IsNull(head_BeforeFetch);
            Assert.IsNotNull(head_AfterFetch);     // I would expect this to be true

            Assert.IsNull(nGit2.Last_Exception);
            Assert.IsNotNull(nGit2.Last_FetchResult);
            Assert.IsTrue(fetchResult1);

            var filesInRepo1 = nGit1.files();
            var filesInRepo2 = nGit2.files();

            Assert.AreEqual(1, filesInRepo1.size());
            Assert.AreEqual(1, filesInRepo2.size());
            var fullPathInRepo1 = nGit1.file_FullPath(filesInRepo1.first());
            var fullPathInRepo2 = nGit2.file_FullPath(filesInRepo2.first());

            Assert.IsTrue(fullPathInRepo1.fileExists());
            Assert.IsFalse(fullPathInRepo2.fileExists());

            //test Error handling

            var fetchResult2 = nGit2.fetch(repoPath1, "master_", "master");

            Assert.IsNotNull(nGit2.Last_Exception);
            Assert.IsNull(nGit2.Last_FetchResult);
            Assert.IsFalse(fetchResult2);
            Assert.AreEqual(nGit2.Last_Exception.Message, "Remote does not have refs/heads/master_ available for fetch.");

            var fetchResult3 = nGit2.fetch();

            Assert.IsNotNull(nGit2.Last_Exception);
            Assert.IsNull(nGit2.Last_FetchResult);
            Assert.IsFalse(fetchResult2);
            Assert.AreEqual(nGit2.Last_Exception.Message, "Invalid remote: origin");
        }
예제 #3
0
/*
 *      [Test]
 *      //[Ignore("Rewrite to take into account new Git Storage")]
 *      //todo: fix compilation error
 *
 *      [Assert_Admin] public void ManualyGitCommitNewUsers()
 *      {
 *          TMConfig.Current.Git.UserData_Git_Enabled = false;
 *
 *          var head1              = nGit.head();
 *
 *          Assert.IsNotNull(nGit);
 *          Assert.IsTrue   (userData.Path_UserData.isGitRepository());
 *          Assert.IsFalse   (head1.isNull());
 *
 *          var tmUser      = userData.newUser().tmUser();
 *          var userXmlFile = tmUser.getTmUserXmlFile().fileName();
 *          var untracked   = nGit.status_Untracked();
 *
 *          Assert.AreEqual (1,untracked.size());
 *          Assert.AreEqual (userXmlFile, untracked.first().fileName());
 *
 *          nGit.add_and_Commit_using_Status();
 *          untracked         = nGit.status_Untracked();
 *          var head2         = nGit.head();
 *          Assert.AreEqual   (0,untracked.size());
 *          Assert.IsFalse    (nGit.head().isNull());
 *          Assert.AreNotEqual(head1, head2);
 *          "Head is now: {0}".info(nGit.head());
 *
 *          TMConfig.Current.Git.UserData_Git_Enabled = true;
 *      }*/
        [Test][Assert_Admin] public void CheckGitRepoDoesCommits_OnNewUser()
        {
            Assert.IsTrue(userData.tmConfig().Git.UserData_Git_Enabled);

            userData.newUser();                        // adding a user
            Assert.IsNotNull(nGit.head());
            userData.newUser();                        // adding another user

            var headBeforeUser = nGit.head();

            userData.newUser();
            var headAfterUser = nGit.head();

            Assert.IsFalse(nGit.head().isNull());
            Assert.AreNotEqual(headBeforeUser, headAfterUser, "Git Head value should be different after a TMUser create");
            Assert.AreNotEqual(2, nGit.commits().size());
        }
예제 #4
0
        public void setUp()
        {
            //create temp repo with no Admin user
            userData = new TM_UserData(true)
            {
                Path_UserData = "nonGitRepo".tempDir()
            };
            userData.SetUp();
            nGit = userData.NGit;

            Assert.AreEqual(2, nGit.commits().size(), "there should be two commits here");
        }
예제 #5
0
        public void setUp()
        {
            //create temp repo with no Admin user
            userData = new TM_UserData(true)
            {
                Path_UserData = "nonGitRepo".tempDir()
            };
            userData.SetUp();
            nGit = userData.NGit;

            Assert.AreEqual(1, nGit.commits().size(), "there should be one commit of the TMSecretData.config file");
        }
예제 #6
0
        [SetUp][Admin] public void setUp()
        {
            UserGroup.Admin.assert();

            //create TM_FileStorage on temp Custom_WebRoot for this TestFixture
            TM_FileStorage.Custom_WebRoot = "custom_WebRoot".tempDir();

            tmFileStorage = new TM_FileStorage(false);
            tmFileStorage.set_WebRoot()
            .set_Path_XmlDatabase()
            .tmServer_Load()
            .set_Path_UserData()
            .load_UserData();
            tmFileStorage.hook_Events_TM_UserData();

            tmXmlDatabase = tmFileStorage.TMXmlDatabase.assert_Not_Null();
            userData      = tmFileStorage.UserData.assert_Not_Null();
            tmServer      = tmFileStorage.Server.assert_Not_Null();

            tmFileStorage.Path_XmlDatabase.assert_Folder_Exists();
            tmFileStorage.Path_UserData.assert_Folder_Exists();

            userDataGit = tmFileStorage.setup_UserData_Git_Support();           // adds Git Support for UserData repos

            tmFileStorage.Path_UserData.isGitRepository().assert_True();

            Assert.NotNull(tmFileStorage.Server.userData_Config());

            userData.createDefaultAdminUser();

            userDataGit.triggerGitCommit();

            nGit = userDataGit.NGit;

            nGit.commits().assert_Size_Is(2, "there should be two commits here");

            UserGroup.None.assert();
        }
        public void pull()
        {
            //a pull into a bare repo doesn't work
            var result_RemoteAdd1   = nGit2.remote_Add("origin", repoPath1);//.pathCombine(".git"));
            var result_Pull_Origin1 = nGit2.pull();

            Assert.IsNotNull(nGit2.Last_Exception);
            if (nGit2.Last_Exception is InvalidConfigurationException)                                               // it was failing on TeamCity
            {
                Assert.Ignore("Ignoring test because there was an InvalidConfigurationException on ngit2.pull()");
            }
            Assert.IsInstanceOf <TransportException>(nGit2.Last_Exception);
            Assert.AreEqual(nGit2.Last_Exception.Message, "Nothing to fetch.");

            Assert.IsTrue(result_RemoteAdd1);
            Assert.IsFalse(result_Pull_Origin1);

            //Do a pull from a clone

            var repoPath3  = "repo3".tempDir();
            var repo1_File = nGit1.files_FullPath().first();

            repoPath3.delete_Folder();

            var head_Repo1       = nGit1.head();
            var nGit3            = repoPath1.git_Clone(repoPath3);
            var files_AfterClone = nGit3.files_FullPath();
            var head_AfterClone  = nGit3.head();
            var repo3_File       = nGit3.files_FullPath().first();

            Assert.IsTrue(repoPath3.isGitRepository());
            Assert.IsNotEmpty(files_AfterClone);
            Assert.AreEqual(head_AfterClone, head_Repo1);
            Assert.IsTrue(repo3_File.fileExists());
            Assert.AreEqual(repo3_File.fileContents(), repo1_File.fileContents());
            Assert.AreEqual("", nGit1.status());
            Assert.AreEqual("", nGit3.status());

            //do a change on repo1
            var newContent = 10.randomLetters();

            newContent.saveAs(repo1_File);

            Assert.AreNotEqual("", nGit1.status());
            nGit1.add_and_Commit_using_Status();
            Assert.AreEqual("", nGit3.status());
            Assert.AreEqual(1, nGit3.commits().size());
            Assert.AreEqual(2, nGit1.commits().size());
            Assert.AreNotEqual(repo3_File.fileContents(), repo1_File.fileContents());

            var result_Pull = nGit3.pull();
            var mergeResult = nGit3.Last_PullResult.GetMergeResult();

            Assert.IsTrue(result_Pull);
            Assert.AreEqual(repo3_File.fileContents(), repo1_File.fileContents());
            Assert.AreEqual(2, nGit1.commits().size());
            Assert.IsNotNull(mergeResult);
            Assert.AreEqual(mergeResult.GetMergeStatus(), MergeStatus.FAST_FORWARD);
            Assert.IsTrue(mergeResult.GetMergeStatus().IsSuccessful());
            Assert.IsFalse(nGit3.reset_on_MergeConflicts(nGit3.Last_PullResult));

            /* the remote_Add is still not working 100% , since the reverse pull fails below)
             *
             * //do a change on repo3
             * var newContent = 10.randomLetters();
             * newContent.saveAs(repo3_File);
             *
             * Assert.AreNotEqual  ("", nGit3.status());
             * nGit3.add_and_Commit_using_Status();
             * Assert.AreEqual  ("", nGit3.status());
             * Assert.AreEqual  (1, nGit1.commits().size());
             * Assert.AreEqual  (2, nGit3.commits().size());
             *
             * var result_RemoteAdd2   = nGit1.remote_Add("origin", repoPath3);//.pathCombine(".git"));
             * var result_Pull_Origin2 = nGit1.pull();
             *
             *
             * Assert.IsNotNull(nGit1.Last_Exception);
             * Assert.IsInstanceOf<TransportException>(nGit1.Last_Exception);
             * Assert.AreEqual(nGit1.Last_Exception.Message, "Nothing to fetch.");
             *
             * Assert.IsTrue  (result_RemoteAdd2);
             * Assert.IsTrue  (result_Pull_Origin2);
             * Assert.AreEqual(2, nGit1.commits().size());
             */

            nGit3.delete_Repository_And_Files();
            Assert.IsFalse(repoPath3.dirExists());

            //Null value handling
            Assert.IsFalse((null as API_NGit).pull(null));
            Assert.IsFalse(nGit3.pull(null));
        }
예제 #8
0
 public static List <string> commits_SHA1(this API_NGit nGit, int maxCount = -1)
 {
     return(nGit.commits(maxCount)
            .Select(logEntry => logEntry.Name)
            .toList());
 }
예제 #9
0
        public void setUp()
        {
            //create temp repo with no Admin user
            userData = new TM_UserData(true)
                                {
                                    Path_UserData = "nonGitRepo".tempDir()
                                };
            userData .SetUp(false);
            nGit     = userData.NGit;

            Assert.AreEqual(1, nGit.commits().size() , "there should be one commit of the TMSecretData.config file");
        }
예제 #10
0
        [Test] public void CheckGitRepoDoesNotCommit_OnNewUser()
        {
            Assert.NotNull(tmServer);
            Assert.IsTrue(tmServer.Git.UserData_Git_Enabled);

            nGit.status().assert_Empty();

            userData.newUser();                        // adding a user
            Assert.IsNotNull(nGit.head());
            userData.newUser();                        // adding another user

            nGit.status().assert_Not_Empty();

            var headBeforeUser = nGit.head();

            userData.newUser();

            nGit.head().assert_Not_Null()
            .assert_Equal(headBeforeUser, "Git Head value are still the same here");

            nGit.commits().assert_Size_Is(2);

            userDataGit.triggerGitCommit();                 // manually trigger the commit
            nGit.status().assert_Empty();
            nGit.commits().assert_Size_Is(3);

            UserGroup.None.assert();
        }