mirror of
				https://github.com/actions/checkout.git
				synced 2025-10-31 05:25:55 +08:00 
			
		
		
		
	Use git config --show-origin to reliably get submodule config paths
This commit is contained in:
		
							
								
								
									
										16
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										16
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							| @@ -280,23 +280,27 @@ class GitAuthHelper { | ||||
|                 let relativePath = path.relative(githubWorkspace, workingDirectory); | ||||
|                 relativePath = relativePath.replace(/\\/g, '/'); | ||||
|                 const containerWorkspaceBase = path.posix.join('/github/workspace', relativePath); | ||||
|                 // Get submodule paths.
 | ||||
|                 // `git rev-parse --show-toplevel` returns the absolute path of each submodule's working tree.
 | ||||
|                 const submodulePaths = yield this.git.submoduleForeach(`git rev-parse --show-toplevel`, this.settings.nestedSubmodules); | ||||
|                 // Get submodule config file paths.
 | ||||
|                 // Use `--show-origin` to get the config file path for each submodule.
 | ||||
|                 const output = yield 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'); | ||||
|                     submoduleGitDir = submoduleGitDir.replace(/\\/g, '/'); | ||||
|                     yield this.git.config(`includeIf.gitdir:${submoduleGitDir}.path`, credentialsConfigPath, false, false, path.join(submodulePath, '.git', 'config')); | ||||
|                     yield this.git.config(`includeIf.gitdir:${submoduleGitDir}.path`, credentialsConfigPath, false, false, configPath); | ||||
|                     // Configure container path includeIf.
 | ||||
|                     // Use forward slashes for git config, even on Windows.
 | ||||
|                     let submoduleRelativePath = path.relative(workingDirectory, submodulePath); | ||||
|                     submoduleRelativePath = submoduleRelativePath.replace(/\\/g, '/'); | ||||
|                     const containerSubmoduleGitDir = path.posix.join(containerWorkspaceBase, submoduleRelativePath, '.git'); | ||||
|                     yield this.git.config(`includeIf.gitdir:${containerSubmoduleGitDir}.path`, containerCredentialsPath, false, false, path.join(submodulePath, '.git', 'config')); | ||||
|                     yield this.git.config(`includeIf.gitdir:${containerSubmoduleGitDir}.path`, containerCredentialsPath, false, false, configPath); | ||||
|                 } | ||||
|                 if (this.settings.sshKey) { | ||||
|                     // Configure core.sshCommand
 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user