Example #1
0
        private static void Fetch(Repository repo, Remote remote, CleanupSettings settings)
        {
            Console.WriteLine($"Refreshing repo");
            var fetchOptions = new FetchOptions
            {
                CredentialsProvider =
                    CredentialsFactory.CreateHandler(settings.AuthType, settings.UserName, settings.Password),
                Prune = true
            };

            Commands.Fetch(repo, remote.Name, new string[0], fetchOptions, null);
        }
Example #2
0
        private static void RemoveBranches(Repository repo, Remote remote, List <BranchInfo> orphans,
                                           CleanupSettings settings)
        {
            Console.WriteLine($"Found {orphans.Count()} orphan branches");
            Console.WriteLine("Cleaning up...");
            var pushOptions = new PushOptions
            {
                CredentialsProvider =
                    CredentialsFactory.CreateHandler(settings.AuthType, settings.UserName, settings.Password),
                OnPushStatusError = errors => Console.WriteLine($"{errors.Reference} - {errors.Message}.")
            };

            var chars = Console.WindowWidth - 20;

            foreach (var bi in orphans)
            {
                Console.Write($"Removing local: {bi.RemoteName.PadRightOrLimit(chars)}\r");
                repo.Branches.Remove(bi.LocalName);
            }
            Console.WriteLine($"Removing locals comleted".PadRightOrLimit(chars));

            if (settings.RunMode == RunMode.Full)
            {
                //now delete the branches on the remote
                var n = 0;
                chars = Console.WindowWidth - 30;
                foreach (var bis in orphans.Paged(settings.BatchSize))
                {
                    var remoteBranches = bis.Select(x => $":{x.RemoteName}").ToList();
                    repo.Network.Push(remote, pushRefSpecs: remoteBranches, pushOptions: pushOptions);
                    foreach (var bi in bis)
                    {
                        Console.Write($"Removing remote: {++n} {bi.RemoteName.PadRightOrLimit(chars)}\r");
                    }
                }
                Console.WriteLine($"Removing remotes completed".PadRightOrLimit(chars));
            }
        }