MCPcopy Create free account
hub / github.com/codeaashu/claude-code / ensureUpstreamIsSet

Function ensureUpstreamIsSet

src/utils/teleport.tsx:215–246  ·  view source on GitHub ↗

* Ensures that the current branch has an upstream set * If not, sets it to origin/ if that remote branch exists

(branchName: string)

Source from the content-addressed store, hash-verified

213 * If not, sets it to origin/<branchName> if that remote branch exists
214 */
215async function ensureUpstreamIsSet(branchName: string): Promise<void> {
216 // Check if upstream is already set
217 const {
218 code: upstreamCheckCode
219 } = await execFileNoThrow(gitExe(), ['rev-parse', '--abbrev-ref', `${branchName}@{upstream}`]);
220 if (upstreamCheckCode === 0) {
221 // Upstream is already set
222 logForDebugging(`Branch '${branchName}' already has upstream set`);
223 return;
224 }
225
226 // Check if origin/<branchName> exists
227 const {
228 code: remoteCheckCode
229 } = await execFileNoThrow(gitExe(), ['rev-parse', '--verify', `origin/${branchName}`]);
230 if (remoteCheckCode === 0) {
231 // Remote branch exists, set upstream
232 logForDebugging(`Setting upstream for '${branchName}' to 'origin/${branchName}'`);
233 const {
234 code: setUpstreamCode,
235 stderr: setUpstreamStderr
236 } = await execFileNoThrow(gitExe(), ['branch', '--set-upstream-to', `origin/${branchName}`, branchName]);
237 if (setUpstreamCode !== 0) {
238 logForDebugging(`Failed to set upstream for '${branchName}': ${setUpstreamStderr}`);
239 // Don't throw, just log - this is not critical
240 } else {
241 logForDebugging(`Successfully set upstream for '${branchName}'`);
242 }
243 } else {
244 logForDebugging(`Remote branch 'origin/${branchName}' does not exist, skipping upstream setup`);
245 }
246}
247
248/**
249 * Checks out a specific branch

Callers 1

checkoutBranchFunction · 0.85

Calls 2

execFileNoThrowFunction · 0.85
logForDebuggingFunction · 0.85

Tested by

no test coverage detected