@andrebuzeli/git-mcp 5.0.5 → 5.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +143 -89
  3. package/dist/config.d.ts +72 -71
  4. package/dist/config.d.ts.map +1 -1
  5. package/dist/config.js +226 -139
  6. package/dist/config.js.map +1 -1
  7. package/dist/index.d.ts +15 -17
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +133 -128
  10. package/dist/index.js.map +1 -1
  11. package/dist/providers/base-provider.d.ts +42 -153
  12. package/dist/providers/base-provider.d.ts.map +1 -1
  13. package/dist/providers/base-provider.js +42 -302
  14. package/dist/providers/base-provider.js.map +1 -1
  15. package/dist/providers/gitea-provider.d.ts +67 -118
  16. package/dist/providers/gitea-provider.d.ts.map +1 -1
  17. package/dist/providers/gitea-provider.js +484 -1161
  18. package/dist/providers/gitea-provider.js.map +1 -1
  19. package/dist/providers/github-provider.d.ts +70 -81
  20. package/dist/providers/github-provider.d.ts.map +1 -1
  21. package/dist/providers/github-provider.js +638 -278
  22. package/dist/providers/github-provider.js.map +1 -1
  23. package/dist/providers/index.d.ts +9 -9
  24. package/dist/providers/index.d.ts.map +1 -1
  25. package/dist/providers/index.js +13 -19
  26. package/dist/providers/index.js.map +1 -1
  27. package/dist/providers/provider-factory.d.ts +29 -59
  28. package/dist/providers/provider-factory.d.ts.map +1 -1
  29. package/dist/providers/provider-factory.js +134 -265
  30. package/dist/providers/provider-factory.js.map +1 -1
  31. package/dist/providers/provider-operation-handler.d.ts +93 -0
  32. package/dist/providers/provider-operation-handler.d.ts.map +1 -0
  33. package/dist/providers/provider-operation-handler.js +331 -0
  34. package/dist/providers/provider-operation-handler.js.map +1 -0
  35. package/dist/providers/types.d.ts +201 -355
  36. package/dist/providers/types.d.ts.map +1 -1
  37. package/dist/providers/types.js +3 -2
  38. package/dist/providers/types.js.map +1 -1
  39. package/dist/server.d.ts +34 -8
  40. package/dist/server.d.ts.map +1 -1
  41. package/dist/server.js +436 -494
  42. package/dist/server.js.map +1 -1
  43. package/dist/tools/git-analytics.d.ts +239 -16
  44. package/dist/tools/git-analytics.d.ts.map +1 -1
  45. package/dist/tools/git-analytics.js +737 -25
  46. package/dist/tools/git-analytics.js.map +1 -1
  47. package/dist/tools/git-archive.d.ts +109 -15
  48. package/dist/tools/git-archive.d.ts.map +1 -1
  49. package/dist/tools/git-archive.js +462 -10
  50. package/dist/tools/git-archive.js.map +1 -1
  51. package/dist/tools/git-backup.d.ts +101 -15
  52. package/dist/tools/git-backup.d.ts.map +1 -1
  53. package/dist/tools/git-backup.js +410 -10
  54. package/dist/tools/git-backup.js.map +1 -1
  55. package/dist/tools/git-branches.d.ts +141 -15
  56. package/dist/tools/git-branches.d.ts.map +1 -1
  57. package/dist/tools/git-branches.js +466 -11
  58. package/dist/tools/git-branches.js.map +1 -1
  59. package/dist/tools/git-config.d.ts +115 -15
  60. package/dist/tools/git-config.d.ts.map +1 -1
  61. package/dist/tools/git-config.js +446 -11
  62. package/dist/tools/git-config.js.map +1 -1
  63. package/dist/tools/git-files.d.ts +179 -59
  64. package/dist/tools/git-files.d.ts.map +1 -1
  65. package/dist/tools/git-files.js +699 -221
  66. package/dist/tools/git-files.js.map +1 -1
  67. package/dist/tools/git-issues.d.ts +158 -15
  68. package/dist/tools/git-issues.d.ts.map +1 -1
  69. package/dist/tools/git-issues.js +323 -11
  70. package/dist/tools/git-issues.js.map +1 -1
  71. package/dist/tools/git-monitor.d.ts +149 -14
  72. package/dist/tools/git-monitor.d.ts.map +1 -1
  73. package/dist/tools/git-monitor.js +528 -11
  74. package/dist/tools/git-monitor.js.map +1 -1
  75. package/dist/tools/git-packages.d.ts +163 -15
  76. package/dist/tools/git-packages.d.ts.map +1 -1
  77. package/dist/tools/git-packages.js +526 -11
  78. package/dist/tools/git-packages.js.map +1 -1
  79. package/dist/tools/git-pulls.d.ts +174 -15
  80. package/dist/tools/git-pulls.d.ts.map +1 -1
  81. package/dist/tools/git-pulls.js +352 -11
  82. package/dist/tools/git-pulls.js.map +1 -1
  83. package/dist/tools/git-release.d.ts +167 -15
  84. package/dist/tools/git-release.d.ts.map +1 -1
  85. package/dist/tools/git-release.js +465 -11
  86. package/dist/tools/git-release.js.map +1 -1
  87. package/dist/tools/git-remote.d.ts +124 -15
  88. package/dist/tools/git-remote.d.ts.map +1 -1
  89. package/dist/tools/git-remote.js +539 -11
  90. package/dist/tools/git-remote.js.map +1 -1
  91. package/dist/tools/git-reset.d.ts +100 -15
  92. package/dist/tools/git-reset.d.ts.map +1 -1
  93. package/dist/tools/git-reset.js +409 -11
  94. package/dist/tools/git-reset.js.map +1 -1
  95. package/dist/tools/git-stash.d.ts +120 -15
  96. package/dist/tools/git-stash.d.ts.map +1 -1
  97. package/dist/tools/git-stash.js +503 -11
  98. package/dist/tools/git-stash.js.map +1 -1
  99. package/dist/tools/git-sync.d.ts +160 -16
  100. package/dist/tools/git-sync.d.ts.map +1 -1
  101. package/dist/tools/git-sync.js +462 -113
  102. package/dist/tools/git-sync.js.map +1 -1
  103. package/dist/tools/git-tags.d.ts +142 -15
  104. package/dist/tools/git-tags.d.ts.map +1 -1
  105. package/dist/tools/git-tags.js +471 -11
  106. package/dist/tools/git-tags.js.map +1 -1
  107. package/dist/tools/git-workflow.d.ts +151 -80
  108. package/dist/tools/git-workflow.d.ts.map +1 -1
  109. package/dist/tools/git-workflow.js +407 -912
  110. package/dist/tools/git-workflow.js.map +1 -1
  111. package/dist/utils/credential-manager.d.ts +119 -0
  112. package/dist/utils/credential-manager.d.ts.map +1 -0
  113. package/dist/utils/credential-manager.js +450 -0
  114. package/dist/utils/credential-manager.js.map +1 -0
  115. package/dist/utils/git-command-executor.d.ts +330 -0
  116. package/dist/utils/git-command-executor.d.ts.map +1 -0
  117. package/dist/utils/git-command-executor.js +889 -0
  118. package/dist/utils/git-command-executor.js.map +1 -0
  119. package/dist/utils/logger.d.ts +143 -0
  120. package/dist/utils/logger.d.ts.map +1 -0
  121. package/dist/utils/logger.js +473 -0
  122. package/dist/utils/logger.js.map +1 -0
  123. package/dist/utils/operation-error-handler.d.ts +54 -41
  124. package/dist/utils/operation-error-handler.d.ts.map +1 -1
  125. package/dist/utils/operation-error-handler.js +211 -227
  126. package/dist/utils/operation-error-handler.js.map +1 -1
  127. package/dist/utils/parameter-validator.d.ts +41 -0
  128. package/dist/utils/parameter-validator.d.ts.map +1 -0
  129. package/dist/utils/parameter-validator.js +465 -0
  130. package/dist/utils/parameter-validator.js.map +1 -0
  131. package/dist/utils/repository-detector.d.ts +128 -0
  132. package/dist/utils/repository-detector.d.ts.map +1 -0
  133. package/dist/utils/repository-detector.js +422 -0
  134. package/dist/utils/repository-detector.js.map +1 -0
  135. package/dist/utils/response-formatter.d.ts +146 -0
  136. package/dist/utils/response-formatter.d.ts.map +1 -0
  137. package/dist/utils/response-formatter.js +378 -0
  138. package/dist/utils/response-formatter.js.map +1 -0
  139. package/dist/utils/retry.d.ts +12 -0
  140. package/dist/utils/retry.d.ts.map +1 -0
  141. package/dist/utils/retry.js +28 -0
  142. package/dist/utils/retry.js.map +1 -0
  143. package/dist/utils/terminal-controller.d.ts +73 -139
  144. package/dist/utils/terminal-controller.d.ts.map +1 -1
  145. package/dist/utils/terminal-controller.js +272 -457
  146. package/dist/utils/terminal-controller.js.map +1 -1
  147. package/package.json +79 -60
  148. package/dist/providers/error-handler.d.ts +0 -51
  149. package/dist/providers/error-handler.d.ts.map +0 -1
  150. package/dist/providers/error-handler.js +0 -176
  151. package/dist/providers/error-handler.js.map +0 -1
  152. package/dist/providers/github-provider-backup.d.ts +0 -81
  153. package/dist/providers/github-provider-backup.d.ts.map +0 -1
  154. package/dist/providers/github-provider-backup.js +0 -1179
  155. package/dist/providers/github-provider-backup.js.map +0 -1
  156. package/dist/providers/github-provider-complete.d.ts +0 -1
  157. package/dist/providers/github-provider-complete.d.ts.map +0 -1
  158. package/dist/providers/github-provider-complete.js +0 -2
  159. package/dist/providers/github-provider-complete.js.map +0 -1
  160. package/dist/tools/git-init.d.ts +0 -50
  161. package/dist/tools/git-init.d.ts.map +0 -1
  162. package/dist/tools/git-init.js +0 -258
  163. package/dist/tools/git-init.js.map +0 -1
  164. package/dist/tools/git-log.d.ts +0 -67
  165. package/dist/tools/git-log.d.ts.map +0 -1
  166. package/dist/tools/git-log.js +0 -320
  167. package/dist/tools/git-log.js.map +0 -1
  168. package/dist/tools/git-status.d.ts +0 -29
  169. package/dist/tools/git-status.d.ts.map +0 -1
  170. package/dist/tools/git-status.js +0 -182
  171. package/dist/tools/git-status.js.map +0 -1
  172. package/dist/tools/git-update.d.ts +0 -34
  173. package/dist/tools/git-update.d.ts.map +0 -1
  174. package/dist/tools/git-update.js +0 -191
  175. package/dist/tools/git-update.js.map +0 -1
  176. package/dist/utils/auto-detection.d.ts +0 -120
  177. package/dist/utils/auto-detection.d.ts.map +0 -1
  178. package/dist/utils/auto-detection.js +0 -259
  179. package/dist/utils/auto-detection.js.map +0 -1
  180. package/dist/utils/configuration-error-generator.d.ts +0 -41
  181. package/dist/utils/configuration-error-generator.d.ts.map +0 -1
  182. package/dist/utils/configuration-error-generator.js +0 -168
  183. package/dist/utils/configuration-error-generator.js.map +0 -1
  184. package/dist/utils/configuration-validator.d.ts +0 -67
  185. package/dist/utils/configuration-validator.d.ts.map +0 -1
  186. package/dist/utils/configuration-validator.js +0 -257
  187. package/dist/utils/configuration-validator.js.map +0 -1
  188. package/dist/utils/error-handler.d.ts +0 -107
  189. package/dist/utils/error-handler.d.ts.map +0 -1
  190. package/dist/utils/error-handler.js +0 -331
  191. package/dist/utils/error-handler.js.map +0 -1
  192. package/dist/utils/git-operations.d.ts +0 -200
  193. package/dist/utils/git-operations.d.ts.map +0 -1
  194. package/dist/utils/git-operations.js +0 -836
  195. package/dist/utils/git-operations.js.map +0 -1
  196. package/dist/utils/multi-provider-error-handler.d.ts +0 -75
  197. package/dist/utils/multi-provider-error-handler.d.ts.map +0 -1
  198. package/dist/utils/multi-provider-error-handler.js +0 -276
  199. package/dist/utils/multi-provider-error-handler.js.map +0 -1
  200. package/dist/utils/multi-provider-operation-handler.d.ts +0 -113
  201. package/dist/utils/multi-provider-operation-handler.d.ts.map +0 -1
  202. package/dist/utils/multi-provider-operation-handler.js +0 -303
  203. package/dist/utils/multi-provider-operation-handler.js.map +0 -1
  204. package/dist/utils/provider-operation-handler.d.ts +0 -80
  205. package/dist/utils/provider-operation-handler.d.ts.map +0 -1
  206. package/dist/utils/provider-operation-handler.js +0 -201
  207. package/dist/utils/provider-operation-handler.js.map +0 -1
  208. package/dist/utils/response-helper.d.ts +0 -57
  209. package/dist/utils/response-helper.d.ts.map +0 -1
  210. package/dist/utils/response-helper.js +0 -54
  211. package/dist/utils/response-helper.js.map +0 -1
  212. package/dist/utils/user-detection.d.ts +0 -25
  213. package/dist/utils/user-detection.d.ts.map +0 -1
  214. package/dist/utils/user-detection.js +0 -54
  215. package/dist/utils/user-detection.js.map +0 -1
