@harryisfish/gitt 1.6.6 → 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.
- package/dist/utils/git.js +18 -1
- package/package.json +1 -1
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
|
-
|
|
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