Skip to content

Commit 6c0ab7a

Browse files
committed
Add worktree support for persist-credentials includeIf
1 parent c2d88d3 commit 6c0ab7a

4 files changed

Lines changed: 82 additions & 0 deletions

File tree

.github/workflows/test.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,22 @@ jobs:
165165
- name: Verify submodules recursive
166166
run: __test__/verify-submodules-recursive.sh
167167

168+
# Worktree credentials
169+
- name: Checkout for worktree test
170+
uses: ./
171+
with:
172+
path: worktree-test
173+
- name: Verify worktree credentials
174+
shell: bash
175+
run: __test__/verify-worktree.sh
176+
177+
# Worktree credentials in container step
178+
- name: Verify worktree credentials in container step
179+
if: runner.os == 'Linux'
180+
uses: docker://bitnami/git:latest
181+
with:
182+
args: bash __test__/verify-worktree.sh
183+
168184
# Basic checkout using REST API
169185
- name: Remove basic
170186
if: runner.os != 'windows'

__test__/verify-worktree.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Verify worktree credentials
5+
# This test verifies that git credentials work in worktrees created after checkout
6+
# Usage: verify-worktree.sh [checkout-path]
7+
8+
CHECKOUT_PATH="${1:-worktree-test}"
9+
10+
cd "$CHECKOUT_PATH"
11+
12+
# Add safe directory for container environments
13+
git config --global --add safe.directory "*" 2>/dev/null || true
14+
15+
# Show the includeIf configuration
16+
echo "Git config includeIf entries:"
17+
git config --list --show-origin | grep -i include || true
18+
19+
# Create a worktree if it doesn't exist
20+
if [ ! -d "../worktree-branch" ]; then
21+
echo "Creating worktree..."
22+
git worktree add ../worktree-branch HEAD --detach
23+
else
24+
echo "Worktree already exists, reusing..."
25+
fi
26+
27+
# Change to worktree directory
28+
cd ../worktree-branch
29+
30+
# Verify we're in a worktree
31+
echo "Verifying worktree gitdir:"
32+
cat .git
33+
34+
# Verify credentials are available in worktree by checking extraheader is configured
35+
echo "Checking credentials in worktree..."
36+
if git config --list --show-origin | grep -q "extraheader"; then
37+
echo "Credentials are configured in worktree"
38+
else
39+
echo "ERROR: Credentials are NOT configured in worktree"
40+
echo "Full git config:"
41+
git config --list --show-origin
42+
exit 1
43+
fi
44+
45+
# Verify fetch works in the worktree
46+
echo "Fetching in worktree..."
47+
git fetch origin
48+
49+
echo "Worktree credentials test passed!"

dist/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@ class GitAuthHelper {
412412
// Configure host includeIf
413413
const hostIncludeKey = `includeIf.gitdir:${gitDir}.path`;
414414
yield this.git.config(hostIncludeKey, credentialsConfigPath);
415+
// Configure host includeIf for worktrees
416+
const hostWorktreeIncludeKey = `includeIf.gitdir:${gitDir}/worktrees/*.path`;
417+
yield this.git.config(hostWorktreeIncludeKey, credentialsConfigPath);
415418
// Container git directory
416419
const workingDirectory = this.git.getWorkingDirectory();
417420
const githubWorkspace = process.env['GITHUB_WORKSPACE'];
@@ -424,6 +427,9 @@ class GitAuthHelper {
424427
// Configure container includeIf
425428
const containerIncludeKey = `includeIf.gitdir:${containerGitDir}.path`;
426429
yield this.git.config(containerIncludeKey, containerCredentialsPath);
430+
// Configure container includeIf for worktrees
431+
const containerWorktreeIncludeKey = `includeIf.gitdir:${containerGitDir}/worktrees/*.path`;
432+
yield this.git.config(containerWorktreeIncludeKey, containerCredentialsPath);
427433
}
428434
});
429435
}

src/git-auth-helper.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,10 @@ class GitAuthHelper {
374374
const hostIncludeKey = `includeIf.gitdir:${gitDir}.path`
375375
await this.git.config(hostIncludeKey, credentialsConfigPath)
376376

377+
// Configure host includeIf for worktrees
378+
const hostWorktreeIncludeKey = `includeIf.gitdir:${gitDir}/worktrees/*.path`
379+
await this.git.config(hostWorktreeIncludeKey, credentialsConfigPath)
380+
377381
// Container git directory
378382
const workingDirectory = this.git.getWorkingDirectory()
379383
const githubWorkspace = process.env['GITHUB_WORKSPACE']
@@ -395,6 +399,13 @@ class GitAuthHelper {
395399
// Configure container includeIf
396400
const containerIncludeKey = `includeIf.gitdir:${containerGitDir}.path`
397401
await this.git.config(containerIncludeKey, containerCredentialsPath)
402+
403+
// Configure container includeIf for worktrees
404+
const containerWorktreeIncludeKey = `includeIf.gitdir:${containerGitDir}/worktrees/*.path`
405+
await this.git.config(
406+
containerWorktreeIncludeKey,
407+
containerCredentialsPath
408+
)
398409
}
399410
}
400411

0 commit comments

Comments
 (0)