@harryisfish/gitt 1.6.3 → 1.6.5

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.
@@ -23,13 +23,23 @@ async function cleanDeletedBranches(options = {}) {
23
23
  // Phase 1: Discovery
24
24
  const discoveryTasks = new listr2_1.Listr([
25
25
  {
26
- title: 'Fetch main from remote',
26
+ title: 'Switch to main branch',
27
27
  task: async (ctx) => {
28
28
  const mainBranch = await (0, git_1.getMainBranch)();
29
29
  ctx.mainBranch = mainBranch;
30
30
  const branchInfo = await git.branchLocal();
31
31
  ctx.currentBranch = branchInfo.current;
32
- await git.fetch(['origin', mainBranch]);
32
+ // Always switch to main branch first
33
+ if (ctx.currentBranch !== mainBranch) {
34
+ await git.checkout(mainBranch);
35
+ await git.pull();
36
+ }
37
+ }
38
+ },
39
+ {
40
+ title: 'Fetch from remote',
41
+ task: async (ctx) => {
42
+ await git.fetch(['origin', ctx.mainBranch]);
33
43
  }
34
44
  },
35
45
  {
@@ -129,18 +139,6 @@ async function cleanDeletedBranches(options = {}) {
129
139
  state.deletedBranches.forEach(b => console.log(` - ${b.name} (${b.reason})`));
130
140
  return;
131
141
  }
132
- // Switch to main branch if current branch will be deleted
133
- const willDeleteCurrent = state.deletedBranches.some(b => b.name === state.currentBranch);
134
- if (willDeleteCurrent) {
135
- try {
136
- await git.checkout(state.mainBranch);
137
- await git.pull();
138
- console.log(`Switched to ${state.mainBranch} and synced with remote`);
139
- }
140
- catch (e) {
141
- throw new errors_1.GitError(`Cannot switch to ${state.mainBranch}. Current branch "${state.currentBranch}" will be deleted but checkout failed: ${e instanceof Error ? e.message : 'Unknown error'}`);
142
- }
143
- }
144
142
  // Phase 3: Execution
145
143
  const deleteTasks = new listr2_1.Listr([
146
144
  {
package/dist/index.js CHANGED
@@ -86,11 +86,12 @@ async function main() {
86
86
  program
87
87
  .option('-i, --interactive', 'Interactive mode: Select branches to delete')
88
88
  .option('-d, --dry-run', 'Dry run: Show what would be deleted without deleting')
89
- .option('--stale [days]', 'Find stale branches (default: 90 days)', '90')
89
+ .option('--stale [days]', 'Find stale branches (default: 90 days)')
90
90
  .action(async (options) => {
91
91
  await checkGitRepo();
92
- const staleDays = options.stale === true ? 90 : parseInt(options.stale, 10);
92
+ // options.stale is undefined when not passed, true when passed without value, or a string when passed with value
93
93
  const isStale = options.stale !== undefined;
94
+ const staleDays = options.stale === true || options.stale === undefined ? 90 : parseInt(options.stale, 10);
94
95
  await (0, clean_1.cleanDeletedBranches)({
95
96
  interactive: options.interactive || false,
96
97
  dryRun: options.dryRun || false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harryisfish/gitt",
3
- "version": "1.6.3",
3
+ "version": "1.6.5",
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": {