threadlines 0.1.16 → 0.1.17
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/git/diff.js +12 -4
- package/package.json +1 -1
package/dist/git/diff.js
CHANGED
|
@@ -95,15 +95,18 @@ async function getBranchDiff(repoRoot, branchName, baseBranch) {
|
|
|
95
95
|
base = await detectBaseBranch(git, branchName);
|
|
96
96
|
}
|
|
97
97
|
// Helper function to detect base branch
|
|
98
|
+
// Returns the branch name to use in git commands (may be local or remote)
|
|
98
99
|
async function detectBaseBranch(git, branchName) {
|
|
99
100
|
// Try upstream tracking branch
|
|
100
101
|
const upstream = await git.revparse(['--abbrev-ref', '--symbolic-full-name', `${branchName}@{u}`]).catch(() => null);
|
|
101
102
|
if (upstream) {
|
|
102
|
-
// Extract base from upstream (e.g., "origin/main" -> "main")
|
|
103
|
+
// Extract base from upstream (e.g., "origin/main" -> check if local exists, else use "origin/main")
|
|
103
104
|
const upstreamBranch = upstream.replace(/^origin\//, '');
|
|
104
105
|
// Don't use the branch itself as its base
|
|
105
106
|
if (upstreamBranch !== branchName) {
|
|
106
|
-
|
|
107
|
+
// Check if local branch exists, otherwise use remote
|
|
108
|
+
const localExists = await git.revparse([upstreamBranch]).catch(() => null);
|
|
109
|
+
return localExists ? upstreamBranch : upstream;
|
|
107
110
|
}
|
|
108
111
|
}
|
|
109
112
|
// Try default branch
|
|
@@ -112,7 +115,9 @@ async function getBranchDiff(repoRoot, branchName, baseBranch) {
|
|
|
112
115
|
const defaultBranchName = defaultBranch.replace(/^origin\//, '');
|
|
113
116
|
// Don't use the branch itself as its base
|
|
114
117
|
if (defaultBranchName !== branchName) {
|
|
115
|
-
|
|
118
|
+
// Check if local branch exists, otherwise use remote
|
|
119
|
+
const localExists = await git.revparse([defaultBranchName]).catch(() => null);
|
|
120
|
+
return localExists ? defaultBranchName : defaultBranch;
|
|
116
121
|
}
|
|
117
122
|
}
|
|
118
123
|
catch {
|
|
@@ -125,8 +130,11 @@ async function getBranchDiff(repoRoot, branchName, baseBranch) {
|
|
|
125
130
|
continue; // Skip if it's the same branch
|
|
126
131
|
}
|
|
127
132
|
try {
|
|
133
|
+
// Check if remote exists
|
|
128
134
|
await git.revparse([`origin/${candidate}`]);
|
|
129
|
-
|
|
135
|
+
// Check if local exists, otherwise use remote
|
|
136
|
+
const localExists = await git.revparse([candidate]).catch(() => null);
|
|
137
|
+
return localExists ? candidate : `origin/${candidate}`;
|
|
130
138
|
}
|
|
131
139
|
catch {
|
|
132
140
|
// Try next
|