예제 #1
0
        public void TM_UserData_Git_Ctor()
        {
            var userDataGit = new TM_UserData_Git(null);

            Assert.AreEqual(userDataGit.NGit_Author_Name , TMConsts.NGIT_DEFAULT_AUTHOR_NAME);
            Assert.AreEqual(userDataGit.NGit_Author_Email, TMConsts.NGIT_DEFAULT_AUTHOR_EMAIL);
        }
예제 #2
0
        public static TM_UserData_Git   pushUserRepository(this TM_UserData_Git userData, API_NGit nGit)
        {
            var tmServer = userData.FileStorage.tmServer();

            if (tmServer.isNull())
            {
                return(userData);
            }

            if (tmServer.Git.UserData_Auto_Push.isFalse())           //skip if this is set
            {
                return(userData);
            }

            if (WebUtils.runningOnLocalHost())  //don't push local changes in order to prevent git merge conflicts
            {
                "[TM_UserData] [triggerGitCommit] skipping because it is a local request and getGitUserConfigFile is set".info();
                return(userData);
            }
            TM_UserData.GitPushThread = O2Thread.mtaThread(
                () => {
                var start = DateTime.Now;
                "[TM_UserData] [GitPush] Start".info();
                nGit.push();
                "[TM_UserData] [GitPush] in ".info(start.duration_To_Now());
            });
            return(userData);
        }
예제 #3
0
 public static TM_UserData       userData(this TM_UserData_Git userDataGit)
 {
     if (userDataGit.notNull())
     {
         return(userDataGit.UserData);
     }
     return(null);
 }
예제 #4
0
 public TM_UserData_Git(TM_FileStorage tmFileStorage)
 {
     Current             = this;
     FileStorage         = tmFileStorage;
     UserData            = tmFileStorage.userData();
     NGit_Author_Name    = TMConsts.NGIT_DEFAULT_AUTHOR_NAME;
     NGit_Author_Email   = TMConsts.NGIT_DEFAULT_AUTHOR_EMAIL;
 }
예제 #5
0
 public TM_UserData_Git(TM_FileStorage tmFileStorage)
 {
     Current           = this;
     FileStorage       = tmFileStorage;
     UserData          = tmFileStorage.userData();
     NGit_Author_Name  = TMConsts.NGIT_DEFAULT_AUTHOR_NAME;
     NGit_Author_Email = TMConsts.NGIT_DEFAULT_AUTHOR_EMAIL;
 }
예제 #6
0
 public static TM_UserData_Git   setup_UserData_Git_Support(this TM_FileStorage tmFileStorage)
 {
     if (tmFileStorage.userData().notNull())
     {
         var userDataGit = new TM_UserData_Git(tmFileStorage);
         userDataGit.syncWithGit();
         return(userDataGit);
     }
     return(null);
 }
 public static TM_UserData_Git setup_UserData_Git_Support(this TM_FileStorage tmFileStorage)
 {
     if(tmFileStorage.userData().notNull())
     {
         var userDataGit =  new TM_UserData_Git(tmFileStorage);
         userDataGit.syncWithGit();
         return userDataGit;
     }
     return null;
 }
예제 #8
0
        public static TM_UserData_Git   clone_UserDataRepo(this TM_UserData_Git userData, string gitLocation, string targetFolder)
        {
            var start = DateTime.Now;

            "[TM_UserData] [GitClone] Start".info();
            if (GitExe.CloneUsingGitExe(gitLocation, targetFolder).isFalse())
            {
                "[TM_UserData] [GitClone] Using NGit for the clone".info();
                gitLocation.git_Clone(targetFolder);
            }
            "\n\n[TM_UserData] [GitClone] in  {0}\n\n".debug(start.duration_To_Now());
            return(userData);
        }