@@ -1,836 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.GitOperations = void 0;
37
- const child_process_1 = require("child_process");
38
- const util_1 = require("util");
39
- const fs = __importStar(require("fs"));
40
- const path = __importStar(require("path"));
41
- const execAsync = (0, util_1.promisify)(child_process_1.exec);
42
- /**
43
- * Classe para operações Git locais - 100% auto-suficiente
44
- * Implementa todas as operações Git sem depender de outras tools
45
- */
46
- class GitOperations {
47
- projectPath;
48
- constructor(projectPath) {
49
- this.projectPath = projectPath;
50
- }
51
- /**
52
- * Executa comando Git local
53
- */
54
- async runGitCommand(command, args = []) {
55
- return new Promise((resolve) => {
56
- const allArgs = [command, ...args];
57
- const fullCommand = `git ${allArgs.map(arg => `"${arg}"`).join(' ')}`;
58
- (0, child_process_1.exec)(fullCommand, {
59
- cwd: this.projectPath,
60
- maxBuffer: 1024 * 1024 * 10 // 10MB buffer
61
- }, (error, stdout, stderr) => {
62
- resolve({
63
- success: !error,
64
- output: stdout.trim(),
65
- error: stderr.trim(),
66
- exitCode: error ? error.code || 1 : 0
67
- });
68
- });
69
- });
70
- }
71
- /**
72
- * Executa comando de sistema
73
- */
74
- async runSystemCommand(command, args = []) {
75
- return new Promise((resolve) => {
76
- const fullCommand = `${command} ${args.join(' ')}`;
77
- (0, child_process_1.exec)(fullCommand, {
78
- cwd: this.projectPath,
79
- maxBuffer: 1024 * 1024 * 10 // 10MB buffer
80
- }, (error, stdout, stderr) => {
81
- resolve({
82
- success: !error,
83
- output: stdout.trim(),
84
- error: stderr.trim(),
85
- exitCode: error ? error.code || 1 : 0
86
- });
87
- });
88
- });
89
- }
90
- /**
91
- * Verifica se é um repositório Git
92
- */
93
- async isGitRepository() {
94
- const result = await this.runGitCommand('rev-parse', ['--git-dir']);
95
- return result.success;
96
- }
97
- /**
98
- * Inicializa repositório Git
99
- */
100
- async initRepository(bare = false) {
101
- const args = bare ? ['--bare'] : [];
102
- return await this.runGitCommand('init', args);
103
- }
104
- /**
105
- * Clona repositório
106
- */
107
- async cloneRepository(url, directory, options = {}) {
108
- const args = [];
109
- if (options.bare)
110
- args.push('--bare');
111
- if (options.depth)
112
- args.push('--depth', options.depth.toString());
113
- if (options.branch)
114
- args.push('--branch', options.branch);
115
- if (options.singleBranch)
116
- args.push('--single-branch');
117
- if (options.recursive)
118
- args.push('--recursive');
119
- args.push(url);
120
- if (directory)
121
- args.push(directory);
122
- return await this.runGitCommand('clone', args);
123
- }
124
- /**
125
- * Adiciona arquivos ao staging
126
- */
127
- async addFiles(files = ['.']) {
128
- return await this.runGitCommand('add', files);
129
- }
130
- /**
131
- * Remove arquivos do staging
132
- */
133
- async resetFiles(files = []) {
134
- return await this.runGitCommand('reset', files);
135
- }
136
- /**
137
- * Faz commit
138
- */
139
- async commit(message, options = {}) {
140
- const args = [];
141
- if (options.amend)
142
- args.push('--amend');
143
- if (options.noVerify)
144
- args.push('--no-verify');
145
- if (options.allowEmpty)
146
- args.push('--allow-empty');
147
- args.push('-m', message);
148
- return await this.runGitCommand('commit', args);
149
- }
150
- /**
151
- * Push para remote
152
- */
153
- async push(remote = 'origin', branch, options = {}) {
154
- const args = [];
155
- if (options.force)
156
- args.push('--force');
157
- if (options.setUpstream)
158
- args.push('--set-upstream');
159
- if (options.tags)
160
- args.push('--tags');
161
- if (options.all)
162
- args.push('--all');
163
- args.push(remote);
164
- if (branch)
165
- args.push(branch);
166
- return await this.runGitCommand('push', args);
167
- }
168
- /**
169
- * Pull do remote
170
- */
171
- async pull(remote = 'origin', branch, options = {}) {
172
- const args = [];
173
- if (options.rebase)
174
- args.push('--rebase');
175
- if (options.ffOnly)
176
- args.push('--ff-only');
177
- if (options.noEdit)
178
- args.push('--no-edit');
179
- args.push(remote);
180
- if (branch)
181
- args.push(branch);
182
- return await this.runGitCommand('pull', args);
183
- }
184
- /**
185
- * Fetch do remote
186
- */
187
- async fetch(remote, options = {}) {
188
- const args = [];
189
- if (options.all)
190
- args.push('--all');
191
- if (options.tags)
192
- args.push('--tags');
193
- if (options.prune)
194
- args.push('--prune');
195
- if (options.depth)
196
- args.push('--depth', options.depth.toString());
197
- if (remote)
198
- args.push(remote);
199
- return await this.runGitCommand('fetch', args);
200
- }
201
- /**
202
- * Lista branches
203
- */
204
- async listBranches(options = {}) {
205
- const args = [];
206
- if (options.all)
207
- args.push('-a');
208
- if (options.remote)
209
- args.push('-r');
210
- if (options.merged)
211
- args.push('--merged');
212
- if (options.noMerged)
213
- args.push('--no-merged');
214
- return await this.runGitCommand('branch', args);
215
- }
216
- /**
217
- * Cria branch
218
- */
219
- async createBranch(name, startPoint, options = {}) {
220
- const args = [];
221
- if (options.force)
222
- args.push('-f');
223
- if (options.track)
224
- args.push('--track');
225
- if (options.noTrack)
226
- args.push('--no-track');
227
- args.push(name);
228
- if (startPoint)
229
- args.push(startPoint);
230
- return await this.runGitCommand('branch', args);
231
- }
232
- /**
233
- * Deleta branch
234
- */
235
- async deleteBranch(name, options = {}) {
236
- const args = [];
237
- if (options.force)
238
- args.push('-D');
239
- else
240
- args.push('-d');
241
- args.push(name);
242
- return await this.runGitCommand('branch', args);
243
- }
244
- /**
245
- * Checkout branch/commit
246
- */
247
- async checkout(target, options = {}) {
248
- const args = [];
249
- if (options.force)
250
- args.push('-f');
251
- if (options.create)
252
- args.push('-b');
253
- if (options.track)
254
- args.push('--track');
255
- args.push(target);
256
- return await this.runGitCommand('checkout', args);
257
- }
258
- /**
259
- * Merge branches
260
- */
261
- async merge(branch, options = {}) {
262
- const args = [];
263
- if (options.noCommit)
264
- args.push('--no-commit');
265
- if (options.squash)
266
- args.push('--squash');
267
- if (options.noEdit)
268
- args.push('--no-edit');
269
- if (options.strategy)
270
- args.push('-s', options.strategy);
271
- args.push(branch);
272
- return await this.runGitCommand('merge', args);
273
- }
274
- /**
275
- * Rebase
276
- */
277
- async rebase(target, options = {}) {
278
- const args = [];
279
- if (options.interactive)
280
- args.push('-i');
281
- if (options.onto)
282
- args.push('--onto', options.onto);
283
- if (options.continue)
284
- args.push('--continue');
285
- if (options.abort)
286
- args.push('--abort');
287
- if (options.skip)
288
- args.push('--skip');
289
- args.push(target);
290
- return await this.runGitCommand('rebase', args);
291
- }
292
- /**
293
- * Reset
294
- */
295
- async reset(target, options = {}) {
296
- const args = [];
297
- // Adicionar flags de modo
298
- if (options.mode === 'soft' || options.soft)
299
- args.push('--soft');
300
- else if (options.mode === 'hard' || options.hard)
301
- args.push('--hard');
302
- else
303
- args.push('--mixed'); // padrão
304
- args.push(target);
305
- return await this.runGitCommand('reset', args);
306
- }
307
- /**
308
- * Revert commit
309
- */
310
- async revert(commit, options = {}) {
311
- const args = [];
312
- if (options.noCommit)
313
- args.push('--no-commit');
314
- if (options.edit)
315
- args.push('--edit');
316
- if (options.mainline)
317
- args.push('-m', options.mainline.toString());
318
- args.push(commit);
319
- return await this.runGitCommand('revert', args);
320
- }
321
- /**
322
- * Cherry-pick
323
- */
324
- async cherryPick(commit, options = {}) {
325
- const args = [];
326
- if (options.noCommit)
327
- args.push('--no-commit');
328
- if (options.edit)
329
- args.push('--edit');
330
- if (options.mainline)
331
- args.push('-m', options.mainline.toString());
332
- if (options.continue)
333
- args.push('--continue');
334
- if (options.abort)
335
- args.push('--abort');
336
- if (options.skip)
337
- args.push('--skip');
338
- args.push(commit);
339
- return await this.runGitCommand('cherry-pick', args);
340
- }
341
- /**
342
- * Stash
343
- */
344
- async stash(action = 'push', options = {}) {
345
- const args = [];
346
- if (action === 'push') {
347
- if (options.message)
348
- args.push('-m', options.message);
349
- if (options.includeUntracked)
350
- args.push('-u');
351
- if (options.keepIndex)
352
- args.push('--keep-index');
353
- }
354
- else if (action === 'pop') {
355
- args.push('pop');
356
- if (options.index)
357
- args.push('--index');
358
- }
359
- else if (action === 'apply') {
360
- args.push('apply');
361
- if (options.index)
362
- args.push('--index');
363
- }
364
- else if (action === 'list') {
365
- args.push('list');
366
- }
367
- else if (action === 'show') {
368
- args.push('show');
369
- if (options.patch)
370
- args.push('-p');
371
- }
372
- else if (action === 'drop') {
373
- args.push('drop');
374
- }
375
- else if (action === 'clear') {
376
- args.push('clear');
377
- }
378
- return await this.runGitCommand('stash', args);
379
- }
380
- /**
381
- * Tag operations
382
- */
383
- async tag(name, options = {}) {
384
- const args = [];
385
- if (options.list)
386
- args.push('-l');
387
- if (options.delete)
388
- args.push('-d');
389
- if (options.force)
390
- args.push('-f');
391
- if (options.annotate)
392
- args.push('-a');
393
- if (options.message)
394
- args.push('-m', options.message);
395
- if (options.sign)
396
- args.push('-s');
397
- if (name)
398
- args.push(name);
399
- return await this.runGitCommand('tag', args);
400
- }
401
- /**
402
- * Log
403
- */
404
- async log(options = {}) {
405
- const args = [];
406
- if (options.oneline)
407
- args.push('--oneline');
408
- if (options.graph)
409
- args.push('--graph');
410
- if (options.decorate)
411
- args.push('--decorate');
412
- if (options.all)
413
- args.push('--all');
414
- if (options.branches)
415
- args.push('--branches');
416
- if (options.tags)
417
- args.push('--tags');
418
- if (options.remotes)
419
- args.push('--remotes');
420
- if (options.maxCount)
421
- args.push('-n', options.maxCount.toString());
422
- if (options.since)
423
- args.push('--since', options.since);
424
- if (options.until)
425
- args.push('--until', options.until);
426
- if (options.author)
427
- args.push('--author', options.author);
428
- if (options.grep)
429
- args.push('--grep', options.grep);
430
- if (options.path)
431
- args.push('--', options.path);
432
- return await this.runGitCommand('log', args);
433
- }
434
- /**
435
- * Status
436
- */
437
- async status(options = {}) {
438
- const args = [];
439
- if (options.short)
440
- args.push('--short');
441
- if (options.branch)
442
- args.push('--branch');
443
- if (options.porcelain)
444
- args.push('--porcelain');
445
- if (options.ignored)
446
- args.push('--ignored');
447
- if (options.untracked)
448
- args.push('--untracked-files', options.untracked);
449
- return await this.runGitCommand('status', args);
450
- }
451
- /**
452
- * Diff
453
- */
454
- async diff(options = {}) {
455
- const args = [];
456
- if (options.cached)
457
- args.push('--cached');
458
- if (options.staged)
459
- args.push('--staged');
460
- if (options.nameOnly)
461
- args.push('--name-only');
462
- if (options.nameStatus)
463
- args.push('--name-status');
464
- if (options.stat)
465
- args.push('--stat');
466
- if (options.patch)
467
- args.push('-p');
468
- if (options.unified)
469
- args.push('-U', options.unified.toString());
470
- if (options.commit1)
471
- args.push(options.commit1);
472
- if (options.commit2)
473
- args.push(options.commit2);
474
- if (options.path)
475
- args.push('--', options.path);
476
- return await this.runGitCommand('diff', args);
477
- }
478
- /**
479
- * Remote operations
480
- */
481
- async remote(action, name, url) {
482
- const args = [action];
483
- if (name)
484
- args.push(name);
485
- if (url)
486
- args.push(url);
487
- return await this.runGitCommand('remote', args);
488
- }
489
- /**
490
- * Config operations
491
- */
492
- async config(key, value, options = {}) {
493
- const args = [];
494
- if (options.global)
495
- args.push('--global');
496
- if (options.local)
497
- args.push('--local');
498
- if (options.system)
499
- args.push('--system');
500
- if (options.unset)
501
- args.push('--unset');
502
- if (options.list)
503
- args.push('--list');
504
- if (options.get)
505
- args.push('--get');
506
- if (options.getAll)
507
- args.push('--get-all');
508
- if (key)
509
- args.push(key);
510
- if (value)
511
- args.push(value);
512
- return await this.runGitCommand('config', args);
513
- }
514
- /**
515
- * Submodule operations
516
- */
517
- async submodule(action, options = {}) {
518
- const args = [action];
519
- if (options.init)
520
- args.push('--init');
521
- if (options.recursive)
522
- args.push('--recursive');
523
- if (options.remote)
524
- args.push('--remote');
525
- if (options.merge)
526
- args.push('--merge');
527
- if (options.rebase)
528
- args.push('--rebase');
529
- if (options.force)
530
- args.push('--force');
531
- if (options.path)
532
- args.push(options.path);
533
- if (options.url)
534
- args.push(options.url);
535
- return await this.runGitCommand('submodule', args);
536
- }
537
- /**
538
- * Worktree operations
539
- */
540
- async worktree(action, options = {}) {
541
- const args = [action];
542
- if (options.add)
543
- args.push('add');
544
- if (options.remove)
545
- args.push('remove');
546
- if (options.list)
547
- args.push('list');
548
- if (options.prune)
549
- args.push('prune');
550
- if (options.move)
551
- args.push('move');
552
- if (options.repair)
553
- args.push('repair');
554
- if (options.path)
555
- args.push(options.path);
556
- if (options.branch)
557
- args.push(options.branch);
558
- return await this.runGitCommand('worktree', args);
559
- }
560
- /**
561
- * Archive operations
562
- */
563
- async archive(format, treeish, output, options = {}) {
564
- const args = [];
565
- if (options.remote)
566
- args.push('--remote');
567
- if (options.exec)
568
- args.push('--exec', options.exec);
569
- if (options.output)
570
- args.push('--output', options.output);
571
- if (options.prefix)
572
- args.push('--prefix', options.prefix);
573
- if (options.worktreeAttributes)
574
- args.push('--worktree-attributes');
575
- args.push(format, treeish);
576
- if (output)
577
- args.push(output);
578
- return await this.runGitCommand('archive', args);
579
- }
580
- /**
581
- * Bundle operations
582
- */
583
- async bundle(action, options = {}) {
584
- const args = [];
585
- if (action === 'create') {
586
- args.push('bundle', 'create');
587
- if (options.file)
588
- args.push(options.file);
589
- if (options.revlist)
590
- args.push(options.revlist);
591
- }
592
- else if (action === 'verify') {
593
- args.push('bundle', 'verify');
594
- if (options.file)
595
- args.push(options.file);
596
- }
597
- else if (action === 'list-heads') {
598
- args.push('bundle', 'list-heads');
599
- if (options.file)
600
- args.push(options.file);
601
- }
602
- else if (action === 'unbundle') {
603
- args.push('bundle', 'unbundle');
604
- if (options.file)
605
- args.push(options.file);
606
- }
607
- else {
608
- args.push('bundle', action);
609
- if (options.file)
610
- args.push(options.file);
611
- if (options.revlist)
612
- args.push(options.revlist);
613
- }
614
- return await this.runGitCommand(args[0], args.slice(1));
615
- }
616
- /**
617
- * File operations
618
- */
619
- async readFile(filePath) {
620
- try {
621
- const fullPath = path.join(this.projectPath, filePath);
622
- const content = fs.readFileSync(fullPath, 'utf-8');
623
- return {
624
- success: true,
625
- message: 'Arquivo lido com sucesso',
626
- data: { content, path: filePath }
627
- };
628
- }
629
- catch (error) {
630
- return {
631
- success: false,
632
- message: 'Erro ao ler arquivo',
633
- error: error instanceof Error ? error.message : String(error)
634
- };
635
- }
636
- }
637
- async writeFile(filePath, content) {
638
- try {
639
- const fullPath = path.join(this.projectPath, filePath);
640
- const dir = path.dirname(fullPath);
641
- // Cria diretório se não existir
642
- if (!fs.existsSync(dir)) {
643
- fs.mkdirSync(dir, { recursive: true });
644
- }
645
- fs.writeFileSync(fullPath, content, 'utf-8');
646
- return {
647
- success: true,
648
- message: 'Arquivo escrito com sucesso',
649
- data: { path: filePath, size: content.length }
650
- };
651
- }
652
- catch (error) {
653
- return {
654
- success: false,
655
- message: 'Erro ao escrever arquivo',
656
- error: error instanceof Error ? error.message : String(error)
657
- };
658
- }
659
- }
660
- async deleteFile(filePath) {
661
- try {
662
- const fullPath = path.join(this.projectPath, filePath);
663
- fs.unlinkSync(fullPath);
664
- return {
665
- success: true,
666
- message: 'Arquivo deletado com sucesso',
667
- data: { path: filePath }
668
- };
669
- }
670
- catch (error) {
671
- return {
672
- success: false,
673
- message: 'Erro ao deletar arquivo',
674
- error: error instanceof Error ? error.message : String(error)
675
- };
676
- }
677
- }
678
- async listFiles(directory = '.') {
679
- try {
680
- const fullPath = path.join(this.projectPath, directory);
681
- const files = fs.readdirSync(fullPath, { withFileTypes: true });
682
- const fileList = files.map(file => ({
683
- name: file.name,
684
- type: file.isDirectory() ? 'directory' : 'file',
685
- path: path.join(directory, file.name)
686
- }));
687
- return {
688
- success: true,
689
- message: 'Arquivos listados com sucesso',
690
- data: { files: fileList, directory }
691
- };
692
- }
693
- catch (error) {
694
- return {
695
- success: false,
696
- message: 'Erro ao listar arquivos',
697
- error: error instanceof Error ? error.message : String(error)
698
- };
699
- }
700
- }
701
- async createDirectory(dirPath) {
702
- try {
703
- const fullPath = path.join(this.projectPath, dirPath);
704
- fs.mkdirSync(fullPath, { recursive: true });
705
- return {
706
- success: true,
707
- message: 'Diretório criado com sucesso',
708
- data: { path: dirPath }
709
- };
710
- }
711
- catch (error) {
712
- return {
713
- success: false,
714
- message: 'Erro ao criar diretório',
715
- error: error instanceof Error ? error.message : String(error)
716
- };
717
- }
718
- }
719
- async deleteDirectory(dirPath) {
720
- try {
721
- const fullPath = path.join(this.projectPath, dirPath);
722
- fs.rmSync(fullPath, { recursive: true, force: true });
723
- return {
724
- success: true,
725
- message: 'Diretório deletado com sucesso',
726
- data: { path: dirPath }
727
- };
728
- }
729
- catch (error) {
730
- return {
731
- success: false,
732
- message: 'Erro ao deletar diretório',
733
- error: error instanceof Error ? error.message : String(error)
734
- };
735
- }
736
- }
737
- /**
738
- * Terminal operations
739
- */
740
- async runCommand(command, args = []) {
741
- return await this.runSystemCommand(command, args);
742
- }
743
- /**
744
- * Network operations
745
- */
746
- async testConnection(url) {
747
- // Testa conectividade básica
748
- const result = await this.runSystemCommand('ping', ['-c', '1', url]);
749
- return result;
750
- }
751
- /**
752
- * Utility operations
753
- */
754
- async getCurrentDirectory() {
755
- return this.projectPath;
756
- }
757
- async changeDirectory(newPath) {
758
- this.projectPath = newPath;
759
- }
760
- /**
761
- * Obtém a branch atual
762
- */
763
- async getCurrentBranch() {
764
- return await this.runGitCommand('branch', ['--show-current']);
765
- }
766
- async getGitInfo() {
767
- const [status, log, branches, remotes] = await Promise.all([
768
- this.status(),
769
- this.log({ maxCount: 1, oneline: true }),
770
- this.listBranches(),
771
- this.remote('show')
772
- ]);
773
- return {
774
- status: status.output,
775
- lastCommit: log.output,
776
- branches: branches.output,
777
- remotes: remotes.output,
778
- isGitRepo: await this.isGitRepository()
779
- };
780
- }
781
- /**
782
- * Inicializa repositório com branch específica
783
- */
784
- async init(branch = 'main') {
785
- const initResult = await this.runGitCommand('init');
786
- if (!initResult.success) {
787
- return initResult;
788
- }
789
- // Configurar branch padrão
790
- if (branch !== 'master') {
791
- const branchResult = await this.runGitCommand('checkout', ['-b', branch]);
792
- if (!branchResult.success) {
793
- return branchResult;
794
- }
795
- }
796
- return initResult;
797
- }
798
- /**
799
- * Obtém remotes configurados
800
- */
801
- async getRemotes() {
802
- return await this.runGitCommand('remote', ['-v']);
803
- }
804
- /**
805
- * Obtém último commit
806
- */
807
- async getLastCommit() {
808
- return await this.runGitCommand('log', ['-1', '--oneline']);
809
- }
810
- /**
811
- * Obtém log com opções customizadas
812
- */
813
- async getLog(options = []) {
814
- return await this.runGitCommand('log', options);
815
- }
816
- /**
817
- * Obtém histórico de arquivo específico
818
- */
819
- async getFileHistory(filePath, options = []) {
820
- return await this.runGitCommand('log', [...options, '--', filePath]);
821
- }
822
- /**
823
- * Obtém histórico de branch
824
- */
825
- async getBranchHistory(branch, options = []) {
826
- return await this.runGitCommand('log', [...options, branch]);
827
- }
828
- /**
829
- * Adiciona remote
830
- */
831
- async addRemote(name, url) {
832
- return await this.runGitCommand('remote', ['add', name, url]);
833
- }
834
- }
835
- exports.GitOperations = GitOperations;
836
- //# sourceMappingURL=git-operations.js.map