public async Task <BranchStatus> GetEditBranchStatus(string editBranchName) { Log.LogTrace("GetEditBranchStatus: {0}", editBranchName); var git = _gitWrapperFactory.MakeGitWrapper(_repositoryPath); var branchList = await git.ListBranches(editBranchName); if (branchList.Length == 0) { return(null); } var aheadCount = await git.RevListCount("refs/heads/develop..refs/heads/" + editBranchName); var behindCount = await git.RevListCount("refs/heads/" + editBranchName + "..refs/heads/develop"); return(new BranchStatus(editBranchName, "develop", aheadCount, behindCount)); }
public async Task CloneRepository(string repository, string targetDirectory, string authenticationToken, UserAccount userAccount) { if (!await EnsureRepository(repository, targetDirectory, authenticationToken, userAccount)) { throw new WorkerException("Failed to validate remote repository {0}. Please check that the repository exists and that you have write access to it.", repository); } var cloneWrapper = _gitWrapperFactory.MakeGitWrapper(Configuration.RepoBaseDir); ProgressLog.Info("Cloning {0}", repository); var cloneResult = await cloneWrapper.Clone(repository, targetDirectory, depth : 1, branch : "gh-pages"); if (!cloneResult.Success) { LogCommandError(cloneResult, $"Clone of repository {repository} gh-pages branch failed."); ProgressLog.Info("Clone of gh-pages branch failed. Attempting to clone default branch and create a new gh-pages branch"); cloneResult = await cloneWrapper.Clone(repository, targetDirectory, depth : 1); if (!cloneResult.Success) { LogCommandError(cloneResult, $"Clone of repository {repository} failed."); throw new WorkerException("Clone of repository {0} failed.", repository); } var repoDir = Path.Combine(Configuration.RepoBaseDir, targetDirectory); var branchWrapper = _gitWrapperFactory.MakeGitWrapper(repoDir); var branchResult = await branchWrapper.NewBranch("gh-pages", force : true); if (!branchResult.Success) { LogCommandError(cloneResult, $"Failed to create a new gh-pages branch in the repository {repository}."); throw new WorkerException("Failed to create a gh-pages branch in the repository {0}", repository); } await PushChanges(repository, repoDir, authenticationToken, true); } ProgressLog.Info("Clone of {0} complete", repository); }