@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.
@@ -16,7 +16,12 @@ const git = (0, simple_git_1.simpleGit)();
16
16
  */
17
17
  async function cleanDeletedBranches(options = {}) {
18
18
  try {
19
- const tasks = new listr2_1.Listr([
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
- title: 'Select branches to delete',
63
- enabled: (ctx) => !!options.interactive && Array.isArray(ctx.deletedBranches) && ctx.deletedBranches.length > 0,
64
- task: async (ctx, task) => {
65
- const branches = ctx.deletedBranches;
66
- // Pause the listr task to show prompt
67
- // We need to stop the spinner to show the prompt clearly
68
- // But listr2 doesn't make it easy to pause/resume in the middle of a task flow easily without custom renderers
69
- // So we will do the prompt and then update the context
70
- // Actually, listr2 supports prompts but it's complex.
71
- // Let's try to use the prompt directly.
72
- // We might need to handle the UI interference.
73
- // For now, let's just run the prompt.
74
- // In a real TTY, listr2 might fight for control.
75
- // A common pattern is to run the prompt outside listr or use listr's prompt adapter.
76
- // But here we are inside a task.
77
- // Let's try to use the prompt.
78
- try {
79
- const selected = await (0, prompts_1.checkbox)({
80
- message: 'Select branches to delete:',
81
- choices: branches.map(b => ({ name: b, value: b, checked: true })),
82
- });
83
- ctx.deletedBranches = selected;
84
- }
85
- catch (e) {
86
- // If user cancels, we might want to abort or just delete nothing
87
- ctx.deletedBranches = [];
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((ctx.deletedBranches || []).map(branch => ({
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 tasks.run();
109
+ await deleteTasks.run(state);
125
110
  (0, errors_2.printSuccess)('Branch cleanup completed');
126
111
  }
127
112
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harryisfish/gitt",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "A command-line tool to help you manage Git repositories and remote repositories, such as keeping in sync, pushing, pulling, etc.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {