Skip to content

Commit

Permalink
PO merge driver
Browse files Browse the repository at this point in the history
  • Loading branch information
Al Nikolov committed Jul 5, 2012
1 parent 6a643df commit c82bdb4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.po merge=pofile
*.pot merge=pofile

41 changes: 41 additions & 0 deletions helpers/git-merge-po.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/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

0 comments on commit c82bdb4

Please sign in to comment.