1 | unit UGit;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, UVCS, UBackend;
|
---|
9 |
|
---|
10 | type
|
---|
11 |
|
---|
12 | { TBackendGit }
|
---|
13 |
|
---|
14 | TBackendGit = class(TBackend)
|
---|
15 | constructor Create;
|
---|
16 | function IsWorkingCopy(Directory: string): Boolean; override;
|
---|
17 | end;
|
---|
18 |
|
---|
19 |
|
---|
20 | { TGit }
|
---|
21 |
|
---|
22 | TGit = class(TWorkingCopy)
|
---|
23 | protected
|
---|
24 | procedure Execute(Parameters: array of string);
|
---|
25 | public
|
---|
26 | procedure Checkout; override;
|
---|
27 | procedure Update; override;
|
---|
28 | procedure CleanUp; override;
|
---|
29 | procedure Commit(Message: TStrings); override;
|
---|
30 | procedure Move(Source, Dest: string); override;
|
---|
31 | procedure Merge; override;
|
---|
32 | procedure Add(FileName: string); override;
|
---|
33 | procedure GetLog(FileName: string; Log: TLogList); override;
|
---|
34 | end;
|
---|
35 |
|
---|
36 | { TRepositoryGit }
|
---|
37 |
|
---|
38 | TRepositoryGit = class(TRepository)
|
---|
39 | protected
|
---|
40 | procedure Execute(Parameters: array of string);
|
---|
41 | public
|
---|
42 | procedure Init; override;
|
---|
43 | end;
|
---|
44 |
|
---|
45 |
|
---|
46 | implementation
|
---|
47 |
|
---|
48 | { TRepositoryGit }
|
---|
49 |
|
---|
50 | procedure TRepositoryGit.Execute(Parameters: array of string);
|
---|
51 | begin
|
---|
52 | ExecuteProcess('/usr/bin/git', Parameters);
|
---|
53 | end;
|
---|
54 |
|
---|
55 | procedure TRepositoryGit.Init;
|
---|
56 | begin
|
---|
57 | Execute(['init', Path]);
|
---|
58 | end;
|
---|
59 |
|
---|
60 | { TBackendGit }
|
---|
61 |
|
---|
62 | constructor TBackendGit.Create;
|
---|
63 | begin
|
---|
64 | Name := 'Git';
|
---|
65 | HomePage := 'https://git-scm.com/';
|
---|
66 | WorkingCopyClass := TGit;
|
---|
67 | RepositoryClass := TRepositoryGit;
|
---|
68 | end;
|
---|
69 |
|
---|
70 | function TBackendGit.IsWorkingCopy(Directory: string): Boolean;
|
---|
71 | begin
|
---|
72 | Result := DirectoryExists(Directory + DirectorySeparator + '.git');
|
---|
73 | end;
|
---|
74 |
|
---|
75 | { TGit }
|
---|
76 |
|
---|
77 | procedure TGit.Execute(Parameters: array of string);
|
---|
78 | begin
|
---|
79 | ExecuteProcess('/usr/bin/git', Parameters);
|
---|
80 | end;
|
---|
81 |
|
---|
82 | procedure TGit.Checkout;
|
---|
83 | begin
|
---|
84 | Execute(['clone', RepositoryURL, Path]);
|
---|
85 | end;
|
---|
86 |
|
---|
87 | procedure TGit.Update;
|
---|
88 | begin
|
---|
89 | Execute(['fetch']);
|
---|
90 | end;
|
---|
91 |
|
---|
92 | procedure TGit.CleanUp;
|
---|
93 | begin
|
---|
94 | Execute(['cleanup']);
|
---|
95 | end;
|
---|
96 |
|
---|
97 | procedure TGit.Commit(Message: TStrings);
|
---|
98 | begin
|
---|
99 | Execute(['config', 'user.name "' + UserName + '"']);
|
---|
100 | Execute(['config', 'user.email "' + Email + '"']);
|
---|
101 | Execute(['commit', '-m "' + Message.Text + '"']);
|
---|
102 | end;
|
---|
103 |
|
---|
104 | procedure TGit.Move(Source, Dest: string);
|
---|
105 | begin
|
---|
106 | Execute(['mv', Source, Dest]);
|
---|
107 | end;
|
---|
108 |
|
---|
109 | procedure TGit.Merge;
|
---|
110 | begin
|
---|
111 | Execute(['merge']);
|
---|
112 | end;
|
---|
113 |
|
---|
114 | procedure TGit.Add(FileName: string);
|
---|
115 | begin
|
---|
116 | Execute(['add', FileName]);
|
---|
117 | end;
|
---|
118 |
|
---|
119 | procedure TGit.GetLog(FileName: string; Log: TLogList);
|
---|
120 | begin
|
---|
121 | end;
|
---|
122 |
|
---|
123 | end.
|
---|
124 |
|
---|