Skip to content

Commit 9979a83

Browse files
authored
Use case-insensitive includeIf.gitdir on Windows
On Windows, git's includeIf.gitdir: directive performs case-sensitive path matching, but the Windows filesystem is case-insensitive. When the runner's GITHUB_WORKSPACE has different casing than the actual path on disk (e.g. D:\workspaces vs D:\Workspaces), the includeIf condition fails to match, breaking credential authentication. This was a regression in v6, which introduced includeIf.gitdir: for credential isolation. v5 did not use includeIf and was unaffected. Fix: use includeIf.gitdir/i: (case-insensitive variant) on Windows. This git feature has been available since git 2.13.0, well before checkout's minimum requirement of git 2.18. Also update the cleanup regex to match both gitdir: and gitdir/i: so credential removal works correctly on Windows. Fixes #2345
1 parent 900f221 commit 9979a83

2 files changed

Lines changed: 22 additions & 14 deletions

File tree

dist/index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ 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 ? 'includeIf.gitdir/i:' : 'includeIf.gitdir:';
154158
const SSH_COMMAND_KEY = 'core.sshCommand';
155159
function createAuthHelper(git, settings) {
156160
return new GitAuthHelper(git, settings);
@@ -270,7 +274,7 @@ class GitAuthHelper {
270274
let submoduleGitDir = path.dirname(configPath); // The config file is at .git/modules/submodule-name/config
271275
submoduleGitDir = submoduleGitDir.replace(/\\/g, '/'); // Use forward slashes, even on Windows
272276
// Configure host includeIf
273-
yield this.git.config(`includeIf.gitdir:${submoduleGitDir}.path`, credentialsConfigPath, false, // globalConfig?
277+
yield this.git.config(`${INCLUDE_IF_GITDIR}${submoduleGitDir}.path`, credentialsConfigPath, false, // globalConfig?
274278
false, // add?
275279
configPath);
276280
// Container submodule git directory
@@ -280,7 +284,7 @@ class GitAuthHelper {
280284
relativeSubmoduleGitDir = relativeSubmoduleGitDir.replace(/\\/g, '/'); // Use forward slashes, even on Windows
281285
const containerSubmoduleGitDir = path.posix.join('/github/workspace', relativeSubmoduleGitDir);
282286
// Configure container includeIf
283-
yield this.git.config(`includeIf.gitdir:${containerSubmoduleGitDir}.path`, containerCredentialsPath, false, // globalConfig?
287+
yield this.git.config(`${INCLUDE_IF_GITDIR}${containerSubmoduleGitDir}.path`, containerCredentialsPath, false, // globalConfig?
284288
false, // add?
285289
configPath);
286290
}
@@ -410,10 +414,10 @@ class GitAuthHelper {
410414
let gitDir = path.join(this.git.getWorkingDirectory(), '.git');
411415
gitDir = gitDir.replace(/\\/g, '/'); // Use forward slashes, even on Windows
412416
// Configure host includeIf
413-
const hostIncludeKey = `includeIf.gitdir:${gitDir}.path`;
417+
const hostIncludeKey = `${INCLUDE_IF_GITDIR}${gitDir}.path`;
414418
yield this.git.config(hostIncludeKey, credentialsConfigPath);
415419
// Configure host includeIf for worktrees
416-
const hostWorktreeIncludeKey = `includeIf.gitdir:${gitDir}/worktrees/*.path`;
420+
const hostWorktreeIncludeKey = `${INCLUDE_IF_GITDIR}${gitDir}/worktrees/*.path`;
417421
yield this.git.config(hostWorktreeIncludeKey, credentialsConfigPath);
418422
// Container git directory
419423
const workingDirectory = this.git.getWorkingDirectory();
@@ -425,10 +429,10 @@ class GitAuthHelper {
425429
// Container credentials config path
426430
const containerCredentialsPath = path.posix.join('/github/runner_temp', path.basename(credentialsConfigPath));
427431
// Configure container includeIf
428-
const containerIncludeKey = `includeIf.gitdir:${containerGitDir}.path`;
432+
const containerIncludeKey = `${INCLUDE_IF_GITDIR}${containerGitDir}.path`;
429433
yield this.git.config(containerIncludeKey, containerCredentialsPath);
430434
// Configure container includeIf for worktrees
431-
const containerWorktreeIncludeKey = `includeIf.gitdir:${containerGitDir}/worktrees/*.path`;
435+
const containerWorktreeIncludeKey = `${INCLUDE_IF_GITDIR}${containerGitDir}/worktrees/*.path`;
432436
yield this.git.config(containerWorktreeIncludeKey, containerCredentialsPath);
433437
}
434438
});
@@ -565,7 +569,7 @@ class GitAuthHelper {
565569
const credentialsPaths = new Set();
566570
try {
567571
// Get all includeIf.gitdir keys
568-
const keys = yield this.git.tryGetConfigKeys('^includeIf\\.gitdir:', false, // globalConfig?
572+
const keys = yield this.git.tryGetConfigKeys('^includeIf\\.gitdir(/i)?:', false, // globalConfig?
569573
configPath);
570574
for (const key of keys) {
571575
// Get all values for this key

src/git-auth-helper.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ 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 ? 'includeIf.gitdir/i:' : 'includeIf.gitdir:'
1620
const SSH_COMMAND_KEY = 'core.sshCommand'
1721

1822
export interface IGitAuthHelper {
@@ -182,7 +186,7 @@ class GitAuthHelper {
182186

183187
// Configure host includeIf
184188
await this.git.config(
185-
`includeIf.gitdir:${submoduleGitDir}.path`,
189+
`${INCLUDE_IF_GITDIR}${submoduleGitDir}.path`,
186190
credentialsConfigPath,
187191
false, // globalConfig?
188192
false, // add?
@@ -204,7 +208,7 @@ class GitAuthHelper {
204208

205209
// Configure container includeIf
206210
await this.git.config(
207-
`includeIf.gitdir:${containerSubmoduleGitDir}.path`,
211+
`${INCLUDE_IF_GITDIR}${containerSubmoduleGitDir}.path`,
208212
containerCredentialsPath,
209213
false, // globalConfig?
210214
false, // add?
@@ -371,11 +375,11 @@ class GitAuthHelper {
371375
gitDir = gitDir.replace(/\\/g, '/') // Use forward slashes, even on Windows
372376

373377
// Configure host includeIf
374-
const hostIncludeKey = `includeIf.gitdir:${gitDir}.path`
378+
const hostIncludeKey = `${INCLUDE_IF_GITDIR}${gitDir}.path`
375379
await this.git.config(hostIncludeKey, credentialsConfigPath)
376380

377381
// Configure host includeIf for worktrees
378-
const hostWorktreeIncludeKey = `includeIf.gitdir:${gitDir}/worktrees/*.path`
382+
const hostWorktreeIncludeKey = `${INCLUDE_IF_GITDIR}${gitDir}/worktrees/*.path`
379383
await this.git.config(hostWorktreeIncludeKey, credentialsConfigPath)
380384

381385
// Container git directory
@@ -397,11 +401,11 @@ class GitAuthHelper {
397401
)
398402

399403
// Configure container includeIf
400-
const containerIncludeKey = `includeIf.gitdir:${containerGitDir}.path`
404+
const containerIncludeKey = `${INCLUDE_IF_GITDIR}${containerGitDir}.path`
401405
await this.git.config(containerIncludeKey, containerCredentialsPath)
402406

403407
// Configure container includeIf for worktrees
404-
const containerWorktreeIncludeKey = `includeIf.gitdir:${containerGitDir}/worktrees/*.path`
408+
const containerWorktreeIncludeKey = `${INCLUDE_IF_GITDIR}${containerGitDir}/worktrees/*.path`
405409
await this.git.config(
406410
containerWorktreeIncludeKey,
407411
containerCredentialsPath
@@ -554,7 +558,7 @@ class GitAuthHelper {
554558
try {
555559
// Get all includeIf.gitdir keys
556560
const keys = await this.git.tryGetConfigKeys(
557-
'^includeIf\\.gitdir:',
561+
'^includeIf\\.gitdir(/i)?:',
558562
false, // globalConfig?
559563
configPath
560564
)

0 commit comments

Comments
 (0)