protected Classes.GitBatch WriteFeatureBranchGit(RepositoryVM repo, string startingFolder, string branchName)
        {
            var mainBat = startingFolder + @"\PullForFeatureBranch.bat";

            if (System.IO.File.Exists(mainBat))
            {
                System.IO.File.Delete(mainBat);
            }

            // see if folder for REPO is there and if not, pull it - if it is recheck out master and release
            var bat = new Classes.GitBatch(mainBat)
            {
                Redirect      = true,
                RedirectError = $@"{startingFolder.Replace(@"\\", @"\")}\ErrorFB.txt",
                RedirectFile  = $@"{startingFolder.Replace(@"\\", @"\")}\OutputFB.txt"
            };

            bat.AddLine($"echo start");

            var theFile       = repo.Name;
            var featurePrefix = _settings.Setting.GetSection("FeatureBranchPrefix").Value ?? "feature/";
            var releasePrefix = _settings.Setting.GetSection("ReleaseBranchName").Value ?? "release";
            var masterPrefix  = _settings.Setting.GetSection("MasterBranchName").Value ?? "master";

            var featureFile = $"{featurePrefix}{branchName}";

            if (featureFile.Length > 60)
            {
                featureFile = featureFile.Substring(0, 60);
            }

            bat.AddLine($"echo Working on '{theFile}'");

            bat.AddCD($@"{startingFolder}\{theFile}");
            bat.AddReset();

            if (repo.OffRelease)
            {
                bat.AddCheckout(releasePrefix, $"origin/{releasePrefix}");
                bat.AddLine($"git checkout -b {featureFile} {releasePrefix}");
            }
            else
            {
                bat.AddCheckout(masterPrefix, $"origin/{masterPrefix}");
                bat.AddLine($"git checkout -b {featureFile} {masterPrefix}");
            }

            bat.AddLine($"git push -u origin {featureFile}");

            bat.AddCD(startingFolder);

            bat.Write();

            return(bat);
        }
        public JsonResult DeleteBranch([DataSourceRequest] DataSourceRequest dsRequest, RepoBranchVM branch)
        {
            if (branch != null && ModelState.IsValid)
            {
                var branchPath  = branch.Name.Split("/");
                var canContinue = true;

                foreach (var bp in branchPath)
                {
                    if (bp == "release" || bp == "master" || bp == "develop" || bp == "tags")
                    {
                        canContinue = false;
                        break;
                    }
                }

                if (!canContinue)
                {
                    return(Json(new JsonMessage(true, "Cannot delete this branch")));
                }
                else
                {
                    var startingFolder = string.Empty;
                    CreateStartingFolder(ref startingFolder);

                    if (System.IO.Directory.Exists(startingFolder))
                    {
                        CreateStartingProjectFolder(ref startingFolder);

                        if (System.IO.Directory.Exists(startingFolder))
                        {
                            var vsts         = new Classes.VSTS.Vsts(HttpContext.Session.GetString(Session.TOKEN));
                            var selectedRepo = vsts.GetRepositoryOnGuid(branch.RepoGuid);

                            var repoName = selectedRepo.Name;

                            var mainBat = startingFolder + @"\DeleteFeatureBranch.bat";

                            if (System.IO.File.Exists(mainBat))
                            {
                                System.IO.File.Delete(mainBat);
                            }

                            var bat = new Classes.GitBatch(mainBat)
                            {
                                Redirect      = true,
                                RedirectError = $@"{startingFolder.Replace(@"\\", @"\")}\ErrorDelete.txt",
                                RedirectFile  = $@"{startingFolder.Replace(@"\\", @"\")}\OutputDelete.txt"
                            };

                            bat.AddLine($"echo start");

                            var newName = branch.Name.Replace("refs/heads/", string.Empty);

                            bat.AddCD($@"{startingFolder}\{repoName}");
                            bat.AddReset();
                            bat.AddCheckout("master", "master");
                            bat.AddLine($@"git branch -D {newName}");            // Remove from local
                            bat.AddLine($@"git push origin --delete {newName}"); // Remove from origin

                            bat.AddCD(startingFolder);

                            bat.Write();

                            bat.GitRun(startingFolder, HttpContext.Session.GetString(Session.USER), HttpContext.Session.GetString(Session.GIT));

                            return(Json(new JsonMessage(true, "Branch Deleted")));
                        }
                        else
                        {
                            return(Json(new JsonMessage(true, $"Unable to find starting folder {startingFolder}")));
                        }
                    }
                    else
                    {
                        return(Json(new JsonMessage(true, $"Unable to find starting folder {startingFolder}")));
                    }
                }
            }
            else
            {
                return(Json(new JsonMessage(true, "Invalid Model State")));
            }
        }
        public JsonResult CheckOutBranch(string name, string guid)
        {
            var startingFolder = string.Empty;
            var repoName       = string.Empty;

            name = name.Replace("refs/heads/", string.Empty);

            var vsts         = new Classes.VSTS.Vsts(HttpContext.Session.GetString(Session.TOKEN));
            var selectedRepo = vsts.GetRepositoryOnGuid(guid);

            repoName = selectedRepo.Name;

            try
            {
                CreateStartingFolder(ref startingFolder);

                if (System.IO.Directory.Exists(startingFolder))
                {
                    CreateStartingProjectFolder(ref startingFolder);

                    var mainBat = startingFolder + @"\CheckOutBranch.bat";

                    if (System.IO.File.Exists(mainBat))
                    {
                        System.IO.File.Delete(mainBat);
                    }

                    var bat = new Classes.GitBatch(mainBat)
                    {
                        Redirect      = true,
                        RedirectError = $@"{startingFolder.Replace(@"\\", @"\")}\Error.txt",
                        RedirectFile  = $@"{startingFolder.Replace(@"\\", @"\")}\output.txt"
                    };

                    bat.AddLine($"echo start");

                    bat.AddLine($"echo Working on '{name}'");

                    if (System.IO.Directory.Exists($"{startingFolder}\\{repoName}"))
                    {
                        bat.AddCD($@"{startingFolder}\{repoName}");
                        bat.AddReset();
                        bat.AddCheckout(name, $"origin/{name}");
                        bat.AddCD(startingFolder);

                        bat.Write();

                        bat.GitRun(startingFolder, HttpContext.Session.GetString(Session.USER), HttpContext.Session.GetString(Session.GIT));

                        return(Json(new JsonMessage(true, name + " : Pulled")));
                    }
                    else
                    {
                        return(Json(new JsonMessage(false, " : FAILED - you need to clone repository first")));
                    }
                }
                else
                {
                    return(Json(new JsonMessage(false, " : FAILED - you need to clone repository first")));
                }
            }
            catch (System.Exception ex)
            {
                return(Json(new JsonMessage(false, $"{repoName} - Failed to check out - [{ex.Message}]")));
            }
        }