@mono-labs/cli 0.0.125 → 0.0.126
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/lib/commands/prune/prune.js +20 -18
- package/package.json +1 -1
|
@@ -1,48 +1,50 @@
|
|
|
1
|
-
import { execSync } from 'child_process'
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
2
|
|
|
3
|
-
const log = (...args) =>
|
|
4
|
-
const err = (...args) => console.error(...args)
|
|
3
|
+
const log = (...args) => console.log(...args);
|
|
4
|
+
const err = (...args) => console.error(...args);
|
|
5
5
|
export function pruneRepo() {
|
|
6
6
|
try {
|
|
7
7
|
// Fetch and prune remote branches
|
|
8
|
-
log('Fetching latest branch data from origin...')
|
|
9
|
-
execSync('git fetch --prune', { stdio: 'inherit' })
|
|
8
|
+
log('Fetching latest branch data from origin...');
|
|
9
|
+
execSync('git fetch --prune', { stdio: 'inherit' });
|
|
10
10
|
|
|
11
11
|
// Get local branches (trim whitespace)
|
|
12
12
|
const localBranches = execSync("git branch --format '%(refname:short)'")
|
|
13
13
|
.toString()
|
|
14
14
|
.trim()
|
|
15
15
|
.split('\n')
|
|
16
|
-
.map((branch) => branch.trim().replaceAll("'", ''))
|
|
16
|
+
.map((branch) => branch.trim().replaceAll("'", ''));
|
|
17
17
|
|
|
18
18
|
// Get remote branches (remove "origin/" prefix)
|
|
19
19
|
const remoteBranches = execSync('git branch -r')
|
|
20
20
|
.toString()
|
|
21
21
|
.trim()
|
|
22
22
|
.split('\n')
|
|
23
|
-
.map((branch) => branch.replace(/^\s*origin\//, '').trim())
|
|
23
|
+
.map((branch) => branch.replace(/^\s*origin\//, '').trim());
|
|
24
24
|
|
|
25
25
|
// Find local branches that are NOT in remote branches
|
|
26
|
-
const branchesToDelete = localBranches.filter(
|
|
26
|
+
const branchesToDelete = localBranches.filter(
|
|
27
|
+
(branch) => !remoteBranches.includes(branch)
|
|
28
|
+
);
|
|
27
29
|
if (branchesToDelete.length === 0) {
|
|
28
|
-
log('No local branches to delete.')
|
|
29
|
-
process.exit(0)
|
|
30
|
+
log('No local branches to delete.');
|
|
31
|
+
process.exit(0);
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
// Delete untracked local branches
|
|
33
|
-
log('Deleting local branches that are not on origin...')
|
|
35
|
+
log('Deleting local branches that are not on origin...');
|
|
34
36
|
branchesToDelete.forEach((branch) => {
|
|
35
|
-
log(`Attempting to delete: ${branch}`)
|
|
37
|
+
log(`Attempting to delete: ${branch}`);
|
|
36
38
|
try {
|
|
37
|
-
execSync(`git branch -D ${branch}`, { stdio: 'inherit' })
|
|
38
|
-
log(`Deleted: ${branch}`)
|
|
39
|
+
execSync(`git branch -D ${branch}`, { stdio: 'inherit' });
|
|
40
|
+
log(`Deleted: ${branch}`);
|
|
39
41
|
} catch (error) {
|
|
40
|
-
error(`Failed to delete branch ${branch}:`, error.message)
|
|
42
|
+
error(`Failed to delete branch ${branch}:`, error.message);
|
|
41
43
|
}
|
|
42
|
-
})
|
|
44
|
+
});
|
|
43
45
|
|
|
44
|
-
log('Cleanup complete!')
|
|
46
|
+
log('Cleanup complete!');
|
|
45
47
|
} catch (error) {
|
|
46
|
-
err('An error occurred:', error.message)
|
|
48
|
+
err('An error occurred:', error.message);
|
|
47
49
|
}
|
|
48
50
|
}
|