Skip to content

Commit 63fc666

Browse files
✨ Alpha 6: Added RemoteManager with full remote operations
1 parent e488f54 commit 63fc666

File tree

2 files changed

+288
-10
lines changed

2 files changed

+288
-10
lines changed

src/config/commandsList.ts

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ export const COMMANDS_LIST: PlainGitCommand[] = [
180180
handler: 'BranchManager.showAndList',
181181
},
182182

183-
// 📝 Commit Operations
184183
// 📝 Commit Operations
185184
{
186185
category: 'Commit',
@@ -256,25 +255,81 @@ export const COMMANDS_LIST: PlainGitCommand[] = [
256255
// 🚀 Remote Operations
257256
{
258257
category: 'Remote',
259-
name: '🚀 Push changes to remote',
260-
command: 'git push',
261-
description: 'Push local commits to the default remote branch.',
258+
name: '🔗 List all remotes',
259+
command: 'git remote -v',
260+
description: 'List all configured remote repositories.',
261+
handler: 'RemoteManager.listRemotes',
262+
},
263+
{
264+
category: 'Remote',
265+
name: '➕ Add a new remote',
266+
command: 'git remote add <name> <url>',
267+
description: 'Add a new remote repository by name and URL.',
268+
handler: 'RemoteManager.addRemote',
269+
},
270+
{
271+
category: 'Remote',
272+
name: '✏️ Rename a remote',
273+
command: 'git remote rename <old> <new>',
274+
description: 'Rename an existing remote repository.',
275+
handler: 'RemoteManager.renameRemote',
276+
},
277+
{
278+
category: 'Remote',
279+
name: '🗑️ Remove a remote',
280+
command: 'git remote remove <name>',
281+
description: 'Remove a remote repository from configuration.',
282+
handler: 'RemoteManager.removeRemote',
283+
},
284+
{
285+
category: 'Remote',
286+
name: '⚙️ Change a remote URL',
287+
command: 'git remote set-url <name> <url>',
288+
description: 'Change the URL for an existing remote repository.',
289+
handler: 'RemoteManager.updateRemoteUrl',
290+
},
291+
{
292+
category: 'Remote',
293+
name: '🚀 Push changes',
294+
command: 'git push <remote>',
295+
description: 'Push commits to a remote repository.',
262296
handler: 'RemoteManager.pushChanges',
263297
},
298+
{
299+
category: 'Remote',
300+
name: '🚀 Push branch and set upstream',
301+
command: 'git push -u <remote> <branch>',
302+
description: 'Push a branch and set it to track a remote branch.',
303+
handler: 'RemoteManager.pushWithUpstream',
304+
},
264305
{
265306
category: 'Remote',
266307
name: '⬇️ Pull latest changes',
267-
command: 'git pull',
268-
description: 'Pull changes from the remote branch into your local branch.',
308+
command: 'git pull <remote>',
309+
description: 'Pull changes from the selected remote repository.',
269310
handler: 'RemoteManager.pullChanges',
270311
},
271312
{
272313
category: 'Remote',
273-
name: '🔍 Fetch updates from remote',
274-
command: 'git fetch',
275-
description: 'Fetch remote changes without merging them.',
314+
name: '🔍 Fetch updates',
315+
command: 'git fetch [remote]',
316+
description: 'Fetch new data from a remote without merging it.',
276317
handler: 'RemoteManager.fetchUpdates',
277318
},
319+
{
320+
category: 'Remote',
321+
name: '🌎 Show remote details',
322+
command: 'git remote show <name>',
323+
description: 'View information about a specific remote repository.',
324+
handler: 'RemoteManager.showRemoteInfo',
325+
},
326+
{
327+
category: 'Remote',
328+
name: '🔄 Sync all remotes',
329+
command: 'git fetch --all && git pull --all',
330+
description: 'Fetch and pull updates from all configured remotes.',
331+
handler: 'RemoteManager.syncAll',
332+
},
278333

279334
// 🕓 History & Diff
280335
{

src/managers/RemoteManager.ts

Lines changed: 224 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,224 @@
1-
export const RemoteManager = {}
1+
/**
2+
* 🌎 RemoteManager.ts
3+
* -------------------------------------------------------------
4+
* Handles all remote-related Git operations:
5+
* - Listing, adding, renaming, and removing remotes
6+
* - Pushing, pulling, and fetching
7+
* - Syncing remotes and updating URLs
8+
* -------------------------------------------------------------
9+
*/
10+
11+
import inquirer from 'inquirer';
12+
import { execSync } from 'child_process';
13+
import { GitExecutor } from '../core/GitExecutor';
14+
import { Logger } from '../utils/Logger';
15+
16+
17+
/**
18+
* Helper: get list of remote names
19+
*/
20+
function getRemoteList(): string[] {
21+
try {
22+
const raw = execSync('git remote', { encoding: 'utf-8' });
23+
return raw
24+
.split('\n')
25+
.map((r) => r.trim())
26+
.filter(Boolean);
27+
} catch {
28+
return [];
29+
}
30+
}
31+
32+
export const RemoteManager = {
33+
/**
34+
* 🔗 List all remotes
35+
*/
36+
async listRemotes() {
37+
Logger.info('🔗 Listing all configured remotes...');
38+
await GitExecutor.run('git remote -v');
39+
},
40+
41+
/**
42+
* ➕ Add a new remote
43+
*/
44+
async addRemote() {
45+
const { name, url } = await inquirer.prompt([
46+
{ type: 'input', name: 'name', message: 'Enter remote name (e.g. origin):' },
47+
{ type: 'input', name: 'url', message: 'Enter remote URL:' },
48+
]);
49+
50+
Logger.info(`➕ Adding remote '${name}'...`);
51+
await GitExecutor.run(`git remote add ${name} ${url}`);
52+
Logger.success(`✅ Remote '${name}' added successfully!`);
53+
},
54+
55+
/**
56+
* ✏️ Rename an existing remote
57+
*/
58+
async renameRemote() {
59+
const remotes = getRemoteList();
60+
if (!remotes.length) {
61+
Logger.info('⚠️ No remotes found.');
62+
return;
63+
}
64+
65+
const { oldName } = await inquirer.prompt([
66+
{ type: 'list', name: 'oldName', message: 'Select remote to rename:', choices: remotes },
67+
]);
68+
69+
const { newName } = await inquirer.prompt([
70+
{ type: 'input', name: 'newName', message: `Enter new name for '${oldName}':` },
71+
]);
72+
73+
Logger.info(`✏️ Renaming remote '${oldName}' → '${newName}'...`);
74+
await GitExecutor.run(`git remote rename ${oldName} ${newName}`);
75+
Logger.success(`✅ Remote renamed to '${newName}'.`);
76+
},
77+
78+
/**
79+
* 🗑️ Remove a remote
80+
*/
81+
async removeRemote() {
82+
const remotes = getRemoteList();
83+
if (!remotes.length) {
84+
Logger.info('⚠️ No remotes found.');
85+
return;
86+
}
87+
88+
const { name } = await inquirer.prompt([
89+
{ type: 'list', name: 'name', message: 'Select remote to remove:', choices: remotes },
90+
]);
91+
92+
Logger.info(`🗑️ Removing remote '${name}'...`);
93+
await GitExecutor.run(`git remote remove ${name}`);
94+
Logger.success(`✅ Remote '${name}' removed successfully!`);
95+
},
96+
97+
/**
98+
* ⚙️ Change a remote URL
99+
*/
100+
async updateRemoteUrl() {
101+
const remotes = getRemoteList();
102+
if (!remotes.length) {
103+
Logger.info('⚠️ No remotes found.');
104+
return;
105+
}
106+
107+
const { name } = await inquirer.prompt([
108+
{ type: 'list', name: 'name', message: 'Select remote to update URL:', choices: remotes },
109+
]);
110+
111+
const { url } = await inquirer.prompt([
112+
{ type: 'input', name: 'url', message: 'Enter new remote URL:' },
113+
]);
114+
115+
Logger.info(`🔄 Updating URL for remote '${name}'...`);
116+
await GitExecutor.run(`git remote set-url ${name} ${url}`);
117+
Logger.success(`✅ Remote '${name}' URL updated!`);
118+
},
119+
120+
/**
121+
* 🚀 Push changes to remote
122+
*/
123+
async pushChanges() {
124+
const remotes = getRemoteList();
125+
const { remote } = await inquirer.prompt([
126+
{
127+
type: 'list',
128+
name: 'remote',
129+
message: 'Select remote to push to:',
130+
choices: remotes.length ? remotes : ['origin'],
131+
},
132+
]);
133+
134+
Logger.info(`🚀 Pushing changes to '${remote}'...`);
135+
await GitExecutor.run(`git push ${remote}`);
136+
Logger.success(`✅ Changes pushed to '${remote}'!`);
137+
},
138+
139+
/**
140+
* 🚀 Push and set upstream
141+
*/
142+
async pushWithUpstream() {
143+
const remotes = getRemoteList();
144+
const { remote, branch } = await inquirer.prompt([
145+
{
146+
type: 'list',
147+
name: 'remote',
148+
message: 'Select remote:',
149+
choices: remotes.length ? remotes : ['origin'],
150+
},
151+
{ type: 'input', name: 'branch', message: 'Enter branch name to push:' },
152+
]);
153+
154+
Logger.info(`🚀 Pushing '${branch}' to '${remote}' (set upstream)...`);
155+
await GitExecutor.run(`git push -u ${remote} ${branch}`);
156+
Logger.success(`✅ Upstream branch '${branch}' set to '${remote}'.`);
157+
},
158+
159+
/**
160+
* ⬇️ Pull changes from remote
161+
*/
162+
async pullChanges() {
163+
const remotes = getRemoteList();
164+
const { remote } = await inquirer.prompt([
165+
{
166+
type: 'list',
167+
name: 'remote',
168+
message: 'Select remote to pull from:',
169+
choices: remotes.length ? remotes : ['origin'],
170+
},
171+
]);
172+
173+
Logger.info(`⬇️ Pulling changes from '${remote}'...`);
174+
await GitExecutor.run(`git pull ${remote}`);
175+
Logger.success(`✅ Pulled latest changes from '${remote}'.`);
176+
},
177+
178+
/**
179+
* 🔍 Fetch updates without merging
180+
*/
181+
async fetchUpdates() {
182+
const remotes = getRemoteList();
183+
const { remote } = await inquirer.prompt([
184+
{
185+
type: 'list',
186+
name: 'remote',
187+
message: 'Select remote to fetch from:',
188+
choices: [...remotes, 'all'],
189+
},
190+
]);
191+
192+
const cmd = remote === 'all' ? 'git fetch --all' : `git fetch ${remote}`;
193+
Logger.info(`🔍 Fetching updates from ${remote}...`);
194+
await GitExecutor.run(cmd);
195+
Logger.success(`✅ Fetched updates from ${remote}.`);
196+
},
197+
198+
/**
199+
* 🌎 Show remote details
200+
*/
201+
async showRemoteInfo() {
202+
const remotes = getRemoteList();
203+
if (!remotes.length) {
204+
Logger.info('⚠️ No remotes found.');
205+
return;
206+
}
207+
208+
const { remote } = await inquirer.prompt([
209+
{ type: 'list', name: 'remote', message: 'Select remote to view info:', choices: remotes },
210+
]);
211+
212+
Logger.info(`🌎 Showing information for remote '${remote}'...`);
213+
await GitExecutor.run(`git remote show ${remote}`);
214+
},
215+
216+
/**
217+
* 🔄 Sync all remotes (fetch + pull)
218+
*/
219+
async syncAll() {
220+
Logger.info('🔄 Fetching and pulling from all remotes...');
221+
await GitExecutor.run('git fetch --all && git pull --all');
222+
Logger.success('✅ All remotes synchronized!');
223+
},
224+
};

0 commit comments

Comments
 (0)