Repository navigation
Expand file tree
/
Copy pathextension.js
More file actions
79 lines (66 loc) · 1.98 KB
/
Copy pathextension.js
File metadata and controls
79 lines (66 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const vscode = require("vscode");
const { execSync } = require("child_process");
// Track if the modal has already been shown in this session
let modalShown = false;
function activate(context) {
showBranchModal(); // show once on startup
// Optional: if you want to re-show when workspace changes, uncomment below
vscode.workspace.onDidChangeWorkspaceFolders(() => {
if (!modalShown) showBranchModal();
});
}
async function showBranchModal() {
// Prevent multiple triggers
if (modalShown) return;
modalShown = true;
try {
const workspace = vscode.workspace.workspaceFolders?.[0];
if (!workspace) return;
const cwd = workspace.uri.fsPath;
const branch = execSync("git rev-parse --abbrev-ref HEAD", { cwd })
.toString()
.trim();
const selection = await vscode.window.showInformationMessage(
`🚨 You are on branch: ${branch.toUpperCase()}`,
{ modal: true },
"Switch Branch",
"Git Fetch --all"
);
if (!selection || selection === "Close") {
return; // just close
}
if (selection === "Switch Branch") {
let branches = execSync("git branch --all --color=never", { cwd })
.toString()
.split("\n")
.map((b) => b.replace("*", "").trim())
.filter((b) => b);
const picked = await vscode.window.showQuickPick(branches, {
placeHolder: "Select a branch to switch to",
});
if (picked) {
try {
execSync(`git checkout ${picked}`, { cwd });
vscode.window.showInformationMessage(
`✅ Switched to branch ${picked}`
);
} catch (err) {
vscode.window.showErrorMessage(
`❌ Failed to switch to branch ${picked}`
);
}
}
} else if (selection === "Git Fetch --all") {
try {
execSync("git fetch --all", { cwd });
vscode.window.showInformationMessage("✅ Git fetch completed!");
} catch (err) {
vscode.window.showErrorMessage("❌ Git fetch failed");
}
}
} catch (err) {
console.log("Not a git repo");
}
}
function deactivate() {}
module.exports = { activate, deactivate };