From b28e11a084a49be4bb570d5a64af826532fb05fa Mon Sep 17 00:00:00 2001 From: Matthew John Cheetham Date: Tue, 26 Mar 2024 14:07:02 -0700 Subject: [PATCH] azrepos: do not query local bindings if outside repo Do not attempt to query for an organisation/user binding in the local repository configuration if we're not currently inside of a repository! This will prevent the warning message from Git's standard error stream from flowing to our caller's stderr stream when GCM tries to use the `--local` option in a `git config` call. --- .../AzureReposBindingManager.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/shared/Microsoft.AzureRepos/AzureReposBindingManager.cs b/src/shared/Microsoft.AzureRepos/AzureReposBindingManager.cs index db2670edf..7e26590bd 100644 --- a/src/shared/Microsoft.AzureRepos/AzureReposBindingManager.cs +++ b/src/shared/Microsoft.AzureRepos/AzureReposBindingManager.cs @@ -93,11 +93,15 @@ public AzureReposBinding GetBinding(string orgName) _trace.WriteLine($"Looking up organization binding for '{orgName}'..."); - // NOT using the short-circuiting OR operator here on purpose - we need both branches to be evaluated - if (config.TryGet(GitConfigurationLevel.Local, GitConfigurationType.Raw, - orgKey, out string localUser) | - config.TryGet(GitConfigurationLevel.Global, GitConfigurationType.Raw, - orgKey, out string globalUser)) + string localUser = null; + bool hasLocal = _git.IsInsideRepository() && // Can only check local config if we are inside a repository + config.TryGet(GitConfigurationLevel.Local, GitConfigurationType.Raw, + orgKey, out localUser); + + bool hasGlobal = config.TryGet(GitConfigurationLevel.Global, GitConfigurationType.Raw, + orgKey, out string globalUser); + + if (hasLocal || hasGlobal) { return new AzureReposBinding(orgName, globalUser, localUser); }