예제 #1
0
        //Helper methods
        public void SetUpNGit()
        {
            TmRest.TBot_Run("Git");// trigger unpack of NGit and Sharpen dlls
            var fluentSharpGit = new API_NGit();

            Assert.NotNull(fluentSharpGit, "fluentSharpGit was null");
        }
예제 #2
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 static API_NGit      file_Write(this API_NGit nGit, string virtualFileName, string fileContents)
        {
            var fileToWrite = nGit.Path_Local_Repository.pathCombine(virtualFileName);

            fileContents.saveAs(fileToWrite);
            return(nGit);
        }
        public static string            diff(this API_NGit nGit)
        {
            var outputStream = NGit_Factory.New_OutputStream();

            nGit.diff_Raw(outputStream);
            return(outputStream.str());
        }
예제 #5
0
        public static API_NGit init(this API_NGit nGit, string targetFolder)
        {
            nGit.Last_Exception = null;

            if (targetFolder.isNull())
            {
                "[API_NGit][git_Init] targetFolder value provided was null".error();
                return(null);
            }
            if (targetFolder.isGitRepository())
            {
                "[API_NGit][git_Init] tried to init a repository in a folder that already has a git repository: {0}"
                .error(targetFolder);
                return(null);
            }
            try
            {
                nGit.close();
                "[API_NGit] init: {0}".debug(targetFolder);
                var init_Command = NGit.Api.Git.Init();

                init_Command.SetDirectory(targetFolder);
                nGit.Git                   = init_Command.Call();
                nGit.Repository            = nGit.Git.GetRepository();
                nGit.Path_Local_Repository = targetFolder;
                return(nGit);
            }
            catch (Exception ex)
            {
                nGit.Last_Exception = ex;
                ex.log("[API_NGit] ");
            }
            return(null);
        }
예제 #6
0
        [Test] public void Create_Repo_Add_Files_Check_Head()
        {
            var nGit     = new API_NGit();
            var tempRepo = "_tempRepo".tempDir(true);

            "TestRepo is: {0}".info(tempRepo);
            //Creating a local temp Repo
            Assert.IsFalse(tempRepo.isGitRepository(), "Should not be a repo");
            nGit.init(tempRepo);
            Assert.IsTrue(tempRepo.isGitRepository(), "Should be a repo");
            Assert.IsNull(nGit.head());

            //Adding a file (using method 1)
            nGit.file_Create("testFile.txt", "some Text");
            nGit.add_and_Commit_using_Status();
            var head1 = nGit.head();

            Assert.IsNotNull(head1);

            //Adding another file (using method 2)
            nGit.file_Create("testFile2.txt", "some Text");
            nGit.add("testFile2.txt");
            nGit.commit("Adding Another file");

            //making sure the head has changed
            var head2 = nGit.head();

            Assert.AreNotEqual(head1, head2);

            nGit.delete_Repository_And_Files();
        }
예제 #7
0
        public static List <GitData_File> gitData_Files(this API_NGit nGit, int max_FilesToShow, string commitSha1)
        {
            var gitData_Files = new  List <GitData_File>();

            try
            {
                var headCommit = nGit.Repository.Resolve(commitSha1);
                if (commitSha1.notNull())
                {
                    var revWalk  = new RevWalk(nGit.Repository);
                    var commit   = revWalk.ParseCommit(headCommit);
                    var treeWalk = new TreeWalk(nGit.Repository);
                    var tree     = commit.Tree;
                    treeWalk.AddTree(tree);
                    treeWalk.Recursive = true;

                    while (treeWalk.Next() && (max_FilesToShow == -1) || gitData_Files.size() < max_FilesToShow)
                    {
                        gitData_Files.add_File(treeWalk);
                    }
                    //repoFiles.Add(treeWalk.PathString);
                }
            }
            catch (Exception ex)
            {
                ex.log("[API_NGit][gitData_Files]");
            }
            return(gitData_Files);
        }
예제 #8
0
        public static List <string> commit_Files(this RevCommit revCommit, API_NGit nGit)
        {
            var repoFiles = new List <string>();

            revCommit.commit_TreeWalk(nGit, treeWalk => repoFiles.Add(treeWalk.PathString));
            return(repoFiles);
        }
