-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathUGit.pas
More file actions
155 lines (137 loc) · 3.84 KB
/
UGit.pas
File metadata and controls
155 lines (137 loc) · 3.84 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
unit UGit;
interface
uses
Forms,
StdCtrls,
ComCtrls,
System.Classes,
Vcl.Controls,
UEditorForm;
type
TFGit = class(TForm)
LVRevisions: TListView;
BOK: TButton;
BCancel: TButton;
procedure LVRevisionsDblClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
public
procedure GitCall(const Call, Folder: string);
procedure ShowGUI(const Path: string);
procedure ShowConsole(const Path: string);
procedure ShowViewer(const Path: string);
function IsRepository(const Dir: string): Boolean;
procedure Execute(Tag: Integer; AEditor: TFEditForm);
end;
var
FGit: TFGit = nil;
implementation
uses
Windows,
SysUtils,
Dialogs,
JvGnugettext,
UStringRessources,
UConfiguration,
UMessages,
UJavaCommands,
UUtils;
{$R *.dfm}
function TFGit.IsRepository(const Dir: string): Boolean;
begin
Result := DirectoryExists(WithTrailingSlash(Dir) + '.git');
end;
procedure TFGit.LVRevisionsDblClick(Sender: TObject);
begin
ModalResult := mrOk;
end;
procedure TFGit.ShowGUI(const Path: string);
begin
MyJavaCommands.ShellExecuteFile(FConfiguration.GitFolder + '\cmd\git-gui.exe',
'', Path, SW_SHOWNORMAL);
end;
procedure TFGit.ShowViewer(const Path: string);
begin
MyJavaCommands.ShellExecuteFile(FConfiguration.GitFolder + '\cmd\gitk.exe',
'', Path, SW_SHOWNORMAL);
end;
procedure TFGit.ShowConsole(const Path: string);
begin
MyJavaCommands.ShellExecuteFile(FConfiguration.GitFolder + '\bin\bash.exe',
'', Path, SW_SHOWNORMAL);
end;
procedure TFGit.GitCall(const Call, Folder: string);
var
Git: string;
Clone: Boolean;
begin
Git := FConfiguration.GitFolder + '\bin\git.exe';
FMessages.ShowTab(K_Messages);
FMessages.DeleteTab(K_Messages);
FMessages.OutputLineTo(K_Messages, 'git ' + Call);
Screen.Cursor := crHourGlass;
Clone := (Pos('clone', Call) > 0);
if Clone then
FMessages.OutputLineTo(K_Messages, 'Please wait!');
if MyJavaCommands.ExecAndWait(Git, Call, Folder, FConfiguration.TempDir +
'error.txt', SW_HIDE) then
FMessages.ShowMessages(FConfiguration.TempDir + 'error.txt');
if Clone then
FMessages.OutputLineTo(K_Messages, 'Done!');
Screen.Cursor := crDefault;
end;
procedure TFGit.FormCreate(Sender: TObject);
begin
TranslateComponent(Self);
with LVRevisions do
begin
Columns[0].Caption := _(LNGRevision);
Columns[1].Caption := _(LNGAuthor);
Columns[2].Caption := _(LNGDate);
Columns[3].Caption := _(LNGMessage);
end;
Caption := _(LNGRevisions);
end;
procedure TFGit.Execute(Tag: Integer; AEditor: TFEditForm);
var
AMessage, AFile: string;
begin
if (Tag in [2, 5, 6, 7]) and not Assigned(AEditor) then
Exit;
if Assigned(AEditor) then begin
if AEditor.Modified then
AEditor.Save(False);
AFile := ExtractFileName(AEditor.Pathname);
end;
case Tag of
1:
GitCall('status', FConfiguration.GitLocalRepository);
2:
GitCall('add ' + AFile, FConfiguration.GitLocalRepository);
3:
if InputQuery('Commit', 'Message', AMessage) then
FGit.GitCall('commit -Message "' + AMessage + '"',
FConfiguration.GitLocalRepository);
4:
GitCall('log --stat', FConfiguration.GitLocalRepository);
5:
GitCall('reset HEAD ' + AFile, FConfiguration.GitLocalRepository);
6:
GitCall('checkout -- ' + AFile, FConfiguration.GitLocalRepository);
7:
GitCall('rm ' + AFile, FConfiguration.GitLocalRepository);
8:
GitCall('remote -v', FConfiguration.GitLocalRepository);
9:
GitCall('fetch ' + FConfiguration.GitRemoteRepository,
FConfiguration.GitLocalRepository);
10:
GitCall('push origin master', FConfiguration.GitLocalRepository);
11:
ShowGUI(FConfiguration.GitLocalRepository);
12:
ShowViewer(FConfiguration.GitLocalRepository);
13:
ShowConsole(FConfiguration.GitLocalRepository);
end;
end;
end.