mirror of
https://github.com/actions/checkout.git
synced 2025-10-17 00:25:08 +07:00
Use git config --show-origin to reliably get submodule config paths
This commit is contained in:
@ -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
|
||||
)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user