From 55709ffa1b583635bb12f40852e2a512c446172b Mon Sep 17 00:00:00 2001 From: Cosimo Streppone Date: Wed, 13 Jan 2021 09:42:33 +0100 Subject: [PATCH] GH#354 Disabled auth submodules config when related setting is false This should help with https://github.com/actions/checkout/issues/354. The problem is that I have no idea whether such auth submodules configuration is required even when settings.submodules is false. --- __test__/git-auth-helper.test.ts | 4 ++++ src/git-auth-helper.ts | 14 ++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/__test__/git-auth-helper.test.ts b/__test__/git-auth-helper.test.ts index b58010b7c..2aa6b168a 100644 --- a/__test__/git-auth-helper.test.ts +++ b/__test__/git-auth-helper.test.ts @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/git-auth-helper.ts b/src/git-auth-helper.ts index 364a04ee8..9aa1cb6d8 100644 --- a/src/git-auth-helper.ts +++ b/src/git-auth-helper.ts @@ -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 + ) + } } }