예제 #1
0
        public RepositoryChange[] Changes(string since = null, string until = null, string filename = null)
        {
            string revset = null;
            if (!String.IsNullOrEmpty(since) || !String.IsNullOrEmpty(until))
            {
                revset = String.Join(String.Empty,
                                     "--rev (", since, "..", until, ")",
                                     String.IsNullOrEmpty(since) ? null : "-" + since,
                                     String.IsNullOrEmpty(until) ? null : "-" + until);
            }

            var logArgs = new[]
                        {
                            "log --template \"changeset: {node}\nuser: {author}\ndate: {date|rfc3339date}\ndescription: \n{desc}\n\"",
                            revset,
                            filename,
                        };
            ProcessManager logCmd = new ProcessManager("hg", logArgs, this.LocalRepositoryPath).Run();
            if (logCmd.ExitCode != (int)GitReturnCode.Success)
            {
                throw new ApplicationException(String.Format("hg exit code: {0}\r\nstdout:{1}\r\nstderr:{2}", logCmd.ExitCode, logCmd.StandardOutput, logCmd.StandardError));
            }

            List<RepositoryChange> changes = new List<RepositoryChange>();
            RepositoryChange change = null;
            bool description = false;
            foreach (var line in logCmd.StandardOutput.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries))
            {
                if (line.StartsWith("changeset:"))
                {
                    description = false;

                    change = new RepositoryChange()
                    {
                        Id = line.Substring(10).Trim(),
                    };

                    changes.Add(change);
                }
                else if (line.StartsWith("user:"******"date:"))
                {
                    change.Date = Convert.ToDateTime(line.Substring(6).Trim());
                }
                else if (line.StartsWith("description:"))
                {
                    description = true;
                }
                else if (description)
                {
                    change.Message = change.Message + (String.IsNullOrEmpty(change.Message) ? String.Empty : "\r\n") + line;
                }
            }

            return changes.ToArray();
        }
예제 #2
0
        public RepositoryChange[] Changes(string since = null, string until = null, string filename = null)
        {
            var logArgs = new[]
                        {
                            "log",
                            "--date=rfc",
                            String.IsNullOrEmpty(since) ? String.Empty : since + "..",
                            until ?? String.Empty,
                            filename ?? String.Empty,
                        };
            ProcessManager logCmd = new ProcessManager("git", logArgs, this.LocalRepositoryPath).Run();
            if (logCmd.ExitCode != (int)GitReturnCode.Success)
            {
                throw new ApplicationException(String.Format("git exit code: {0}\r\nstdout:{1}\r\nstderr:{2}", logCmd.ExitCode, logCmd.StandardOutput, logCmd.StandardError));
            }

            List<RepositoryChange> changes = new List<RepositoryChange>();
            RepositoryChange change = null;
            foreach (var line in logCmd.StandardOutput.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries))
            {
                if (line.StartsWith("commit "))
                {
                    change = new RepositoryChange()
                    {
                        Id = line.Substring(7),
                    };

                    changes.Add(change);
                }
                else if (line.StartsWith("Author: "))
                {
                    change.Author = line.Substring(8);
                }
                else if (line.StartsWith("Date:   "))
                {
                    change.Date = Convert.ToDateTime(line.Substring(8));
                }
                else if (line.StartsWith("    "))
                {
                    change.Message = change.Message + (String.IsNullOrEmpty(change.Message) ? String.Empty : "\r\n") + line.Substring(4);
                }
            }

            return changes.ToArray();
        }
예제 #3
0
        public MsbuildProcess Build()
        {
            string msbuildPath = this.GetMsbuildPath();
            string[] args = new[]
                {
                    "/nologo",
                    this.Project,
                    String.IsNullOrEmpty(this.Target) ? null : "/t:" + this.Target,
                    String.IsNullOrEmpty(this.LogPath) ? null : "/flp:logfile=" + PathExtension.QuotePathIfNecessary(this.LogPath),
                    this.PropertiesForCommandLine(),
                };
            ProcessManager msbuild = new ProcessManager(msbuildPath, args, this.WorkingFolder).Run();

            this.Output = msbuild.StandardOutput;
            this.ExitCode = msbuild.ExitCode;

            return this;
        }
