Skip to content

Instantly share code, notes, and snippets.

@apankov
Created December 22, 2014 20:44
Show Gist options
  • Save apankov/11b09be69d3691cfcc2f to your computer and use it in GitHub Desktop.
Save apankov/11b09be69d3691cfcc2f to your computer and use it in GitHub Desktop.
gpg-encrypted files merge tool for mercurial
#!/bin/bash
# Merge tool for Mercurial
# It allows to merge binary GPG-encrypted files. After decryption files are compared with vimdiff
# [merge-tools]
# gpg-merge.executable = ~/bin/gpg-merge
# gpg-merge.priority = 100
# gpg-merge.premerge = False
# gpg-merge.args = $local $other $base $output --recipient foo@example.com
#
# [merge-patterns]
# **.gpg = gpg-merge
local_file=$1
shift
other_file=$1
shift
base_file=$1
shift
output_file=$1
shift
while test $# -gt 0
do
case $1 in
--recipient)
rec=$2
shift
recipients="$recipients --recipient $rec"
;;
*)
echo >&2 "Invalid argument: $1"
;;
esac
shift
done
tmp_local=`mktemp --dry-run`
tmp_other=`mktemp --dry-run`
tmp_base=`mktemp --dry-run`
gpg --decrypt $local_file > $tmp_local
gpg --decrypt $other_file > $tmp_other
gpg --decrypt $base_file > $tmp_base
vimdiff $tmp_local $tmp_other $tmp_base
cmd="gpg $recipients --output $output_file --yes --encrypt $tmp_local"
$($cmd)
rm -f $tmp_local
rm -f $tmp_other
rm -f $tmp_base
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment