예제 #1
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);
        }
예제 #2
0
 public static bool     delete_Repository(this API_NGit nGit)
 {
     nGit.close();
     if (nGit.files_Location().valid())
     {
         var folderToDelete = nGit.git_Folder();
         if (folderToDelete.dirExists())
         {
             //need to make the repo files read/write before deleting the repo folder
             foreach (var file in folderToDelete.files(true))
             {
                 file.file_Attribute_ReadOnly_Remove();
             }
             return(Files.deleteFolder(folderToDelete, true));
         }
     }
     return(false);
 }
예제 #3
0
 public static API_NGit open(this API_NGit nGit, string pathToLocalRepository)
 {
     nGit.Last_Exception = null;
     try
     {
         nGit.close();
         "[API_NGit] open: {0}".debug(pathToLocalRepository);
         nGit.Git                   = NGit.Api.Git.Open(pathToLocalRepository);
         nGit.Repository            = nGit.Git.GetRepository();
         nGit.Path_Local_Repository = pathToLocalRepository;
         return(nGit);
     }
     catch (Exception ex)
     {
         nGit.Last_Exception = ex;
         ex.log("[API_NGit] ");
     }
     return(null);
 }
예제 #4
0
        public static API_NGit clone(this API_NGit nGit, string sourceRepository, string targetFolder)
        {
            nGit.Last_Exception = null;
            "[API_NGit] cloning: {0} into {1}".debug(sourceRepository, targetFolder);
            try
            {
                if (targetFolder.dirExists())
                {
                    "[API_NGit] provided target folder already exists,please delete it or provide a difference one: {0}".error(targetFolder);
                    return(null);
                }
                nGit.close();
                var start         = DateTime.Now;
                var clone_Command = NGit.Api.Git.CloneRepository();

                clone_Command.SetDirectory(targetFolder);
                clone_Command.SetURI(sourceRepository);
                clone_Command.SetCredentialsProvider(nGit.Credentials);
                nGit.LastGitProgress = new GitProgress();
                clone_Command.SetProgressMonitor(nGit.LastGitProgress);

                nGit.Git                   = clone_Command.Call();
                nGit.Repository            = nGit.Git.GetRepository();
                nGit.Path_Local_Repository = targetFolder;

                "[API_NGit] clone completed in: {0}".debug(start.timeSpan_ToString());

                return(nGit);
            }
            catch (Exception ex)
            {
                nGit.Last_Exception = ex;
                ex.log("[API_NGit] ");
                if (ex.isNotInstanceOf <WebException>())
                {
                    Files.deleteFolder(targetFolder, true);
                }
            }
            return(null);
        }