Skip to content

Commit

Permalink
commit: add support for signed commits
Browse files Browse the repository at this point in the history
Add a `sign` flag to the Commit command.

Add a "Create Signed Commit" checkbox to the commit message editor so
that signed commits can be toggled on/off.

Default the checkbox to:

	git config --bool cola.signcommits

This allows us to enable this feature by default by setting:

	git config cola.signcommits true

Closes #149

Suggested-by: Justin Lecher <jlec@gentoo.org>
Cheered-on-by: Micha Rosenbaum <micha@rosetree.de>
Signed-off-by: David Aguilar <davvid@gmail.com>
  • Loading branch information
davvid committed Oct 4, 2014
1 parent 8d335a5 commit 7cb8d2a
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
7 changes: 5 additions & 2 deletions cola/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,11 @@ class Commit(ResetMode):

SHORTCUT = 'Ctrl+Return'

def __init__(self, amend, msg):
def __init__(self, amend, msg, sign):
ResetMode.__init__(self)
self.amend = amend
self.msg = msg
self.sign = sign
self.old_commitmsg = self.model.commitmsg
self.new_commitmsg = ''

Expand All @@ -358,7 +359,9 @@ def do(self):
core.write(tmpfile, msg)

# Run 'git commit'
status, out, err = self.model.git.commit(F=tmpfile, v=True,
status, out, err = self.model.git.commit(F=tmpfile,
v=True,
gpg_sign=self.sign,
amend=self.amend)
core.unlink(tmpfile)

Expand Down
10 changes: 9 additions & 1 deletion cola/widgets/commitmsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ def __init__(self, model, parent):
self.amend_action.setShortcut(cmds.AmendMode.SHORTCUT)
self.amend_action.setShortcutContext(Qt.ApplicationShortcut)

# Sign commits
cfg = gitcfg.current()
self.sign_action = self.actions_menu.addAction(
N_('Create Signed Commit'))
self.sign_action.setCheckable(True)
self.sign_action.setChecked(cfg.get('cola.signcommits', False))

# Spell checker
self.check_spelling_action = self.actions_menu.addAction(
N_('Check Spelling'))
Expand Down Expand Up @@ -430,7 +437,8 @@ def commit(self):
N_('Amend Commit'),
default=False, icon=save_icon())):
return
status, out, err = cmds.do(cmds.Commit, amend, msg)
sign = self.sign_action.isChecked()
status, out, err = cmds.do(cmds.Commit, amend, msg, sign)
if status != 0:
Interaction.critical(N_('Commit failed'),
N_('"git commit" returned exit code %s') %
Expand Down
63 changes: 63 additions & 0 deletions share/doc/git-cola/git-cola.rst
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,15 @@ into the commit message editor when this option is selected.

The `Status` tool will display all of the changes for the amended commit.

Create Signed Commit
--------------------
Tell `git commit` to use GPG to sign commits.
Using this option is equivalent to passing the ``-S`` option
to `git commit <http://git-scm.com/docs/git-commit>`_.

This option's default value can be configured using the `cola.signcommits`
configuration variable.

APPLY PATCHES
=============
Use the ``File -> Apply Patches`` menu item to begin applying patches.
Expand Down Expand Up @@ -408,6 +417,11 @@ cola.readsize
The maximum size to read is controlled by `cola.readsize`
and defaults to `2048`.

cola.signcommits
----------------
`git cola` will sign commits using `git commit -S` by default when set `true`.
See the section below on setting up GPG for more details.

gui.diffcontext
---------------
The number of diff context lines to display.
Expand Down Expand Up @@ -555,6 +569,55 @@ Specifies the general prompt string to display at the top of the dialog,
before subsections for argprompt and revprompt.
The default value includes the actual command.

SETTING UP GPG FOR SIGNED COMMITS
=================================
When creating signed commits `gpg` will attempt to read your password from the
terminal from which `git cola` was launched.
The way to make this work smoothly is to use a GPG agent so that you can avoid
needing to re-enter your password every time you commit.

This also gets you a graphical passphrase prompt instead of getting prompted
for your password in the terminal.

Install gpg-agent and friends
-----------------------------
On Mac OS X, you may need to `brew install gpg-agent` and install the
`Mac GPG Suite <https://gpgtools.org/macgpg2/>`_.

On Linux use your package manager to install gnupg-agent and pinentry-qt4, e.g.::

sudo apt-get install gnupg-agent pinentry-qt4

Configure gpg-agent and a pin-entry program
-------------------------------------------
Edit `~/.gnupg/gpg.conf` to include the line,::

use-agent

Edit `~/.gnupg/gpg-agent.conf` to contain a pinentry-program line pointing to
the pin-entry program for your platform.

The following example `gpg-agent.conf` shows how to use pinentry-qt4 on Linux::

pinentry-program /usr/bin/pinentry-qt4
default-cache-ttl 3600
enable-ssh-support
use-standard-socket

This following example `gpg-agent.conf` shows how to use MacGPG2's
pinentry app on On Mac OS X::

pinentry-program /usr/local/MacGPG2/libexec/pinentry-mac.app/Contents/MacOS/pinentry-mac
default-cache-ttl 3600
enable-ssh-support
use-standard-socket

Once this has been setup then you will need to eval the output
of `gpg-agent --daemon` in your shell prior to launching git-cola.::

eval $(gpg-agent --daemon)
bin/git-cola

LINKS
=====

Expand Down
1 change: 1 addition & 0 deletions share/doc/git-cola/thanks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Thanks
* Maarten Nieber
* Matěj Šmíd
* Matthew Levine
* Micha Rosenbaum
* Michael Geddes
* Michael Homer
* Minarto Margoliono
Expand Down

0 comments on commit 7cb8d2a

Please sign in to comment.