@harryisfish/gitt 1.4.0 → 1.4.1
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/dist/commands/clean.js +40 -55
- package/package.json +1 -1
package/dist/commands/clean.js
CHANGED
|
@@ -16,7 +16,12 @@ const git = (0, simple_git_1.simpleGit)();
|
|
|
16
16
|
*/
|
|
17
17
|
async function cleanDeletedBranches(options = {}) {
|
|
18
18
|
try {
|
|
19
|
-
const
|
|
19
|
+
const state = {
|
|
20
|
+
mainBranch: '',
|
|
21
|
+
deletedBranches: []
|
|
22
|
+
};
|
|
23
|
+
// Phase 1: Discovery
|
|
24
|
+
const discoveryTasks = new listr2_1.Listr([
|
|
20
25
|
{
|
|
21
26
|
title: 'Fetch main from remote',
|
|
22
27
|
task: async (ctx) => {
|
|
@@ -57,62 +62,42 @@ async function cleanDeletedBranches(options = {}) {
|
|
|
57
62
|
}
|
|
58
63
|
ctx.deletedBranches = deletedBranches;
|
|
59
64
|
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
title: 'Dry Run: List branches to be deleted',
|
|
93
|
-
enabled: (ctx) => !!options.dryRun && Array.isArray(ctx.deletedBranches) && ctx.deletedBranches.length > 0,
|
|
94
|
-
task: (ctx, task) => {
|
|
95
|
-
const branches = ctx.deletedBranches;
|
|
96
|
-
task.output = `The following branches would be deleted:\n${branches.map(b => ` - ${b}`).join('\n')}`;
|
|
97
|
-
// We don't want to fail, just show info.
|
|
98
|
-
// But listr output is transient.
|
|
99
|
-
// We will print it at the end or use a separate log.
|
|
100
|
-
console.log('\nDry Run: The following branches would be deleted:');
|
|
101
|
-
branches.forEach(b => console.log(` - ${b}`));
|
|
102
|
-
ctx.deletedBranches = []; // Clear so next step does nothing
|
|
103
|
-
}
|
|
104
|
-
},
|
|
65
|
+
}
|
|
66
|
+
]);
|
|
67
|
+
await discoveryTasks.run(state);
|
|
68
|
+
// Phase 2: Interaction / Filtering
|
|
69
|
+
if (state.deletedBranches.length === 0) {
|
|
70
|
+
(0, errors_2.printSuccess)('No branches need to be cleaned up');
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (options.interactive) {
|
|
74
|
+
try {
|
|
75
|
+
const selected = await (0, prompts_1.checkbox)({
|
|
76
|
+
message: 'Select branches to delete:',
|
|
77
|
+
choices: state.deletedBranches.map(b => ({ name: b, value: b, checked: true })),
|
|
78
|
+
});
|
|
79
|
+
state.deletedBranches = selected;
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
// User cancelled
|
|
83
|
+
throw new Error('Operation cancelled');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (state.deletedBranches.length === 0) {
|
|
87
|
+
(0, errors_2.printSuccess)('No branches selected for deletion');
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (options.dryRun) {
|
|
91
|
+
console.log('\nDry Run: The following branches would be deleted:');
|
|
92
|
+
state.deletedBranches.forEach(b => console.log(` - ${b}`));
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
// Phase 3: Execution
|
|
96
|
+
const deleteTasks = new listr2_1.Listr([
|
|
105
97
|
{
|
|
106
98
|
title: 'Delete branches removed on remote',
|
|
107
|
-
enabled: (ctx) => Array.isArray(ctx.deletedBranches),
|
|
108
|
-
skip: (ctx) => {
|
|
109
|
-
if (!ctx.deletedBranches || ctx.deletedBranches.length === 0) {
|
|
110
|
-
return 'No branches need to be cleaned up';
|
|
111
|
-
}
|
|
112
|
-
return false;
|
|
113
|
-
},
|
|
114
99
|
task: (ctx) => {
|
|
115
|
-
return new listr2_1.Listr(
|
|
100
|
+
return new listr2_1.Listr(state.deletedBranches.map(branch => ({
|
|
116
101
|
title: `Delete ${branch}`,
|
|
117
102
|
task: async () => {
|
|
118
103
|
await git.branch(['-D', branch]);
|
|
@@ -121,7 +106,7 @@ async function cleanDeletedBranches(options = {}) {
|
|
|
121
106
|
}
|
|
122
107
|
}
|
|
123
108
|
]);
|
|
124
|
-
await
|
|
109
|
+
await deleteTasks.run(state);
|
|
125
110
|
(0, errors_2.printSuccess)('Branch cleanup completed');
|
|
126
111
|
}
|
|
127
112
|
catch (error) {
|
package/package.json
CHANGED