GitScc.GitRepository.Commit C# (CSharp) Method

Commit() public method

public Commit ( string message, bool amend = false, bool signoff = false ) : GitActionResult
message string
amend bool
signoff bool
return GitActionResult
        public GitActionResult<string> Commit(string message, bool amend = false, bool signoff = false)
        {
            var result = new GitActionResult<string>();
            using (var repository = GetRepository())
            {
                if (string.IsNullOrEmpty(message))
                {
                    result.Succeeded = false;
                    result.ErrorMessage = "Commit message must not be null or empty!";
                    //throw new ArgumentException("Commit message must not be null or empty!", "message");
                }
                else
                {
                    Signature author = repository.Config.BuildSignature(DateTimeOffset.Now);
                    Signature committer = author;

                    CommitOptions opts = new CommitOptions();
                    opts.AmendPreviousCommit = amend;
                    var commit = repository.Commit(message, author, committer, opts);
                    result.Succeeded = true;
                    result.Item = commit.Sha;
                }
                return result;
            }
        }

Usage Example

Esempio n. 1
0
        public void AmendCommitTest()
        {
            GitRepository.Init(tempFolder);
            File.WriteAllLines(tempFilePath, lines);

            GitRepository tracker = new GitRepository(tempFolder);
            tracker.StageFile(tempFile);

            tracker.Commit("中文 1čtestč");
            Assert.IsTrue(tracker.LastCommitMessage.Equals("中文 1čtestč"));

            File.WriteAllText(tempFile, "changed text");
            tracker.StageFile(tempFile);
            tracker.Commit("new message", true);
            Assert.IsTrue(tracker.LastCommitMessage.Equals("new message"));
        }
All Usage Examples Of GitScc.GitRepository::Commit