@harryisfish/gitt 1.6.5 → 1.6.7

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,25 +23,21 @@ async function cleanDeletedBranches(options = {}) {
23
23
  // Phase 1: Discovery
24
24
  const discoveryTasks = new listr2_1.Listr([
25
25
  {
26
- title: 'Switch to main branch',
26
+ title: 'Fetch and 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
- // Always switch to main branch first
32
+ // Fetch main branch first to avoid conflicts
33
+ await git.fetch(['origin', mainBranch]);
34
+ // Switch to main branch if not already on it
33
35
  if (ctx.currentBranch !== mainBranch) {
34
36
  await git.checkout(mainBranch);
35
37
  await git.pull();
36
38
  }
37
39
  }
38
40
  },
39
- {
40
- title: 'Fetch from remote',
41
- task: async (ctx) => {
42
- await git.fetch(['origin', ctx.mainBranch]);
43
- }
44
- },
45
41
  {
46
42
  title: 'Analyze branches',
47
43
  task: async (ctx) => {
package/dist/utils/git.js CHANGED
@@ -79,11 +79,28 @@ async function setMainBranch(branch) {
79
79
  }
80
80
  /**
81
81
  * Check if a branch is merged into the main branch.
82
+ * Supports regular merge, squash merge, and rebase merge detection.
82
83
  */
83
84
  async function isBranchMerged(branch, mainBranch) {
84
85
  try {
86
+ // Method 1: Check regular merge with git branch --merged
85
87
  const mergedBranches = await git.branch(['--merged', mainBranch]);
86
- return mergedBranches.all.includes(branch);
88
+ if (mergedBranches.all.includes(branch)) {
89
+ return true;
90
+ }
91
+ // Method 2: Check squash/rebase merge with git cherry
92
+ // git cherry returns empty or all lines start with '-' if fully merged
93
+ // '-' means the commit exists in upstream (merged)
94
+ // '+' means the commit does not exist in upstream (not merged)
95
+ const cherryOutput = await git.raw(['cherry', mainBranch, branch]);
96
+ const lines = cherryOutput.trim().split('\n').filter(Boolean);
97
+ // If no commits unique to branch, or all commits are merged (start with -)
98
+ if (lines.length === 0) {
99
+ return true;
100
+ }
101
+ // Check if all commits are merged (all lines start with '-')
102
+ const hasUnmergedCommits = lines.some(line => line.startsWith('+'));
103
+ return !hasUnmergedCommits;
87
104
  }
88
105
  catch (error) {
89
106
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harryisfish/gitt",
3
- "version": "1.6.5",
3
+ "version": "1.6.7",
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": {