Skip to content

Commit 605480f

Browse files
✨ Alpha 3: Enhanced RepositoryManager with full repo-level commands and updated command list
1 parent 361493d commit 605480f

File tree

4 files changed

+250
-24
lines changed

4 files changed

+250
-24
lines changed

src/config/commandsList.ts

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,90 @@ export const COMMANDS_LIST: PlainGitCommand[] = [
2323
description: "Create a new local Git repository in the current folder.",
2424
handler: "RepositoryManager.initRepo",
2525
},
26+
{
27+
category: "Repository",
28+
name: "📦 Initialize a bare repository",
29+
command: "git init --bare",
30+
description: "Create a bare Git repository (no working directory).",
31+
handler: "RepositoryManager.initRepo",
32+
},
2633
{
2734
category: "Repository",
2835
name: "🌐 Clone a repository from URL",
29-
command: "git clone <url>",
36+
command: "git clone <url> [folder]",
3037
description: "Clone an existing repository from a remote Git URL.",
3138
handler: "RepositoryManager.cloneRepo",
3239
},
3340
{
3441
category: "Repository",
3542
name: "📂 Check repository status",
36-
command: "git status",
37-
description: "Display the working tree status.",
43+
command: "git status [-s]",
44+
description: "Display the current working tree status (short or detailed).",
3845
handler: "RepositoryManager.status",
3946
},
4047
{
4148
category: "Repository",
4249
name: "⚙️ Show Git configuration",
43-
command: "git config --list",
44-
description: "Show global and local Git config values.",
50+
command: "git config --list [--global | --local | --system]",
51+
description: "Show Git configuration for the selected scope.",
4552
handler: "RepositoryManager.showConfig",
4653
},
54+
{
55+
category: "Repository",
56+
name: "🧩 Set Git configuration value",
57+
command: "git config [--global] <key> <value>",
58+
description: "Set or update a Git configuration key/value pair.",
59+
handler: "RepositoryManager.setConfig",
60+
},
61+
{
62+
category: "Repository",
63+
name: "🔗 List remotes",
64+
command: "git remote -v",
65+
description: "List all configured remote repositories.",
66+
handler: "RepositoryManager.listRemotes",
67+
},
68+
{
69+
category: "Repository",
70+
name: "➕ Add a new remote",
71+
command: "git remote add <name> <url>",
72+
description: "Add a new remote repository by name and URL.",
73+
handler: "RepositoryManager.addRemote",
74+
},
75+
{
76+
category: "Repository",
77+
name: "✏️ Update existing remote URL",
78+
command: "git remote set-url <name> <new-url>",
79+
description: "Change the URL for an existing remote repository.",
80+
handler: "RepositoryManager.updateRemote",
81+
},
82+
{
83+
category: "Repository",
84+
name: "🗑️ Remove a remote",
85+
command: "git remote remove <name>",
86+
description: "Remove a remote repository from configuration.",
87+
handler: "RepositoryManager.removeRemote",
88+
},
89+
{
90+
category: "Repository",
91+
name: "🔍 Show repository info (HEAD + Root)",
92+
command: "git rev-parse --show-toplevel && git rev-parse --abbrev-ref HEAD",
93+
description: "Show repository root directory and current branch info.",
94+
handler: "RepositoryManager.showRepoInfo",
95+
},
96+
{
97+
category: "Repository",
98+
name: "🧹 Optimize repository (cleanup & GC)",
99+
command: "git gc --prune=now --aggressive",
100+
description: "Run Git garbage collection to optimize repository size.",
101+
handler: "RepositoryManager.optimizeRepo",
102+
},
103+
{
104+
category: "Repository",
105+
name: "🔎 Verify repository integrity",
106+
command: "git fsck --full",
107+
description: "Check repository for corrupted or missing objects.",
108+
handler: "RepositoryManager.verifyRepo",
109+
},
47110

