Skip to content

Commit

Permalink
GH#354 Disabled auth submodules config when related setting is false
Browse files Browse the repository at this point in the history
This should help with actions#354.
The problem is that I have no idea whether such auth submodules configuration
is required even when settings.submodules is false.
  • Loading branch information
cosimo authored and kaidokert committed May 15, 2023
1 parent f095bcc commit 55709ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions __test__/git-auth-helper.test.ts
Expand Up @@ -482,6 +482,7 @@ describe('git-auth-helper tests', () => {
)
settings.persistCredentials = false
settings.sshKey = ''
settings.submodules = true
const authHelper = gitAuthHelper.createAuthHelper(git, settings)
await authHelper.configureAuth()
const mockSubmoduleForeach = git.submoduleForeach as jest.Mock<any, any>
Expand Down Expand Up @@ -515,6 +516,7 @@ describe('git-auth-helper tests', () => {
configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsFalseAndSshKeySet
)
settings.persistCredentials = false
settings.submodules = true
const authHelper = gitAuthHelper.createAuthHelper(git, settings)
await authHelper.configureAuth()
const mockSubmoduleForeach = git.submoduleForeach as jest.Mock<any, any>
Expand All @@ -541,6 +543,7 @@ describe('git-auth-helper tests', () => {
configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsTrueAndSshKeyNotSet
)
settings.sshKey = ''
settings.submodules = true
const authHelper = gitAuthHelper.createAuthHelper(git, settings)
await authHelper.configureAuth()
const mockSubmoduleForeach = git.submoduleForeach as jest.Mock<any, any>
Expand Down Expand Up @@ -580,6 +583,7 @@ describe('git-auth-helper tests', () => {
await setup(
configureSubmoduleAuth_configuresSubmodulesWhenPersistCredentialsTrueAndSshKeySet
)
settings.submodules = true
const authHelper = gitAuthHelper.createAuthHelper(git, settings)
await authHelper.configureAuth()
const mockSubmoduleForeach = git.submoduleForeach as jest.Mock<any, any>
Expand Down
14 changes: 8 additions & 6 deletions src/git-auth-helper.ts
Expand Up @@ -364,11 +364,13 @@ class GitAuthHelper {
}
}

const pattern = regexpHelper.escape(configKey)
await this.git.submoduleForeach(
// wrap the pipeline in quotes to make sure it's handled properly by submoduleForeach, rather than just the first part of the pipeline
`sh -c "git config --local --name-only --get-regexp '${pattern}' && git config --local --unset-all '${configKey}' || :"`,
true
)
if (this.settings.submodules) {
const pattern = regexpHelper.escape(configKey)
await this.git.submoduleForeach(
// wrap the pipeline in quotes to make sure it's handled properly by submoduleForeach, rather than just the first part of the pipeline
`sh -c "git config --local --name-only --get-regexp '${pattern}' && git config --local --unset-all '${configKey}' || :"`,
true
)
}
}
}

0 comments on commit 55709ff

Please sign in to comment.