Ejemplo n.º 1
0
        public async Task <Tuple <Repository, string> > CloneAsync(string url, string path, string name)
        {
            Repository repository = new Repository();
            var        error      = string.Empty;
            await Task.Run(async() =>
            {
                var clone = await _gitService.CloneAsync(url, path).ConfigureAwait(false);
                error     = await GitParser.ParseError(clone.Error).ConfigureAwait(false);
                if (string.IsNullOrWhiteSpace(error))
                {
                    path              = path + $@"\{name}";
                    var branches      = await _gitService.GetBranchesAsync(path);
                    var parseBranches = await GitParser.ParseBranchAsync(branches.Output);
                    repository        = new Repository()
                    {
                        Id       = Guid.NewGuid(),
                        Name     = name,
                        Path     = path,
                        Url      = url,
                        Branches = parseBranches
                    };
                    foreach (var item in parseBranches)
                    {
                        await _gitService.CheckoutAsync(path, item.Name);
                    }

                    var branchesWirhCommits =
                        await GetBranchWithCommitsAsync(path, parseBranches).ConfigureAwait(false);
                    repository.Branches = branchesWirhCommits;
                    await _repositoriesService.AddRepositoryAsync(repository).ConfigureAwait(false);
                    error = null;
                }
                else
                {
                    repository = null;
                }
            }).ConfigureAwait(false);

            var result = Tuple.Create(repository, error);

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <Tuple <Repository, string> > AddExistingRepositoryAsync(string path)
        {
            var repository = new Repository();
            var branches   = await _gitService.GetBranchesAsync(path).ConfigureAwait(false);

            var error = await GitParser.ParseError(branches.Error).ConfigureAwait(false);

            if (string.IsNullOrWhiteSpace(error))
            {
                var parseBranches = await GitParser.ParseBranchAsync(branches.Output).ConfigureAwait(false);

                var branchesWithCommit = await GetBranchWithCommitsAsync(path, parseBranches).ConfigureAwait(false);

                var createName = path.Split('\\');
                var name       = createName.Last().Trim();
                var remote     = await _gitService.RemoteAsync(path).ConfigureAwait(false);

                var url = await GitParser.ParseRemoteAsync(remote.Output).ConfigureAwait(false);

                repository = new Repository()
                {
                    Id       = Guid.NewGuid(),
                    Name     = name,
                    Path     = path,
                    Branches = branchesWithCommit,
                    Url      = url
                };
                await _repositoriesService.AddRepositoryAsync(repository).ConfigureAwait(false);

                error = null;
            }
            else
            {
                repository = null;
            }
            var result = Tuple.Create(repository, error);

            return(result);
        }