Skip to content

Instantly share code, notes, and snippets.

@justhamade
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justhamade/e4d9bcae90b3c2b26aa0 to your computer and use it in GitHub Desktop.
Save justhamade/e4d9bcae90b3c2b26aa0 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Custom Git merge driver - merges PO files using msgcat(1)
#
# - Install gettext
#
# - Place this script in your PATH
#
# - Add this to your .git/config :
#
# [merge "pofile"]
# name = Gettext merge driver
# driver = git merge-po %O %A %B
#
# - Add this to .gitattributes :
#
# *.po merge=pofile
# *.pot merge=pofile
#
# - When merging branches, conflicts in PO files will be maked with "#-#-#-#"
#
O=$1
A=$2
B=$3
# Extract the PO header from the current branch (top of file until first empty line)
header=$(mktemp /tmp/merge-po.XXXX)
sed -e '/^$/q' < $A > $header
# Merge files, then repair header
temp=$(mktemp /tmp/merge-po.XXXX)
msgcat -o $temp $A $B
msgcat --use-first -o $A $header $temp
# Clean up
rm $header $temp
# Check for conflicts
conflicts=$(grep -c "#-#" $A)
test $conflicts -gt 0 && exit 1
exit 0
#!/bin/bash
# run curl https://gist.githubusercontent.com/justhamade/e4d9bcae90b3c2b26aa0/raw/git_po_config | sh
cat << EOF >> .git/config
[merge "pofile"]
name = Gettext merge driver
driver = git merge-po %O %A %Be
[diff "pofile"]
textconv = msgcat --no-location --no-wrap --sort-output
EOF
cat << EOR >> .gitattributes
*.po diff=pofile
*.po merge=pofile
EOF
wget https://gist.githubusercontent.com/justhamade/e4d9bcae90b3c2b26aa0/raw/git-merge-po.sh -O /usr/local/bin/git-merge-po.sh
chmod 755 /usr/local/bin/git-merge-po.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment