Exemplo n.º 1
0
        public async Task <SvnClientExecutionResult> UpdateAsync(string workingCopyDirectory, string additionalArguments)
        {
            var args = new SvnArgumentBuilder();

            args.Append("update");
            args.AppendQuoted(workingCopyDirectory);
            args.Append(additionalArguments);

            return(await this.ExecuteCommandLineAsync(args).ConfigureAwait(false));
        }
Exemplo n.º 2
0
        public async Task <SvnClientExecutionResult> ExportAsync(SvnPath sourcePath, string destinationDirectory, string additionalArguments)
        {
            var args = new SvnArgumentBuilder();

            args.Append("export");
            args.AppendQuoted(sourcePath.AbsolutePath);
            args.AppendQuoted(destinationDirectory);
            args.Append(additionalArguments);

            return(await this.ExecuteCommandLineAsync(args).ConfigureAwait(false));
        }
Exemplo n.º 3
0
        public async Task <SvnClientExecutionResult> DeleteAsync(SvnPath path, string message, string additionalArguments)
        {
            var args = new SvnArgumentBuilder();

            args.Append("delete");
            args.AppendQuoted(path.AbsolutePath);
            args.Append("-m");
            args.AppendQuoted(message);
            args.Append(additionalArguments);

            return(await this.ExecuteCommandLineAsync(args).ConfigureAwait(false));
        }
Exemplo n.º 4
0
        private async Task <SvnClientExecutionResult> ExecuteCommandLineAsync(SvnArgumentBuilder args)
        {
            args.Append("--non-interactive");
            args.Append("--trust-server-cert");

            if (!string.IsNullOrEmpty(this.userName))
            {
                args.Append("--username");
                args.AppendQuoted(this.userName);
            }
            if (this.password != null)
            {
                args.Append("--password");
                args.AppendSensitive(AH.Unprotect(this.password));
            }

            var startInfo = new RemoteProcessStartInfo
            {
                FileName  = this.svnExePath,
                Arguments = args.ToString()
            };

            this.log.LogDebug("Working directory: " + startInfo.WorkingDirectory);
            this.log.LogDebug("Executing: " + startInfo.FileName + " " + args.ToSensitiveString());

            var execOps = this.execOps.Value;

            using (var process = execOps.CreateProcess(startInfo))
            {
                var outputLines = new List <string>();
                var errorLines  = new List <string>();

                process.OutputDataReceived += (s, e) => { if (e?.Data != null)
                                                          {
                                                              outputLines.Add(e.Data);
                                                          }
                };
                process.ErrorDataReceived += (s, e) => { if (e?.Data != null)
                                                         {
                                                             errorLines.Add(e.Data);
                                                         }
                };

                process.Start();

                await process.WaitAsync(this.cancellationToken).ConfigureAwait(false);

                return(new SvnClientExecutionResult(process.ExitCode ?? -1, outputLines, errorLines));
            }
        }
Exemplo n.º 5
0
        public async Task <string> GetRevisionNumberAsync(SvnPath path)
        {
            var args = new SvnArgumentBuilder();

            args.Append("info");
            args.Append("--xml");
            args.AppendQuoted(path.AbsolutePath);
            var result = await this.ExecuteCommandLineAsync(args).ConfigureAwait(false);

            if (result.ErrorLines.Count > 0)
            {
                throw new InvalidOperationException(string.Join(Environment.NewLine, result.ErrorLines));
            }

            var info = XElement.Parse(string.Join(Environment.NewLine, result.OutputLines));

            return(info.Element("entry").Attribute("revision").Value);
        }
Exemplo n.º 6
0
        public async Task <IEnumerable <SvnPath> > EnumerateChildSourcePathsAsync(SvnPath path)
        {
            var args = new SvnArgumentBuilder();

            args.Append("ls");
            args.AppendQuoted(path.AbsolutePath);
            var result = await this.ExecuteCommandLineAsync(args).ConfigureAwait(false);

            if (result.ErrorLines.Count > 0)
            {
                throw new InvalidOperationException(string.Join(Environment.NewLine, result.ErrorLines));
            }

            var lines = from o in result.OutputLines
                        where o?.Length > 0
                        select o;

            return(lines.Select(o => new SvnPath(path, o)));
        }
Exemplo n.º 7
0
        public async Task <IEnumerable <SvnBranch> > EnumerateBranchesAsync(SvnPath path)
        {
            var branchesPath = new SvnPath(path, "branches/");

            var args = new SvnArgumentBuilder();

            args.Append("ls");
            args.Append("--xml");
            args.AppendQuoted(path.AbsolutePath);
            args.AppendQuoted(branchesPath.AbsolutePath);
            var result = await this.ExecuteCommandLineAsync(args).ConfigureAwait(false);

            if (result.ErrorLines.Count > 0)
            {
                throw new InvalidOperationException(string.Join(Environment.NewLine, result.ErrorLines));
            }

            var lists = XElement.Parse(string.Join(Environment.NewLine, result.OutputLines));

            if (lists.Elements("list").Count() != 2)
            {
                throw new InvalidOperationException($"expected 2 list elements but there are {lists.Elements("list").Count()}");
            }

            var trunkEntry    = lists.Elements("list").First().Elements("entry").FirstOrDefault(e => e.Attribute("kind").Value == "dir" && e.Element("name").Value == "trunk");
            var branchEntries = lists.Elements("list").Last().Elements("entry").Where(e => e.Attribute("kind").Value == "dir");

            var branches = new List <SvnBranch>();

            if (trunkEntry != null)
            {
                branches.Add(new SvnBranch(path, trunkEntry));
            }

            branches.AddRange(branchEntries.Select(e => new SvnBranch(branchesPath, e)));

            return(branches);
        }