-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCommitMenu.cs
130 lines (106 loc) · 4.3 KB
/
CommitMenu.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Interop;
namespace FileManager
{
public partial class CommitMenu : Form
{
private string path;
Form1 form1;
public CommitMenu(Form1 form)
{
InitializeComponent();
form1 = form;
label1.Text = "The list of Staged Changes";
label2.Text = "Enter a commit message";
button1.Text = "Commit";
button2.Text = "Exit";
textBox1.ReadOnly = true;
textBox1.Enabled = false;
textBox1.Enabled = true;
}
public void SetTextBeforeCommit(string directoryPath, string[] result)
{
this.path = directoryPath;
textBox1.Text += directoryPath + "\r\n";
int noneFilesInStage = 0;
foreach (string staged in result)
{
if (String.IsNullOrEmpty(staged))
{
noneFilesInStage++;
continue;
}
else
{
textBox1.Text += staged + "\r\n";
}
}
if(noneFilesInStage == result.Length)
{
button1.Enabled = false; // stage에 아무 파일이 없으면 commit button 비활성화
textBox1.Text = "The File to commit does not exist on Stage.\r\n" +
"Press Exit to return to the main screen.";
textBox2.ReadOnly = true;
textBox2.Enabled = false;
textBox2.Enabled = true;
}
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
this.Close(); // exit and return to Form1
}
private void button1_Click(object sender, EventArgs e) // git commit button click
{
// cmd를 사용하기 위한 준비
ProcessStartInfo cmd = new ProcessStartInfo();
Process process = new Process();
string directoryPath;
directoryPath = this.path;
string[] gitAfterCommit;
cmd.FileName = @"cmd";
cmd.WindowStyle = ProcessWindowStyle.Hidden; // cmd창이 숨겨지도록 하기
cmd.CreateNoWindow = true; // cmd창을 띄우지 안도록 하기
cmd.UseShellExecute = false;
cmd.RedirectStandardOutput = true; // cmd창에서 데이터를 가져오기
cmd.RedirectStandardInput = true; // cmd창으로 데이터 보내기
cmd.RedirectStandardError = true; // cmd창에서 오류 내용 가져오기
process.EnableRaisingEvents = false;
process.StartInfo = cmd;
process.Start(); // cmd 명령 입히는거 시작
process.StandardInput.Write(@"cd " + directoryPath + Environment.NewLine);
string commitMsg = textBox2.Text.Replace("\r\n", " / ");
process.StandardInput.Write(@"git commit -m " + "\"" + commitMsg + "\"" + Environment.NewLine);
process.StandardInput.Close(); // cmd 명령 입력 끝
StreamReader reader = process.StandardOutput;
string output = reader.ReadToEnd();
gitAfterCommit = output.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
StreamReader readError = process.StandardError;
string error = readError.ReadToEnd();
if (error.Contains("error") || error.Contains("fatal"))
{
form1.setTextAfterCommit(error, gitAfterCommit, textBox2.Text);
}
else
{
form1.setTextAfterCommit(null, gitAfterCommit, textBox2.Text);
}
process.WaitForExit();
process.Close(); // cmd 창을 닫음
this.Close(); // commitMenu close
}
}
}