@harryisfish/gitt 1.1.1 → 1.2.0

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.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.cleanDeletedBranches = cleanDeletedBranches;
4
4
  const simple_git_1 = require("simple-git");
5
+ const listr2_1 = require("listr2");
5
6
  const errors_1 = require("../errors");
6
7
  const errors_2 = require("../errors");
7
8
  const git = (0, simple_git_1.simpleGit)();
@@ -11,30 +12,51 @@ const git = (0, simple_git_1.simpleGit)();
11
12
  */
12
13
  async function cleanDeletedBranches() {
13
14
  try {
14
- console.log('Switching to main branch...');
15
- await git.checkout('main');
16
- console.log('Pulling latest code...');
17
- await git.pull();
18
- console.log('Cleaning up remotely deleted branches...');
19
- // 获取最新的远程分支信息
20
- await git.fetch(['--prune']);
21
- // 获取所有分支信息
22
- const branchSummary = await git.branch(['-vv']);
23
- // 找出已经在远程被删除的分支
24
- const deletedBranches = branchSummary.all.filter(branch => {
25
- const branchInfo = branchSummary.branches[branch];
26
- return branchInfo.label && branchInfo.label.includes(': gone]');
27
- });
28
- if (deletedBranches.length === 0) {
29
- console.log('No branches need to be cleaned up.');
30
- return;
31
- }
32
- console.log('The following branches will be deleted:', deletedBranches.join(', '));
33
- // 删除这些分支
34
- for (const branch of deletedBranches) {
35
- await git.branch(['-D', branch]);
36
- console.log(`Deleted branch: ${branch}`);
37
- }
15
+ const tasks = new listr2_1.Listr([
16
+ {
17
+ title: 'Switch to main branch',
18
+ task: async () => {
19
+ await git.checkout('main');
20
+ }
21
+ },
22
+ {
23
+ title: 'Pull latest code',
24
+ task: async () => {
25
+ await git.pull();
26
+ }
27
+ },
28
+ {
29
+ title: 'Fetch and prune remote branches',
30
+ task: async (ctx) => {
31
+ await git.fetch(['--prune']);
32
+ const branchSummary = await git.branch(['-vv']);
33
+ const deletedBranches = branchSummary.all.filter(branch => {
34
+ const branchInfo = branchSummary.branches[branch];
35
+ return branchInfo.label && branchInfo.label.includes(': gone]');
36
+ });
37
+ ctx.deletedBranches = deletedBranches;
38
+ }
39
+ },
40
+ {
41
+ title: 'Delete branches removed on remote',
42
+ enabled: (ctx) => Array.isArray(ctx.deletedBranches),
43
+ skip: (ctx) => {
44
+ if (!ctx.deletedBranches || ctx.deletedBranches.length === 0) {
45
+ return 'No branches need to be cleaned up';
46
+ }
47
+ return false;
48
+ },
49
+ task: (ctx) => {
50
+ return new listr2_1.Listr((ctx.deletedBranches || []).map(branch => ({
51
+ title: `Delete ${branch}`,
52
+ task: async () => {
53
+ await git.branch(['-D', branch]);
54
+ }
55
+ })), { concurrent: false });
56
+ }
57
+ }
58
+ ]);
59
+ await tasks.run();
38
60
  (0, errors_2.printSuccess)('Branch cleanup completed');
39
61
  }
40
62
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harryisfish/gitt",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
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": {
@@ -38,7 +38,8 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@inquirer/prompts": "^3.3.0",
41
- "simple-git": "^3.22.0"
41
+ "simple-git": "^3.22.0",
42
+ "listr2": "^8.0.0"
42
43
  },
43
44
  "engines": {
44
45
  "node": ">=14.0.0"