@andrebuzeli/git-mcp 15.1.2 → 15.1.4
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.
package/package.json
CHANGED
|
@@ -46,6 +46,29 @@ export class ProviderManager {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
async getRemoteUrls(repoName) {
|
|
50
|
+
const urls = {};
|
|
51
|
+
|
|
52
|
+
// GitHub URL
|
|
53
|
+
if (this.github) {
|
|
54
|
+
const owner = await this.getGitHubOwner();
|
|
55
|
+
if (owner) {
|
|
56
|
+
urls.github = `https://github.com/${owner}/${repoName}.git`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Gitea URL
|
|
61
|
+
if (this.giteaUrl && this.giteaToken) {
|
|
62
|
+
const owner = await this.getGiteaOwner();
|
|
63
|
+
if (owner) {
|
|
64
|
+
const base = this.giteaUrl.replace(/\/$/, "");
|
|
65
|
+
urls.gitea = `${base}/${owner}/${repoName}.git`;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return urls;
|
|
70
|
+
}
|
|
71
|
+
|
|
49
72
|
async ensureRepos({ repoName, createIfMissing = true, description = "Managed by git-mcpv2" }) {
|
|
50
73
|
const results = { github: null, gitea: null };
|
|
51
74
|
// GitHub
|
package/src/utils/gitAdapter.js
CHANGED
|
@@ -82,10 +82,33 @@ export class GitAdapter {
|
|
|
82
82
|
|
|
83
83
|
async ensureRemotes(dir, { githubUrl, giteaUrl }) {
|
|
84
84
|
const remotes = await git.listRemotes({ fs, dir });
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
const repoName = path.basename(dir);
|
|
86
|
+
|
|
87
|
+
// Tenta obter URLs autenticadas/corretas do ProviderManager
|
|
88
|
+
const calculatedUrls = await this.pm.getRemoteUrls(repoName);
|
|
89
|
+
const targetGithub = calculatedUrls.github || githubUrl;
|
|
90
|
+
const targetGitea = calculatedUrls.gitea || giteaUrl;
|
|
91
|
+
|
|
92
|
+
const ensure = async (name, url) => {
|
|
93
|
+
if (!url) return;
|
|
94
|
+
const existing = remotes.find(r => r.remote === name);
|
|
95
|
+
if (existing) {
|
|
96
|
+
if (existing.url !== url) {
|
|
97
|
+
// URL mudou (ex: token novo, user diferente, host diferente)
|
|
98
|
+
await git.deleteRemote({ fs, dir, remote: name });
|
|
99
|
+
await git.addRemote({ fs, dir, remote: name, url });
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
await git.addRemote({ fs, dir, remote: name, url });
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
await ensure("github", targetGithub);
|
|
107
|
+
await ensure("gitea", targetGitea);
|
|
108
|
+
|
|
109
|
+
// Origin prefere GitHub, fallback para Gitea
|
|
110
|
+
const originUrl = targetGithub || targetGitea;
|
|
111
|
+
if (originUrl) await ensure("origin", originUrl);
|
|
89
112
|
}
|
|
90
113
|
|
|
91
114
|
getAuth(remoteUrl) {
|
|
@@ -122,6 +145,9 @@ export class GitAdapter {
|
|
|
122
145
|
}
|
|
123
146
|
|
|
124
147
|
async pushParallel(dir, branch, force = false) {
|
|
148
|
+
// Auto-fix remotes antes de tentar push
|
|
149
|
+
await this.ensureRemotes(dir, {});
|
|
150
|
+
|
|
125
151
|
const remotes = await git.listRemotes({ fs, dir });
|
|
126
152
|
const targets = remotes.filter(r => ["github", "gitea"].includes(r.remote));
|
|
127
153
|
if (targets.length === 0) {
|