Пример #1
0
        public GitCommitResult Commit(string message, bool amend = false, bool signoff = false)
        {
            if (!this.HasGitRepository)
            {
                return(null);
            }

            if (string.IsNullOrEmpty(message))
            {
                throw new ArgumentException("Commit message must not be null or empty!", "message");
            }

            GitCommitResult result = new GitCommitResult();

            if (GitBash.Exists)
            {
                var msgFile = Path.Combine(this.repository.Directory, "COMMITMESSAGE");
                File.WriteAllText(msgFile, message);
                try
                {
                    string opt = "";
                    if (amend)
                    {
                        opt += "--amend ";
                    }
                    if (signoff)
                    {
                        opt += "--signoff ";
                    }

                    var bashResult = GitBash.Run(string.Format("commit -F \"{0}\" {1}", msgFile, opt), this.GitWorkingDirectory);
                    if (bashResult.HasError)
                    {
                        result.Message = bashResult.Error;
                    }
                    else
                    {
                        result.Message = bashResult.Output;
                        result.IsSha1  = true;
                    }
                }
                finally
                {
                    File.Delete(msgFile);
                }
            }
            else
            {
                try
                {
                    var git = new Git(this.repository);
                    var rev = git.Commit().SetMessage(message).SetAmend(amend).Call();
                    result.Message = rev.Name;
                    result.IsSha1  = true;
                }
                catch (Exception ex)
                {
                    result.Message = ex.Message;
                }
            }
            Refresh();

            return(result);
        }
        public GitCommitResult Commit(string message, bool amend = false, bool signoff = false)
        {
            if (!this.HasGitRepository) return null;

            if (string.IsNullOrEmpty(message))
                throw new ArgumentException("Commit message must not be null or empty!", "message");

            GitCommitResult result = new GitCommitResult();

            if (GitBash.Exists)
            {
                var msgFile = Path.Combine(this.repository.Directory, "COMMITMESSAGE");
                File.WriteAllText(msgFile, message);
                try
                {
                    string opt = "";
                    if (amend) opt += "--amend ";
                    if (signoff) opt += "--signoff ";

                    var bashResult = GitBash.Run(string.Format("commit -F \"{0}\" {1}", msgFile, opt), this.GitWorkingDirectory);
                    if (bashResult.HasError)
                        result.Message = bashResult.Error;
                    else
                    {
                        result.Message = bashResult.Output;
                        result.IsSha1 = true;
                    }
                }
                finally
                {
                    File.Delete(msgFile);
                }
            }
            else
            {
                try
                {
                    var git = new Git(this.repository);
                    var rev = git.Commit().SetMessage(message).SetAmend(amend).Call();
                    result.Message = rev.Name;
                    result.IsSha1 = true;
                }
                catch (Exception ex)
                {
                    result.Message = ex.Message;
                }
            }
            Refresh();

            return result;
        }