Skip to content

Commit 4e8e593

Browse files
author
Matthew John Cheetham
authored
Make GPG Pass store path configurable by git config (#1698)
I found this change beneficial when using conditional git configuration includes for multiple git identities and `pass` password stores. It lets me transparently select appropriate password store without need to set its path explicitly by environment variable. For example: > ~/.config/git/config: ``` [user] name = John Doe email = [email protected] [credential] credentialStore = gpg helper = /usr/local/bin/git-credential-manager gpgPassStorePath = /home/jdoe/.password-store [includeIf "gitdir:~/Work/"] path = config.work ``` > ~/.config/git/config.work: ``` [user] name = John Doe (Umbrella Corp.) email = [email protected] [credential] gpgPassStorePath = /home/jdoe/.password-store.umbrella ```
2 parents 415adfe + 0b3d846 commit 4e8e593

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

docs/configuration.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,24 @@ git config --global credential.dpapiStorePath D:\credentials
633633

634634
---
635635

636+
### credential.gpgPassStorePath
637+
638+
Specify a custom directory to store GPG-encrypted [pass][pass]-compatible credential files
639+
in when [`credential.credentialStore`][credential-credentialstore] is set to `gpg`.
640+
641+
Defaults to the value `~/.password-store` or `%USERPROFILE%\.password-store`.
642+
643+
#### Example
644+
645+
```shell
646+
git config --global credential.gpgPassStorePath /mnt/external-drive/.password-store
647+
```
648+
649+
**Note:** Location of the password store used by [pass][pass] can be overridden by the
650+
`PASSWORD_STORE_DIR` environment variable, see the [man page][pass-man] for details.
651+
652+
---
653+
636654
### credential.msauthFlow
637655

638656
Specify which authentication flow should be used when performing Microsoft
@@ -1042,6 +1060,7 @@ Defaults to disabled.
10421060
[provider-migrate]: migration.md#gcm_authority
10431061
[cache-options]: https://git-scm.com/docs/git-credential-cache#_options
10441062
[pass]: https://www.passwordstore.org/
1063+
[pass-man]: https://git.zx2c4.com/password-store/about/
10451064
[trace2-normal-docs]: https://git-scm.com/docs/api-trace2#_the_normal_format_target
10461065
[trace2-normal-env]: environment.md#GIT_TRACE2
10471066
[trace2-event-docs]: https://git-scm.com/docs/api-trace2#_the_event_format_target

src/shared/Core/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public static class Credential
162162
public const string DevUseLegacyUiHelpers = "devUseLegacyUiHelpers";
163163
public const string MsAuthUseDefaultAccount = "msauthUseDefaultAccount";
164164
public const string GuiSoftwareRendering = "guiSoftwareRendering";
165+
public const string GpgPassStorePath = "gpgPassStorePath";
165166

166167
public const string OAuthAuthenticationModes = "oauthAuthModes";
167168
public const string OAuthClientId = "oauthClientId";

src/shared/Core/CredentialStore.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ private void ValidateGpgPass(out string storeRoot, out string execPath)
276276
// Check for a redirected pass store location
277277
if (!_context.Settings.TryGetSetting(
278278
GpgPassCredentialStore.PasswordStoreDirEnvar,
279-
null, null,
279+
Constants.GitConfiguration.Credential.SectionName,
280+
Constants.GitConfiguration.Credential.GpgPassStorePath,
280281
out storeRoot))
281282
{
282283
// Use default store root at ~/.password-store

0 commit comments

Comments
 (0)