Use git config --show-origin to reliably get submodule config paths

This commit is contained in:
eric sciple
2025-10-14 22:24:46 +00:00
parent 8e4be9ae12
commit a60fb6cabe
2 changed files with 23 additions and 13 deletions

View File

@ -190,16 +190,22 @@ class GitAuthHelper {
relativePath
)
// Get submodule paths.
// `git rev-parse --show-toplevel` returns the absolute path of each submodule's working tree.
const submodulePaths = await this.git.submoduleForeach(
`git rev-parse --show-toplevel`,
// Get submodule config file paths.
// Use `--show-origin` to get the config file path for each submodule.
const output = await this.git.submoduleForeach(
`git config --local --show-origin --name-only --get-regexp remote.origin.url`,
this.settings.nestedSubmodules
)
// Extract config file paths from the output (lines starting with "file:").
const configPaths =
output.match(/(?<=(^|\n)file:)[^\t]+(?=\tremote\.origin\.url)/g) || []
// For each submodule, configure includeIf entries pointing to the shared credentials file.
// Configure both host and container paths to support Docker container actions.
for (const submodulePath of submodulePaths.split('\n').filter(x => x)) {
for (const configPath of configPaths) {
// Get the submodule path from its config file path.
const submodulePath = path.dirname(path.dirname(configPath))
// Configure host path includeIf.
// Use forward slashes for git config, even on Windows.
let submoduleGitDir = path.join(submodulePath, '.git')
@ -209,7 +215,7 @@ class GitAuthHelper {
credentialsConfigPath,
false,
false,
path.join(submodulePath, '.git', 'config')
configPath
)
// Configure container path includeIf.
@ -229,7 +235,7 @@ class GitAuthHelper {
containerCredentialsPath,
false,
false,
path.join(submodulePath, '.git', 'config')
configPath
)
}