Skip to content

Commit

Permalink
Do not query local bindings if outside repo in Azure Repos (#1561)
Browse files Browse the repository at this point in the history
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.

cc @markphip
  • Loading branch information
mjcheetham authored Mar 26, 2024
2 parents d6432f9 + b28e11a commit 5f9bede
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/shared/Microsoft.AzureRepos/AzureReposBindingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 5f9bede

Please sign in to comment.