Skip to content

Commit 6e134d0

Browse files
authored
Fix includeIf case sensitivity on Windows self-hosted runners
Switch to includeIf.gitdir/i: on Windows so path matching is case-insensitive, matching the filesystem behavior. This fixes auth failures on self-hosted Windows runners where the workspace folder casing doesn't match between the runner config and disk. Also update the cleanup regex to handle both gitdir: and gitdir/i: variants. Fixes #2345
1 parent 900f221 commit 6e134d0

2 files changed

Lines changed: 26 additions & 14 deletions

File tree

dist/index.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ const stateHelper = __importStar(__nccwpck_require__(4866));
151151
const urlHelper = __importStar(__nccwpck_require__(9437));
152152
const uuid_1 = __nccwpck_require__(5840);
153153
const IS_WINDOWS = process.platform === 'win32';
154+
// Use case-insensitive gitdir matching on Windows to handle path casing mismatches
155+
// between the runner's GITHUB_WORKSPACE and the actual filesystem casing.
156+
// See: https://github.com/actions/checkout/issues/2345
157+
const INCLUDE_IF_GITDIR = IS_WINDOWS
158+
? 'includeIf.gitdir/i:'
159+
: 'includeIf.gitdir:';
154160
const SSH_COMMAND_KEY = 'core.sshCommand';
155161
function createAuthHelper(git, settings) {
156162
return new GitAuthHelper(git, settings);
@@ -270,7 +276,7 @@ class GitAuthHelper {
270276
let submoduleGitDir = path.dirname(configPath); // The config file is at .git/modules/submodule-name/config
271277
submoduleGitDir = submoduleGitDir.replace(/\\/g, '/'); // Use forward slashes, even on Windows
272278
// Configure host includeIf
273-
yield this.git.config(`includeIf.gitdir:${submoduleGitDir}.path`, credentialsConfigPath, false, // globalConfig?
279+
yield this.git.config(`${INCLUDE_IF_GITDIR}${submoduleGitDir}.path`, credentialsConfigPath, false, // globalConfig?
274280
false, // add?
275281
configPath);
276282
// Container submodule git directory
@@ -280,7 +286,7 @@ class GitAuthHelper {
280286
relativeSubmoduleGitDir = relativeSubmoduleGitDir.replace(/\\/g, '/'); // Use forward slashes, even on Windows
281287
const containerSubmoduleGitDir = path.posix.join('/github/workspace', relativeSubmoduleGitDir);
282288
// Configure container includeIf
283-
yield this.git.config(`includeIf.gitdir:${containerSubmoduleGitDir}.path`, containerCredentialsPath, false, // globalConfig?
289+
yield this.git.config(`${INCLUDE_IF_GITDIR}${containerSubmoduleGitDir}.path`, containerCredentialsPath, false, // globalConfig?
284290
false, // add?
285291
configPath);
286292
}
@@ -410,10 +416,10 @@ class GitAuthHelper {
410416
let gitDir = path.join(this.git.getWorkingDirectory(), '.git');
411417
gitDir = gitDir.replace(/\\/g, '/'); // Use forward slashes, even on Windows
412418
// Configure host includeIf
413-
const hostIncludeKey = `includeIf.gitdir:${gitDir}.path`;
419+
const hostIncludeKey = `${INCLUDE_IF_GITDIR}${gitDir}.path`;
414420
yield this.git.config(hostIncludeKey, credentialsConfigPath);
415421
// Configure host includeIf for worktrees
416-
const hostWorktreeIncludeKey = `includeIf.gitdir:${gitDir}/worktrees/*.path`;
422+
const hostWorktreeIncludeKey = `${INCLUDE_IF_GITDIR}${gitDir}/worktrees/*.path`;
417423
yield this.git.config(hostWorktreeIncludeKey, credentialsConfigPath);
418424
// Container git directory
419425
const workingDirectory = this.git.getWorkingDirectory();
@@ -425,10 +431,10 @@ class GitAuthHelper {
425431
// Container credentials config path
426432
const containerCredentialsPath = path.posix.join('/github/runner_temp', path.basename(credentialsConfigPath));
427433
// Configure container includeIf
428-
const containerIncludeKey = `includeIf.gitdir:${containerGitDir}.path`;
434+
const containerIncludeKey = `${INCLUDE_IF_GITDIR}${containerGitDir}.path`;
429435
yield this.git.config(containerIncludeKey, containerCredentialsPath);
430436
// Configure container includeIf for worktrees
431-
const containerWorktreeIncludeKey = `includeIf.gitdir:${containerGitDir}/worktrees/*.path`;
437+
const containerWorktreeIncludeKey = `${INCLUDE_IF_GITDIR}${containerGitDir}/worktrees/*.path`;
432438
yield this.git.config(containerWorktreeIncludeKey, containerCredentialsPath);
433439
}
434440
});
@@ -565,7 +571,7 @@ class GitAuthHelper {
565571
const credentialsPaths = new Set();
566572
try {
567573
// Get all includeIf.gitdir keys
568-
const keys = yield this.git.tryGetConfigKeys('^includeIf\\.gitdir:', false, // globalConfig?
574+
const keys = yield this.git.tryGetConfigKeys('^includeIf\\.gitdir(/i)?:', false, // globalConfig?
569575
configPath);
570576
for (const key of keys) {
571577
// Get all values for this key

src/git-auth-helper.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import {IGitCommandManager} from './git-command-manager'
1313
import {IGitSourceSettings} from './git-source-settings'
1414

1515
const IS_WINDOWS = process.platform === 'win32'
16+
// Use case-insensitive gitdir matching on Windows to handle path casing mismatches
17+
// between the runner's GITHUB_WORKSPACE and the actual filesystem casing.
18+
// See: https://github.com/actions/checkout/issues/2345
19+
const INCLUDE_IF_GITDIR = IS_WINDOWS
20+
? 'includeIf.gitdir/i:'
21+
: 'includeIf.gitdir:'
1622
const SSH_COMMAND_KEY = 'core.sshCommand'
1723

1824
export interface IGitAuthHelper {
@@ -182,7 +188,7 @@ class GitAuthHelper {
182188

183189
// Configure host includeIf
184190
await this.git.config(
185-
`includeIf.gitdir:${submoduleGitDir}.path`,
191+
`${INCLUDE_IF_GITDIR}${submoduleGitDir}.path`,
186192
credentialsConfigPath,
187193
false, // globalConfig?
188194
false, // add?
@@ -204,7 +210,7 @@ class GitAuthHelper {
204210

205211
// Configure container includeIf
206212
await this.git.config(
207-
`includeIf.gitdir:${containerSubmoduleGitDir}.path`,
213+
`${INCLUDE_IF_GITDIR}${containerSubmoduleGitDir}.path`,
208214
containerCredentialsPath,
209215
false, // globalConfig?
210216
false, // add?
@@ -371,11 +377,11 @@ class GitAuthHelper {
371377
gitDir = gitDir.replace(/\\/g, '/') // Use forward slashes, even on Windows
372378

373379
// Configure host includeIf
374-
const hostIncludeKey = `includeIf.gitdir:${gitDir}.path`
380+
const hostIncludeKey = `${INCLUDE_IF_GITDIR}${gitDir}.path`
375381
await this.git.config(hostIncludeKey, credentialsConfigPath)
376382

377383
// Configure host includeIf for worktrees
378-
const hostWorktreeIncludeKey = `includeIf.gitdir:${gitDir}/worktrees/*.path`
384+
const hostWorktreeIncludeKey = `${INCLUDE_IF_GITDIR}${gitDir}/worktrees/*.path`
379385
await this.git.config(hostWorktreeIncludeKey, credentialsConfigPath)
380386

381387
// Container git directory
@@ -397,11 +403,11 @@ class GitAuthHelper {
397403
)
398404

399405
// Configure container includeIf
400-
const containerIncludeKey = `includeIf.gitdir:${containerGitDir}.path`
406+
const containerIncludeKey = `${INCLUDE_IF_GITDIR}${containerGitDir}.path`
401407
await this.git.config(containerIncludeKey, containerCredentialsPath)
402408

403409
// Configure container includeIf for worktrees
404-
const containerWorktreeIncludeKey = `includeIf.gitdir:${containerGitDir}/worktrees/*.path`
410+
const containerWorktreeIncludeKey = `${INCLUDE_IF_GITDIR}${containerGitDir}/worktrees/*.path`
405411
await this.git.config(
406412
containerWorktreeIncludeKey,
407413
containerCredentialsPath
@@ -554,7 +560,7 @@ class GitAuthHelper {
554560
try {
555561
// Get all includeIf.gitdir keys
556562
const keys = await this.git.tryGetConfigKeys(
557-
'^includeIf\\.gitdir:',
563+
'^includeIf\\.gitdir(/i)?:',
558564
false, // globalConfig?
559565
configPath
560566
)

0 commit comments

Comments
 (0)