예제 #9
0
 public static bool  pull(this API_NGit nGit, string remote = "origin")
 {
     try
     {
         var originalHead = nGit.head();
         nGit.Last_Exception = null;
         var pull_Command = nGit.Git.Pull();
         nGit.LastGitProgress = new GitProgress();
         pull_Command.SetProgressMonitor(nGit.LastGitProgress);
         nGit.Last_PullResult = pull_Command.Call();
         if (nGit.Last_PullResult.GetMergeResult().GetMergeStatus() == MergeStatus.CONFLICTING)
         {
             return(nGit.reset_on_MergeConflicts(nGit.Last_PullResult));
         }
         "[API_NGit] pull completed ok (with no conflicts)".debug();
         return(true);
     }
     catch (Exception ex)
     {
         if (nGit.notNull())
         {
             nGit.Last_Exception = ex;
         }
         ex.log("[API_NGit][pull]");
         return(false);
     }
 }
        public static API_NGit  files(this API_NGit nGit, string commitId, Action <TreeWalk> onTreeWalk)
        {
            try
            {
                var headCommit = nGit.Repository.Resolve(commitId);
                if (commitId.notNull())
                {
                    var revWalk  = new RevWalk(nGit.Repository);
                    var commit   = revWalk.ParseCommit(headCommit);
                    var treeWalk = new TreeWalk(nGit.Repository);
                    var tree     = commit.Tree;
                    treeWalk.AddTree(tree);
                    treeWalk.Recursive = true;

                    while (treeWalk.Next())
                    {
                        onTreeWalk(treeWalk);
                    }
                }
            }
            catch (Exception ex)
            {
                ex.log("[API_NGit][getRepoFiles]");
            }
            return(nGit);
        }
        public static string        status(this API_NGit nGit)
        {
            var status = nGit.status_Raw();

            if (status.isNull())
            {
                return(null);
            }
            var added       = status.added();
            var changed     = status.changed();
            var modified    = status.modified();
            var removed     = status.removed();
            var missing     = status.missing();
            var untracked   = status.untracked();
            var conflicting = status.conflicting();

            var statusDetails = ((added.Count > 0) ? "Added: {0}\n".format(added.join(" , ")) : "") +
                                ((changed.Count > 0) ? "changed: {0}\n".format(changed.join(" , ")) : "") +
                                ((removed.Count > 0) ? "removed: {0}\n".format(removed.join(" , ")) : "") +
                                ((missing.Count > 0) ? "missing: {0}\n".format(missing.join(" , ")) : "") +
                                ((modified.Count > 0) ? "modified: {0}\n".format(modified.join(" , ")) : "") +
                                ((untracked.Count > 0) ? "untracked: {0}\n".format(untracked.join(" , ")) : "") +
                                ((conflicting.Count > 0) ? "conflicting: {0}\n".format(conflicting.join(" , ")) : "");

            return(statusDetails);
        }
        public static List <string> files(this API_NGit nGit, string commitId)
        {
            var repoFiles = new List <string>();

            nGit.files(commitId, (treeWalk) => repoFiles.Add(treeWalk.PathString));
            return(repoFiles);
        }
예제 #13
0
        public static List <GitData_File> gitData_Files(this RevCommit revCommit, API_NGit nGit)
        {
            var gitData_Files = new List <GitData_File>();

            revCommit.commit_TreeWalk(nGit, treeWalk => gitData_Files.add_File(treeWalk));
            return(gitData_Files);
        }
예제 #14
0
 public static bool     delete_Repository_And_Files(this API_NGit nGit)
 {
     if (nGit.delete_Repository())
     {
         return(Files.deleteFolder(nGit.Path_Local_Repository, true));
     }
     return(false);
 }
예제 #15
0
 public static List <Ref> refs_Raw(this API_NGit nGit)
 {
     if (nGit.repository().notNull())
     {
         return(nGit.repository().GetAllRefs().Values.toList());
     }
     return(new List <Ref>());
 }