예제 #9
0
        /*public static TMUser            triggerGitCommit         (this TMUser tmUser)
         * {
         *  TM_UserData_Git.Current.triggerGitCommit();
         *  return tmUser;
         * }*/
        public static TM_UserData_Git   triggerGitCommit(this TM_UserData_Git userData)
        {
            "[TM_UserData_Git][triggerGitCommit]".info();
            var tmFileStorage = userData.FileStorage;
            var tmServer      = tmFileStorage.Server;

            if (tmServer.notNull())
            {
                if (tmServer.Git.UserData_Git_Enabled && userData.NGit.notNull())
                {
                    if (userData.NGit.status().valid())
                    {
                        var start = DateTime.Now;
                        userData.NGit.setDefaultAuthor();
                        userData.NGit.add_and_Commit_using_Status();
                        "[TM_UserData] [GitCommit] in ".info(start.duration_To_Now());
                    }
                }
            }
            return(userData);
        }
예제 #10
0
        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();
        }
예제 #11
0
        public static TM_UserData_Git   syncWithGit(this TM_UserData_Git userDataGit)
        {
            try
            {
                if (TM_Server.Current.git().isNull())
                {
                    return(userDataGit);
                }
                var tmFileStorage = userDataGit.FileStorage;

                if (userDataGit.userData().isNull())
                {
                    return(userDataGit);
                }

                //var userData = userDataGit.userData();
                var gitConfig = TM_Server.Current.git();
                if (gitConfig.UserData_Git_Enabled.isFalse())
                {
                    return(userDataGit);
                }

                var userData_Config = tmFileStorage.Server.userData_Config();

                var gitLocation = userData_Config.remote_GitPath();
                if (gitLocation.valid())
                {
                    //Adjust Path_UserData so that there is an unique folder per repo
                    //var extraFolderName = "_Git_";

                    // extra mode to switch of multiple Git_Hosting in same server
                    //extraFolderName += gitLocation.replace("\\","/").split("/").last().remove(".git").safeFileName();

                    //userData.Path_UserData = userData.Path_UserData_Base + extraFolderName;
                    //userData.Path_UserData.createDir();
                    "[TM_UserData] [handleExternalGitPull] userData.Path_UserData set to: {0}".debug(tmFileStorage.Path_UserData);

                    if (WebUtils.online().isFalse() && gitLocation.dirExists().isFalse())
                    {
                        return(userDataGit);
                    }

                    if (tmFileStorage.Path_UserData.isGitRepository())
                    {
                        if (gitConfig.UserData_Auto_Pull.isFalse())     //skip if this is set
                        {
                            return(userDataGit);
                        }

                        "[TM_UserData] [GitPull]".info();
                        var nGit = tmFileStorage.Path_UserData.git_Open();
                        nGit.pull();
                        //var nGit = userData.Path_UserData.git_Pull();
                        userDataGit.pushUserRepository(nGit);
                    }
                    else
                    {
                        userDataGit.clone_UserDataRepo(gitLocation, tmFileStorage.Path_UserData);
                    }
                }
                if (tmFileStorage.Path_UserData.notNull())
                {
                    //var gitEnabled = userData.tmConfig().Git.UserData_Git_Enabled;

                    //                if (gitEnabled)
                    //               {
                    if (tmFileStorage.Path_UserData.isGitRepository())
                    {
                        //"[TM_UserData] [setupGitSupport] open repository: {0}".info(userData.Path_UserData);
                        "[TM_UserData] [GitOpen]".info();
                        userDataGit.NGit = tmFileStorage.Path_UserData.git_Open();
                    }
                    else
                    {
                        //"[TM_UserData] [setupGitSupport] initializing repository at: {0}".info(userData.Path_UserData);
                        "[TM_UserData] [GitInit]".info();
                        userDataGit.NGit = tmFileStorage.Path_UserData.git_Init();
                    }
                    userDataGit.triggerGitCommit();        // in case there are any files that need to be commited
                    //                }
                }
            }
            catch (Exception ex)
            {
                var message = ex.Message;
                System.Diagnostics.Debug.Write(ex.Message);
                ex.log("[TM_UserData]  [handleExternalGitPull]");
            }
            return(userDataGit);
        }