protected override int HandleCommand() { string cloneDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")); string manifestPath = Path.Combine(cloneDir, "mr.manifest.json"); ConsoleEx.PrintLine($"Cloning manifest repo to {cloneDir}"); ProgressBar progressBar = ConsoleEx.ProgressBar(new ProgressBarSpec { Format = "Cloning repository... [<<bar>>] <<percentage>>%", }, style: ProgressBarStyle.Shaded); var cloneOptions = new CloneOptions { OnCheckoutProgress = (path, completedSteps, totalSteps) => { progressBar.Value = (completedSteps * 100) / totalSteps; } }; Repository.Clone(ManifestRepoUrl.ToString(), cloneDir, cloneOptions); try { using (var repo = new Repository(cloneDir)) { List <Branch> branches = repo.Branches .Where(b => b.IsRemote) .OrderBy(b => b.FriendlyName, StringComparer.OrdinalIgnoreCase) .ToList(); foreach (var b in branches) { string remotePrefix = $"{b.RemoteName}/"; Branch branch = LibGit2Sharp.Commands.Checkout(repo, b); if (!File.Exists(manifestPath)) { continue; } string displayName = b.FriendlyName.Substring(remotePrefix.Length); ConsoleEx.PrintLine(displayName); if (ShowContent) { string manifestContent = File.ReadAllText(manifestPath); ConsoleEx.PrintIndented(manifestContent, 4); } } } } finally { //TODO: Delete clone dir //if (Directory.Exists(cloneDir)) // Directory.Delete(cloneDir, true); } return(0); }
private void CloneManifestRepo(ProgressBar progressBar) { string manifestRepoDir = Path.Combine(RootDirectory.FullName, ManifestDirectory); var cloneOptions = new CloneOptions { CredentialsProvider = _credentialProvider.Provide, OnCheckoutProgress = (path, completedSteps, totalSteps) => { progressBar.Value = (completedSteps * 100) / totalSteps; } }; if (!string.IsNullOrEmpty(Branch)) { cloneOptions.BranchName = Branch; } string result = Repository.Clone(ManifestRepoUrl.ToString(), manifestRepoDir, cloneOptions); }