48111
// 🌿 Branch Operations
49112
{

src/core/HandleCommands.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
import {RepositoryManager, BranchManager, CommitManager, RemoteManager, ResetManager, HistoryManager} from '../managers'
21
import { Logger } from '../utils/Logger';
3-
4-
const managerMap: Record<string, any> = {
5-
RepositoryManager,
6-
BranchManager,
7-
CommitManager,
8-
RemoteManager,
9-
HistoryManager,
10-
ResetManager,
11-
};
2+
import { managerMap } from './registry/ManagerMap';
3+
import { COMMANDS_LIST } from '../config/commandsList';
4+
import chalk from 'chalk';
125

136
export async function handleCommand(handlerPath: string) {
147
try {
8+
// Find the command details from the list
9+
const commandItem = COMMANDS_LIST.find((cmd) => cmd.handler === handlerPath);
10+
const gitCommand = commandItem ? commandItem.command : null;
11+
12+
// Log which command is about to be executed
13+
if (gitCommand) {
14+
console.log(chalk.cyanBright(`\n💻 Executing command: ${chalk.bold(gitCommand)}\n`));
15+
} else {
16+
console.log(chalk.gray('\n⚙️ Executing custom handler...\n'));
17+
}
18+
1519
const [managerName, methodName] = handlerPath.split('.');
1620
const manager = managerMap[managerName];
1721

@@ -23,4 +27,4 @@ export async function handleCommand(handlerPath: string) {
2327
} catch (err) {
2428
Logger.error(`❌ Command failed: ${(err as Error).message}`);
2529
}
26-
}
30+
}

src/core/registry/ManagerMap.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* 🧭 managerMap.ts
3+
* -------------------------------------------------------------
4+
* Central registry that maps all manager names to their modules.
5+
* This ensures handleCommands.ts can dynamically route any handler.
6+
* -------------------------------------------------------------
7+
*/
8+
9+
import {RepositoryManager, BranchManager, CommitManager, RemoteManager, HistoryManager, ResetManager} from '../../managers'
10+
11+
export const managerMap: Record<string, any> = {
12+
RepositoryManager,
13+
BranchManager,
14+
CommitManager,
15+
RemoteManager,
16+
HistoryManager,
17+
ResetManager,
18+
};

src/managers/RepositoryManager.ts

Lines changed: 149 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,158 @@
1-
import inquirer from 'inquirer';
2-
import { GitExecutor } from '../core/GitExecutor';
3-
import { Logger } from '../utils/Logger';
1+
/**
2+
* 🏁 RepositoryManager.ts (Deep Version)
3+
* -------------------------------------------------------------
4+
* Handles all repository-level operations including initialization,
5+
* configuration, inspection, remote management, and maintenance.
6+
* -------------------------------------------------------------
7+
*/
8+
9+
import inquirer from "inquirer";
10+
import { GitExecutor } from "../core/GitExecutor";
11+
import { Logger } from "../utils/Logger";
412

513
export const RepositoryManager = {
14+
// 🏗 Initialize Repo
615
async initRepo() {
7-
Logger.info('🌀 Initializing new Git repository...');
8-
await GitExecutor.run('git init');
16+
const { bare } = await inquirer.prompt([
17+
{
18+
type: "confirm",
19+
name: "bare",
20+
message: "Do you want to create a bare repository?",
21+
default: false,
22+
},
23+
]);
24+
25+
const cmd = bare ? "git init --bare" : "git init";
26+
Logger.info(`📦 Initializing repository (${bare ? "bare" : "standard"})...`);
27+
await GitExecutor.run(cmd);
28+
Logger.success("✅ Repository initialized successfully!");
929
},
1030

31+
// 🌐 Clone Repo
32+
async cloneRepo() {
33+
const { url, folder } = await inquirer.prompt([
34+
{ type: "input", name: "url", message: "Enter repository URL to clone:" },
35+
{ type: "input", name: "folder", message: "Optional: Enter target folder name (leave empty for default):" },
36+
]);
37+
38+
const cmd = folder ? `git clone ${url} ${folder}` : `git clone ${url}`;
39+
Logger.info(`🔁 Cloning repository from ${url}...`);
40+
await GitExecutor.run(cmd);
41+
Logger.success("✅ Repository cloned successfully!");
42+
},
43+
44+
// 📂 Check Status
1145
async status() {
12-
Logger.info('📋 Checking repository status...');
13-
await GitExecutor.run('git status');
46+
const { short } = await inquirer.prompt([
47+
{
48+
type: "confirm",
49+
name: "short",
50+
message: "Show compact (short) status?",
51+
default: false,
52+
},
53+
]);
54+
55+
const cmd = short ? "git status -s" : "git status";
56+
Logger.info("📂 Checking repository status...");
57+
await GitExecutor.run(cmd);
58+
},
59+
60+
// ⚙️ Git Config Management
61+
async showConfig() {
62+
const { scope } = await inquirer.prompt([
63+
{
64+
type: "list",
65+
name: "scope",
66+
message: "Which config scope do you want to view?",
67+
choices: [
68+
{ name: "Local", value: "--local" },
69+
{ name: "Global", value: "--global" },
70+
{ name: "System", value: "--system" },
71+
{ name: "All combined", value: "--list" },
72+
],
73+
},
74+
]);
75+
76+
const cmd = scope === "--list" ? "git config --list" : `git config ${scope} --list`;
77+
Logger.info(`⚙️ Showing ${scope.replace("--", "")} configuration...`);
78+
await GitExecutor.run(cmd);
79+
},
80+
81+
// ✏️ Set Config
82+
async setConfig() {
83+
const { key, value, global } = await inquirer.prompt([
84+
{ type: "input", name: "key", message: "Enter config key (e.g. user.name):" },
85+
{ type: "input", name: "value", message: "Enter config value:" },
86+
{ type: "confirm", name: "global", message: "Apply globally?", default: false },
87+
]);
88+
89+
const flag = global ? "--global" : "";
90+
const cmd = `git config ${flag} ${key} "${value}"`;
91+
Logger.info(`🧩 Setting config: ${key}=${value}`);
92+
await GitExecutor.run(cmd);
93+
Logger.success("✅ Configuration updated!");
94+
},
95+
96+
// 🔗 List Remotes
97+
async listRemotes() {
98+
Logger.info("🔗 Listing remotes...");
99+
await GitExecutor.run("git remote -v");
14100
},
15101

16-
102+
// ➕ Add Remote
103+
async addRemote() {
104+
const { name, url } = await inquirer.prompt([
105+
{ type: "input", name: "name", message: "Enter remote name (e.g. origin):" },
106+
{ type: "input", name: "url", message: "Enter remote URL:" },
107+
]);
108+
109+
const cmd = `git remote add ${name} ${url}`;
110+
Logger.info(`🔗 Adding remote '${name}' -> ${url}`);
111+
await GitExecutor.run(cmd);
112+
Logger.success(`✅ Remote '${name}' added successfully!`);
113+
},
114+
115+
// ✏️ Change Remote URL
116+
async updateRemote() {
117+
const { name, url } = await inquirer.prompt([
118+
{ type: "input", name: "name", message: "Enter remote name to update:" },
119+
{ type: "input", name: "url", message: "Enter new remote URL:" },
120+
]);
121+
122+
const cmd = `git remote set-url ${name} ${url}`;
123+
Logger.info(`🔄 Updating remote '${name}' to ${url}`);
124+
await GitExecutor.run(cmd);
125+
Logger.success("✅ Remote URL updated!");
126+
},
127+
128+
// 🗑️ Remove Remote
129+
async removeRemote() {
130+
const { name } = await inquirer.prompt([
131+
{ type: "input", name: "name", message: "Enter remote name to remove:" },
132+
]);
133+
134+
const cmd = `git remote remove ${name}`;
135+
Logger.info(`🗑️ Removing remote '${name}'...`);
136+
await GitExecutor.run(cmd);
137+
Logger.success(`✅ Remote '${name}' removed successfully!`);
138+
},
139+
140+
// 🧠 Repository Info
141+
async showRepoInfo() {
142+
Logger.info("🔍 Getting repository HEAD and root info...");
143+
await GitExecutor.run("git rev-parse --show-toplevel && git rev-parse --abbrev-ref HEAD");
144+
},
145+
146+
// 🧹 Repository Cleanup / Maintenance
147+
async optimizeRepo() {
148+
Logger.info("🧹 Running garbage collection...");
149+
await GitExecutor.run("git gc --prune=now --aggressive");
150+
Logger.success("✅ Repository optimized successfully!");
151+
},
152+
153+
// 🧾 Check Repository Integrity
154+
async verifyRepo() {
155+
Logger.info("🔎 Verifying repository integrity...");
156+
await GitExecutor.run("git fsck --full");
157+
},
17158
};

0 commit comments

Comments
 (0)