Skip to content

Commit 2d52c13

Browse files
vasilii-bolgar-212claude
authored andcommitted
fix: preserve checked-out repo remote URL in configureGitAuth
configureGitAuth() was constructing the remote URL from context.repository (GITHUB_REPOSITORY env var), which is always the workflow's host repo. When actions/checkout checks out a different repo, the action would overwrite the origin remote to point at the wrong repository, breaking subsequent git push steps. Now reads the current remote URL and injects the auth token into it, preserving whatever repo actions/checkout set up. Falls back to the previous context.repository behavior if reading the remote fails. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2e26adc commit 2d52c13

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/github/operations/git-config.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,21 @@ export async function configureGitAuth(
7373
await $`git config credential.helper ${helperPath}`;
7474
console.log("✓ Configured credential helper");
7575
} else {
76-
// Update the remote URL to include the token for authentication
76+
// Inject auth token into the existing remote URL, preserving the original
77+
// repo (which may differ from context.repository if a different repo was checked out)
7778
console.log("Updating remote URL with authentication...");
78-
const remoteUrl = `https://x-access-token:${githubToken}@${serverUrl.host}/${context.repository.owner}/${context.repository.repo}.git`;
79+
let remoteUrl: string;
80+
try {
81+
const currentUrl = (await $`git remote get-url origin`.text()).trim();
82+
const parsed = new URL(
83+
currentUrl.endsWith(".git") ? currentUrl : currentUrl + ".git",
84+
);
85+
parsed.username = "x-access-token";
86+
parsed.password = githubToken;
87+
remoteUrl = parsed.toString();
88+
} catch {
89+
remoteUrl = `https://x-access-token:${githubToken}@${serverUrl.host}/${context.repository.owner}/${context.repository.repo}.git`;
90+
}
7991
await $`git remote set-url origin ${remoteUrl}`;
8092
console.log("✓ Updated remote URL with authentication token");
8193
}

0 commit comments

Comments
 (0)