Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPG no-tty helper script and options #1018

Merged
merged 1 commit into from
Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion GitSavvy.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,27 @@

/*
For each command specified, always include the command line flags
indicated in the global_flags hash.
indicated in the global_flags option AFTER the command.
*/
"global_flags": {
// --no-columns is not supported in Git versions <1.7.11. If Git is configured
// to use columns globally, --no-columns should be added here.
// "branch": ["--no-columns"]
//
// or, configure a GPG key to sign commits with a given key
// "commit": ["-S", "--gpg-sign=<key-id>"]
},

/*
For each command specified, always include the command line flags
indicated in the global_flags option BEFORE the command.
*/
"global_pre_flags": {
// for example, override settings via the "-c" option, e.g
// the following configures a gpg.program no-tty wrapper script
// "commit": ["-c", "gpg.program=./scripts/stgpg.sh"]
// and configure every commit to be signed with your key
// "commit": ["-c", "commit.gpgsign=true"]
},

/*
Expand Down
6 changes: 6 additions & 0 deletions core/git_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,15 @@ def _include_global_flags(self, args):
git_cmd, *addl_args = args

global_flags = self.savvy_settings.get("global_flags")
global_pre_flags = self.savvy_settings.get("global_pre_flags")

if global_flags and git_cmd in global_flags:
args = [git_cmd] + global_flags[git_cmd] + addl_args
else:
args = [git_cmd] + list(addl_args)

if global_pre_flags and git_cmd in global_pre_flags:
args = global_pre_flags[git_cmd] + args

return args

Expand Down
14 changes: 7 additions & 7 deletions docs/commit.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ GitHub has instructions on [how to add your GPG key to GitHub](https://help.gith

## Sign your commits automatically

If you always want to sign your commits you can configure git globally or in your project:
If you always want to sign your commits with a GPG key you can configure git globally, locally in your git repo or using the `global_pre_flags` setting.:

`git config (--global) commit.gpgsign true`

Now when you commit with GitSavvy, your commit will be automatically signed due to the git configuration.
When you commit with GitSavvy it will attempt to sign your commit. If your key hasn't been unlocked yet with your passphrase you will be asked for it (see more on credentials below).

## Unlock your GPG key
For more information, see [official git docs on the subject](https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work).

Next you want to tell git to ask for your passphrase through the gui. You can do this by setting the `askpass` variable:
## Providing credentials to git

`git config (--global) core.askpass git-gui--askpass`
GitSavvy does not support prompting a user for credentials (there is no way, known to us, to forward the password securely to git). In order to tell git to ask for your passphrase through the OS gui, you can set the `askPass` variable in your config, e.g:

I added my GPG to my keychain so it is unlocked when I log in as a user.
`git config (--global) core.askPass git-gui--askpass`

When you commit with GitSavvy it will attempt to sign your commit. If your key hasn't been unlocked yet with your passphrase you should now have a gui asking for it.
For more information, see [official git docs on the subject](https://git-scm.com/docs/gitcredentials).
4 changes: 4 additions & 0 deletions scripts/stgpg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
# kudos to SourceTree for providing us with this idea
# use --batch and --no-tty to avoid the terminal
gpg2 --batch --no-tty "$@"