예제 #4
0
        public bool Update(bool rebase = false)
        {
            ProcessManager pullCmd = null;
            if (Directory.Exists(this.LocalRepositoryPath))
            {
                var pullArgs = new[]
                    {
                        "pull",
                        "-u",
                        rebase ? "--rebase" : null,
                    };
                pullCmd = new ProcessManager("hg", pullArgs, this.LocalRepositoryPath).Run();
            }

            // No repository, clone from the remote.
            if (pullCmd == null || pullCmd.ExitCode == (int)GitReturnCode.NoRepository)
            {
                string[] cloneArgs = new[]
                {
                    "clone",
                    "-q",
                    String.IsNullOrEmpty(this.Branch) ? String.Empty : " -b " + this.Branch,
                    this.RemoteRepositoryPath,
                    this.LocalRepositoryPath,
                };

                ProcessManager cloneCmd = new ProcessManager("hg", cloneArgs).Run();
                if (cloneCmd.ExitCode != (int)GitReturnCode.Success)
                {
                    throw new ApplicationException(String.Format("hg exit code: {0}\r\nstdout:{1}\r\nstderr:{2}", cloneCmd.ExitCode, cloneCmd.StandardOutput, cloneCmd.StandardError));
                }

                this.LastUpdated = DateTime.UtcNow;
                return true;
            }
            else if (pullCmd.ExitCode == (int)GitReturnCode.Success)
            {
                if (String.IsNullOrEmpty(pullCmd.StandardError) &&
                    (String.IsNullOrEmpty(pullCmd.StandardOutput) ||
                     pullCmd.StandardOutput.TrimEnd().EndsWith("no changes found", StringComparison.OrdinalIgnoreCase)))
                {
                    return false;
                }

                this.LastUpdated = DateTime.UtcNow;
                return true;
            }
            else
            {
                throw new ApplicationException(String.Format("hg exit code: {0}\r\nstdout:{1}\r\nstderr:{2}", pullCmd.ExitCode, pullCmd.StandardOutput, pullCmd.StandardError));
            }
        }
예제 #5
0
 public void Clean()
 {
     if (Directory.Exists(this.LocalRepositoryPath))
     {
         ProcessManager cleanCmd = new ProcessManager("hg", "clean --all", this.LocalRepositoryPath).Run();
     }
 }
예제 #6
0
        /// <summary>
        /// Checks the current status of the local repository with
        /// respect to the remote repository.
        /// </summary>
        /// <returns>Status of the local repository.</returns>
        public RepositoryStatus Check()
        {
            if (!Directory.Exists(this.LocalRepositoryPath))
            {
                return RepositoryStatus.Absent;
            }

            ProcessManager incomingCmd = new ProcessManager("hg", "incoming", this.LocalRepositoryPath).Run();
            if (incomingCmd.ExitCode == 0)
            {
                return RepositoryStatus.OutOfDate;
            }
            else if (incomingCmd.ExitCode == 1)
            {
                return RepositoryStatus.UpToDate;
            }
            else if (incomingCmd.ExitCode == (int)HgReturnCode.NoRepository)
            {
                return RepositoryStatus.Absent;
            }

            return RepositoryStatus.Error;
        }
예제 #7
0
        /// <summary>
        /// Checks the current status of the local repository with
        /// respect to the remote repository.
        /// </summary>
        /// <returns>Status of the local repository.</returns>
        public RepositoryStatus Check()
        {
            if (!Directory.Exists(this.LocalRepositoryPath))
            {
                return RepositoryStatus.Absent;
            }

            ProcessManager fetchCmd = new ProcessManager("git", "fetch --dry-run", this.LocalRepositoryPath).Run();
            if (fetchCmd.ExitCode == (int)GitReturnCode.Success)
            {
                // If nothing was fetched, check to see if there are still diffs to be
                // merged from the origin. Technically speaking this is not necessary
                // since all of our fetches are done in dry run but this will catch
                // stuff that slips through.
                //
                // TODO: what about local changes that have not been pushed?
                if (String.IsNullOrEmpty(fetchCmd.StandardOutput) && String.IsNullOrEmpty(fetchCmd.StandardError))
                {
                    var logArgs = new[]
                        {
                            "log",
                            "..@{u}",
                            "--abbrev-commit",
                            "--format=oneline",
                        };
                    ProcessManager logCmd = new ProcessManager("git", logArgs, this.LocalRepositoryPath).Run();
                    if (logCmd.ExitCode != (int)GitReturnCode.Success)
                    {
                        throw new ApplicationException(String.Format("git exit code: {0}\r\nstdout:{1}\r\nstderr:{2}", logCmd.ExitCode, logCmd.StandardOutput, logCmd.StandardError));
                    }

                    if (String.IsNullOrEmpty(logCmd.StandardOutput) && String.IsNullOrEmpty(logCmd.StandardError))
                    {
                        return RepositoryStatus.UpToDate;
                    }
                }

                return RepositoryStatus.OutOfDate;
            }
            else if (fetchCmd.ExitCode == (int)GitReturnCode.NoRepository)
            {
                return RepositoryStatus.Absent;
            }

            return RepositoryStatus.Error;
        }
예제 #8
0
 public void Clean()
 {
     ProcessManager cleanCmd = null;
     if (Directory.Exists(this.LocalRepositoryPath))
     {
         var args = new[]
             {
                 "clean",
                 "-dxf",
             };
         cleanCmd = new ProcessManager("git", args, this.LocalRepositoryPath).Run();
     }
 }