forked from gitextensions/gitextensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommitHelper.cs
55 lines (47 loc) · 1.42 KB
/
CommitHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.IO;
namespace GitCommands
{
public class CommitDto
{
public CommitDto(string message, bool amend)
{
Message = message;
Amend = amend;
}
public string Message { get; set; }
public string Result { get; set; }
public bool Amend { get; set; }
}
public class CommitHelper
{
public CommitHelper(CommitDto dto)
{
Dto = dto;
}
public CommitDto Dto { get; set; }
public void Execute(GitModule module)
{
if (Dto.Amend)
Dto.Result = module.RunGitCmd("commit --amend -m \"" + Dto.Message + "\"");
else
Dto.Result = module.RunGitCmd("commit -m \"" + Dto.Message + "\"");
}
public static void SetCommitMessage(GitModule module, string commitMessageText)
{
if (String.IsNullOrEmpty(commitMessageText))
{
File.Delete(GetCommitMessagePath(module));
return;
}
using (var textWriter = new StreamWriter(GetCommitMessagePath(module), false, module.CommitEncoding))
{
textWriter.Write(commitMessageText);
}
}
public static string GetCommitMessagePath(GitModule module)
{
return Path.Combine(module.GetGitDirectory(), "COMMITMESSAGE");
}
}
}