예제 #16
0
 public static NGit.Api.Git git(this API_NGit nGit)
 {
     if (nGit.notNull())
     {
         return(nGit.Git);
     }
     return(null);
 }
        public static string        file_Create_Random_File(this API_NGit nGit)
        {
            var fileName    = "name".add_RandomLetters().add(".txt");
            var fileContent = "content".add_RandomLetters();

            nGit.file_Write(fileName, fileContent);
            return(fileName);
        }
예제 #18
0
 public static bool isGitRepository(this API_NGit nGit)
 {
     return(nGit.notNull() &&
            nGit.Git.notNull() &&
            nGit.Repository.notNull() &&
            nGit.Path_Local_Repository.dirExists() &&
            nGit.Path_Local_Repository.isGitRepository());
 }
 public static string        files_Location(this API_NGit nGit)
 {
     if (nGit.notNull())
     {
         return(nGit.Path_Local_Repository);
     }
     return(null);
 }
예제 #20
0
        public bool Clone_Or_Open_O2_Platform_Scripts_Repository()
        {
            var sourceRepository = O2_Platform_Consts.GIT_HUB_O2_PLATFORM_SCRIPTS;
            var targetFolder     = O2_Platform_Config.Current.Folder_Scripts;

            nGit = new API_NGit().open_or_Clone(sourceRepository, targetFolder);
            return(nGit.isGitRepository());
        }
예제 #21
0
 public static string       branch_Current(this API_NGit nGit)
 {
     if (nGit.repository().notNull())
     {
         return(nGit.repository().GetBranch());
     }
     return(null);
 }
 public static string        file_FullPath(this API_NGit nGit, string virtualPath)
 {
     if (nGit.notNull() && nGit.Path_Local_Repository.valid() && nGit.Path_Local_Repository.dirExists() && virtualPath.notNull())
     {
         return(nGit.Path_Local_Repository.pathCombine(virtualPath));
     }
     return(null);
 }
 public static List <string> config_Sections(this API_NGit nGit)
 {
     if (nGit.repository().notNull())
     {
         return(nGit.config().GetSections().toList());
     }
     return(new List <string>());
 }
 public static StoredConfig      config(this API_NGit nGit)
 {
     if (nGit.repository().notNull())
     {
         return(nGit.repository().GetConfig());
     }
     return(null);
 }
예제 #25
0
 public static Repository   repository(this API_NGit nGit)
 {
     if (nGit.notNull())
     {
         return(nGit.Repository);
     }
     return(null);
 }
 public static RevWalk revCommits_Raw(this API_NGit nGit, int maxCount)
 {
     if (nGit.head().isNull())
     {
         return(nGit.revWalk());
     }
     return((RevWalk)nGit.Git.Log().SetMaxCount(maxCount).Call());
 }
예제 #27
0
 public static RevWalk revWalk(this API_NGit nGit)
 {
     if (nGit.notNull() && nGit.Repository.notNull())
     {
         return(new RevWalk(nGit.Repository));
     }
     return(null);
 }
 public static Status        status_Raw(this API_NGit nGit)
 {
     if (nGit.notNull())
     {
         return(nGit.Git.Status().Call());
     }
     return(null);
 }
        public static FileBasedConfig   config_Global(this API_NGit nGit)
        {
            var fs           = NGit.Util.FS.DETECTED;
            var systemReader = NGit.Util.SystemReader.GetInstance();
            var userConfig   = systemReader.OpenUserConfig(null, fs);

            userConfig.Load();
            return(userConfig);
        }
 public static string        remote_Url(this API_NGit nGit, string remoteName)
 {
     if (nGit.repository().notNull())
     {
         //no try-catch becasue can't trigger from UnitTest
         return(nGit.config().GetString("remote", remoteName, "url"));
     }
     return(null);
 }
예제 #31
0
 public static TM_UserData pushUserRepository(this TM_UserData userData, API_NGit nGit)
 {
     if (MiscUtils.runningOnLocalHost() && TMConfig.Current.getGitUserConfigFile().valid())  //don't push local changes in order to prevent git merge conflicts
     {
         "[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;
 }
예제 #32
0
 public Test_NGit_Support()
 {
     TempRepo = "_tempRepo".tempDir(true);
     NGitApi = new API_NGit();
 }
예제 #33
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");
        }
예제 #34
0
 public Test_NGit_Support()
 {
     NGitApi = new API_NGit();
 }