public Task <List <RepositorySource> > Add(RepositorySourceAddRequest request)
        {
            var directoriesToAdd = request.RepositoryPaths
                                   .Select(path => new { remote = GitDataRetriever.GetRemoteUrl(path), path })
                                   .Where(dir => Directory.Exists(Path.Combine(dir.path, ".git")) && !string.IsNullOrEmpty(dir.remote))
                                   .ToList();

            var remotePaths = (from path in directoriesToAdd
                               select new
            {
                path = Path.GetFullPath(path.path),
                slug = Path.GetFullPath(path.path).Split(Path.DirectorySeparatorChar).LastOrDefault(),
                remote = new Uri(path.remote)
            }).ToList();

            var remotePathsSplit = (from remotePath in remotePaths
                                    select new
            {
                remotePath.path,
                remotePath.remote,
                remotePath.slug,
                remotePath.remote.Host,
                user = remotePath.remote.Segments[1].Replace("/", " "),
            }).ToList();

            var repositorySources = remotePathsSplit.GroupBy(group => new { group.Host, group.user }).Select(repositorySource =>
                                                                                                             new RepositorySource
            {
                Name         = repositorySource.Key.user.Replace(" ", ""),
                Domain       = repositorySource.Key.Host,
                Repositories = repositorySource.Select(repo => new RepositoryRemoteLink
                {
                    Local = new LocalRepository
                    {
                        Location = Path.GetFullPath(repo.path),
                        Name     = repo.slug
                    },
                    Origin = new RemoteRepository
                    {
                        Location = repo.remote.AbsoluteUri,
                        Name     = $"origin/{repo.slug}"
                    },
                    Slug = repo.slug
                }).ToList(),
                Source = Sources.Local
            }).ToList();

            foreach (var repositorySource in repositorySources)
            {
                _repositoryRegisterManager.UpdateRegister(repositorySource.GetFileName());
                _fileRepository.WriteServiceRepositories(repositorySource);
            }

            return(Task.FromResult(repositorySources));
        }
        public async Task <RepositorySource> Clone(CloneRequest cloneRequest, CancellationToken cancellationToken = default)
        {
            var existingRepository =
                _fileRepository.GetServiceRepositories(Domains.BitBucket, cloneRequest.GetRepositoriesRequest.User) ?? new RepositorySource
            {
                Name   = cloneRequest.GetRepositoriesRequest.User,
                Domain = Domains.BitBucket,
                Source = Sources.BitBucket
            };

            var existingSlugs = existingRepository.Repositories.Select(s => s.Slug).ToList();

            var repositories = await _bitBucketClient.GetRepositoriesAsync(cloneRequest.GetRepositoriesRequest, cancellationToken);

            var repositoriesToAdd = repositories
                                    .ToRepositories(cloneRequest.CloneDirectory)
                                    .Where(rep => !existingSlugs.Contains(rep.Slug))
                                    .ToList();

            foreach (var cloneProcess in repositoriesToAdd
                     .Select(repo => new
            {
                RunnableProcess = RepositoryManager
                                  .Clone(Git.Models.Clone.Create(repo.Local.Location, repo.Origin.Location, repo.Local.Name))
                                  .ToRunnableProcess(),
                Repo = repo
            }))
            {
                Console.WriteLine($"Cloning: {cloneProcess.Repo.Slug} into: {cloneProcess.Repo.Local.Location}");
                cloneProcess.RunnableProcess.Start();
                Console.WriteLine($"Cloned: {cloneProcess.Repo.Slug} into: {cloneProcess.Repo.Local.Location}");
            }

            existingRepository.Repositories.AddRange(repositoriesToAdd);

            _repositoryRegisterManager.UpdateRegister(existingRepository.GetFileName());
            return(_fileRepository.WriteServiceRepositories(existingRepository));
        }