Skip to content

Commit 179f3db

Browse files
authored
Add Git configuration options for trace & debug (#1228)
Add options for enabling tracing and debugging in Git configuration. Today the below options were only supported via environment variable: - `GCM_TRACE` - `GCM_TRACE_SECRETS` - `GCM_TRACE_MSAUTH` - `GCM_DEBUG`
2 parents d6a4cf3 + 50837bf commit 179f3db

File tree

4 files changed

+120
-12
lines changed

4 files changed

+120
-12
lines changed

docs/configuration.md

+84
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,86 @@ Defaults to enabled.
7676

7777
---
7878

79+
### credential.trace
80+
81+
Enables trace logging of all activities.
82+
Configuring Git and GCM to trace to the same location is often desirable, and
83+
GCM is compatible and cooperative with `GIT_TRACE`.
84+
85+
#### Example
86+
87+
```shell
88+
git config --global credential.trace /tmp/git.log
89+
```
90+
91+
If the value of `credential.trace` is a full path to a file in an existing
92+
directory, logs are appended to the file.
93+
94+
If the value of `credential.trace` is `true` or `1`, logs are written to
95+
standard error.
96+
97+
Defaults to disabled.
98+
99+
**Also see: [GCM_TRACE][gcm-trace]**
100+
101+
---
102+
103+
### credential.traceSecrets
104+
105+
Enables tracing of secret and sensitive information, which is by default masked
106+
in trace output. Requires that `credential.trace` is also enabled.
107+
108+
#### Example
109+
110+
```shell
111+
git config --global credential.traceSecrets true
112+
```
113+
114+
If the value of `credential.traceSecrets` is `true` or `1`, trace logs will include
115+
secret information.
116+
117+
Defaults to disabled.
118+
119+
**Also see: [GCM_TRACE_SECRETS][gcm-trace-secrets]**
120+
121+
---
122+
123+
### credential.traceMsAuth
124+
125+
Enables inclusion of Microsoft Authentication library (MSAL) logs in GCM trace
126+
output. Requires that `credential.trace` is also enabled.
127+
128+
#### Example
129+
130+
```shell
131+
git config --global credential.traceMsAuth true
132+
```
133+
134+
If the value of `credential.traceMsAuth` is `true` or `1`, trace logs will
135+
include verbose MSAL logs.
136+
137+
Defaults to disabled.
138+
139+
**Also see: [GCM_TRACE_MSAUTH][gcm-trace-msauth]**
140+
141+
---
142+
143+
### credential.debug
144+
145+
Pauses execution of GCM at launch to wait for a debugger to be attached.
146+
147+
#### Example
148+
149+
```shell
150+
git config --global credential.debug true
151+
```
152+
153+
Defaults to disabled.
154+
155+
**Also see: [GCM_DEBUG][gcm-debug]**
156+
157+
---
158+
79159
### credential.provider
80160

81161
Define the host provider to use when authenticating.
@@ -682,6 +762,7 @@ git config --global credential.azreposCredentialType oauth
682762
[gcm-bitbucket-authmodes]: environment.md#GCM_BITBUCKET_AUTHMODES
683763
[gcm-credential-cache-options]: environment.md#GCM_CREDENTIAL_CACHE_OPTIONS
684764
[gcm-credential-store]: environment.md#GCM_CREDENTIAL_STORE
765+
[gcm-debug]: environment.md#GCM_DEBUG
685766
[gcm-dpapi-store-path]: environment.md#GCM_DPAPI_STORE_PATH
686767
[gcm-github-authmodes]: environment.md#GCM_GITHUB_AUTHMODES
687768
[gcm-gitlab-authmodes]:environment.md#GCM_GITLAB_AUTHMODES
@@ -693,6 +774,9 @@ git config --global credential.azreposCredentialType oauth
693774
[gcm-namespace]: environment.md#GCM_NAMESPACE
694775
[gcm-plaintext-store-path]: environment.md#GCM_PLAINTEXT_STORE_PATH
695776
[gcm-provider]: environment.md#GCM_PROVIDER
777+
[gcm-trace]: environment.md#GCM_TRACE
778+
[gcm-trace-secrets]: environment.md#GCM_TRACE_SECRETS
779+
[gcm-trace-msauth]: environment.md#GCM_TRACE_MSAUTH
696780
[usage]: usage.md
697781
[git-config-http-proxy]: https://git-scm.com/docs/git-config#Documentation/git-config.txt-httpproxy
698782
[http-proxy]: netconfig.md#http-proxy

docs/environment.md

+12-8
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ logs are appended to the file.
3939

4040
If the value of `GCM_TRACE` is `true` or `1`, logs are written to standard error.
4141

42-
Defaults to tracing disabled.
42+
Defaults to disabled.
4343

44-
_No configuration equivalent._
44+
**Also see: [credential.trace][credential-trace]**
4545

4646
---
4747

@@ -71,14 +71,14 @@ secret information.
7171

7272
Defaults to disabled.
7373

74-
_No configuration equivalent._
74+
**Also see: [credential.traceSecrets][credential-trace-secrets]**
7575

7676
---
7777

7878
### GCM_TRACE_MSAUTH
7979

80-
Enables inclusion of Microsoft Authentication libraries (ADAL, MSAL) logs in GCM
81-
trace output. Requires that `GCM_TRACE` is also enabled.
80+
Enables inclusion of Microsoft Authentication library (MSAL) logs in GCM trace
81+
output. Requires that `GCM_TRACE` is also enabled.
8282

8383
#### Example
8484

@@ -97,11 +97,11 @@ export GCM_TRACE_MSAUTH=1
9797
```
9898

9999
If the value of `GCM_TRACE_MSAUTH` is `true` or `1`, trace logs will include
100-
verbose ADAL/MSAL logs.
100+
verbose MSAL logs.
101101

102102
Defaults to disabled.
103103

104-
_No configuration equivalent._
104+
**Also see: [credential.traceMsAuth][credential-trace-msauth]**
105105

106106
---
107107

@@ -125,7 +125,7 @@ export GCM_DEBUG=1
125125

126126
Defaults to disabled.
127127

128-
_No configuration equivalent._
128+
**Also see: [credential.debug][credential-debug]**
129129

130130
---
131131

@@ -840,6 +840,7 @@ export GCM_AZREPOS_CREDENTIALTYPE="oauth"
840840
[credential-bitbucketauthmodes]: configuration.md#credentialbitbucketAuthModes
841841
[credential-cacheoptions]: configuration.md#credentialcacheoptions
842842
[credential-credentialstore]: configuration.md#credentialcredentialstore
843+
[credential-debug]: configuration.md#credentialdebug
843844
[credential-dpapi-store-path]: configuration.md#credentialdpapistorepath
844845
[credential-githubauthmodes]: configuration.md#credentialgitHubAuthModes
845846
[credential-gitlabauthmodes]: configuration.md#credentialgitLabAuthModes
@@ -852,6 +853,9 @@ export GCM_AZREPOS_CREDENTIALTYPE="oauth"
852853
[credential-plain-text-store]: configuration.md#credentialplaintextstorepath
853854
[credential-provider]: configuration.md#credentialprovider
854855
[credential-stores]: credstores.md
856+
[credential-trace]: configuration.md#credentialtrace
857+
[credential-trace-secrets]: configuration.md#credentialtracesecrets
858+
[credential-trace-msauth]: configuration.md#credentialtracemsauth
855859
[default-values]: enterprise-config.md
856860
[freedesktop-ss]: https://specifications.freedesktop.org/secret-service/
857861
[gcm]: usage.md

src/shared/Core/Constants.cs

+4
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ public static class Credential
122122
{
123123
public const string SectionName = "credential";
124124
public const string Helper = "helper";
125+
public const string Trace = "trace";
126+
public const string TraceSecrets = "traceSecrets";
127+
public const string TraceMsAuth = "traceMsAuth";
128+
public const string Debug = "debug";
125129
public const string Provider = "provider";
126130
public const string Authority = "authority";
127131
public const string AllowWia = "allowWindowsAuth";

src/shared/Core/Settings.cs

+20-4
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,11 @@ protected virtual bool TryGetExternalDefault(string section, string scope, strin
475475

476476
public Uri RemoteUri { get; set; }
477477

478-
public bool IsDebuggingEnabled => _environment.Variables.GetBooleanyOrDefault(KnownEnvars.GcmDebug, false);
478+
public bool IsDebuggingEnabled =>
479+
TryGetSetting(KnownEnvars.GcmDebug,
480+
KnownGitCfg.Credential.SectionName,
481+
KnownGitCfg.Credential.Debug,
482+
out string str) && str.IsTruthy();
479483

480484
public bool IsTerminalPromptsEnabled => _environment.Variables.GetBooleanyOrDefault(KnownEnvars.GitTerminalPrompts, true);
481485

@@ -536,7 +540,11 @@ public bool IsInteractionAllowed
536540
}
537541
}
538542

539-
public bool GetTracingEnabled(out string value) => _environment.Variables.TryGetValue(KnownEnvars.GcmTrace, out value) && !value.IsFalsey();
543+
public bool GetTracingEnabled(out string value) =>
544+
TryGetSetting(KnownEnvars.GcmTrace,
545+
KnownGitCfg.Credential.SectionName,
546+
KnownGitCfg.Credential.Trace,
547+
out value) && !value.IsFalsey();
540548

541549
public Trace2Settings GetTrace2Settings()
542550
{
@@ -563,9 +571,17 @@ public Trace2Settings GetTrace2Settings()
563571
return settings;
564572
}
565573

566-
public bool IsSecretTracingEnabled => _environment.Variables.GetBooleanyOrDefault(KnownEnvars.GcmTraceSecrets, false);
574+
public bool IsSecretTracingEnabled =>
575+
TryGetSetting(KnownEnvars.GcmTraceSecrets,
576+
KnownGitCfg.Credential.SectionName,
577+
KnownGitCfg.Credential.TraceSecrets,
578+
out string str) && str.IsTruthy();
567579

568-
public bool IsMsalTracingEnabled => _environment.Variables.GetBooleanyOrDefault(Constants.EnvironmentVariables.GcmTraceMsAuth, false);
580+
public bool IsMsalTracingEnabled =>
581+
TryGetSetting(KnownEnvars.GcmTraceMsAuth,
582+
KnownGitCfg.Credential.SectionName,
583+
KnownGitCfg.Credential.TraceMsAuth,
584+
out string str) && str.IsTruthy();
569585

570586
public string ProviderOverride =>
571587
TryGetSetting(KnownEnvars.GcmProvider, GitCredCfg.SectionName, GitCredCfg.Provider, out string providerId) ? providerId : null;

0 commit comments

Comments
 (0)