├── .gitignore ├── .jshintrc ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── index.js ├── merge.sh ├── package.json └── test ├── catches conflicts and fails ├── base.po ├── expected.po ├── ours.po └── theirs.po ├── merges a single addition ├── base.po ├── expected.po ├── ours.po └── theirs.po ├── merges pos of different widths ├── base.po ├── expected.po ├── ours.po └── theirs.po ├── strips long headers ├── base.po ├── expected.po ├── ours.po └── theirs.po └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | node_modules/jsgreat/.jshintrc -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: node_js 4 | 5 | node_js: 6 | - 'iojs' 7 | - '0.12' 8 | 9 | script: 10 | - npm test 11 | 12 | notifications: 13 | email: false 14 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # git-po-merge changelog 2 | 3 | ## 0.1.0 4 | 5 | * Keep language and plural form headers, fixes ([#2][2]) 6 | 7 | [2]: https://github.com/beck/git-po-merge/issues/2 8 | 9 | 10 | ## 0.0.1 11 | 12 | * Initial Release ([#1][1]) 13 | 14 | [1]: https://github.com/beck/git-po-merge/pull/1 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Douglas Beck 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # git-po-merge 2 | [![Build Status](https://travis-ci.org/beck/git-po-merge.svg?branch=master)](https://travis-ci.org/beck/git-po-merge) 3 | [![npm version](https://badge.fury.io/js/git-po-merge.svg)](http://badge.fury.io/js/git-po-merge) 4 | 5 | A git merge driver for repos with translations and i18n, the driver helps 6 | resolve .po file conflicts when merging or rebasing gettext catalogs. 7 | 8 | 9 | ## Install 10 | 11 | Git-po-merge requires `msgcat`, a tool included when installing `gettext`. 12 | 13 | Try: 14 | ``` 15 | msgcat --version 16 | ``` 17 | 18 | If missing and using OSX, gettext is available via homebrew: 19 | ``` 20 | brew install gettext 21 | brew link gettext --force 22 | ``` 23 | 24 | ### Install and update git config 25 | 26 | This can be done one of two ways, globally or per-project/directory: 27 | 28 | #### Globally 29 | 30 | Install: 31 | ```sh 32 | npm install --global git-po-merge 33 | ``` 34 | 35 | Add to `~/.gitconfig`: 36 | ```ini 37 | [core] 38 | attributesfile = ~/.gitattributes 39 | [merge "pofile"] 40 | name = custom merge driver for gettext po files 41 | driver = git-po-merge %A %O %B 42 | ``` 43 | 44 | Create `~/.gitattributes`: 45 | ```ini 46 | *.po merge=pofile 47 | *.pot merge=pofile 48 | ``` 49 | 50 | #### Single project / directory 51 | 52 | Install: 53 | ```sh 54 | npm install git-po-merge --save-dev 55 | ``` 56 | 57 | Update git config: 58 | ```sh 59 | git config merge.pofile.driver "$(npm bin)/git-po-merge %A %O %B" 60 | git config merge.pofile.name "custom merge driver for gettext po files" 61 | ``` 62 | 63 | Add the same `.gitattributes` where desired and commit. 64 | Note `.gitattributes` is only used after committed. 65 | 66 | 67 | ### Verify install 68 | 69 | ``` 70 | git-po-merge # or $(npm bin)/git-po-merge 71 | > usage: git-po-merge [-s] our.po base.po their.po 72 | 73 | touch messages.po 74 | git check-attr -a messages.po 75 | > messages.po: merge: pofile 76 | 77 | git-po-merge messages.po messages.po messages.po 78 | > Resolving po conflict with git-merge-po... done. 79 | 80 | git merge [some branch with translation changes that conflict] 81 | > Resolving po conflict with git-merge-po... done. 82 | > Resolving po conflict with git-merge-po... done. 83 | > Auto-merging project/locale/fr/LC_MESSAGES/messages.po 84 | > Auto-merging project/locale/es/LC_MESSAGES/messages.po 85 | ``` 86 | 87 | 88 | ## Notes and caveats 89 | 90 | Git only calls the driver in the event of a conflict and will always 91 | attempt a traditional 3-way merge first. 92 | 93 | The git-merge-po driver will restore messages marked obsolete if the message 94 | is active in any po being merged. Good practice is to remake messages after 95 | any merge or rebase. 96 | 97 | 98 | ## Dev 99 | 100 | ``` 101 | node --version # using v0.12 102 | npm install --global . 103 | npm link 104 | npm test 105 | ``` 106 | 107 | Helpful docs: 108 | * http://git-scm.com/docs/gitattributes#_defining_a_custom_merge_driver 109 | * http://stackoverflow.com/questions/28026767/where-should-i-place-my-global-gitattributes-file 110 | 111 | Thanks: 112 | * https://gist.github.com/mezis/1605647 113 | * http://stackoverflow.com/questions/16214067/wheres-the-3-way-git-merge-driver-for-po-gettext-files 114 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var cp = require('child_process'); 4 | var path = require('path'); 5 | 6 | module.exports = function(ours, base, theirs, options) { 7 | options = options || {'silent': false}; 8 | var args = [ours, base, theirs]; 9 | options.silent && args.unshift('-s'); 10 | var cpOpts = {stdio: [0, process.stdout, process.stderr]}; 11 | cp.execFileSync(path.join(__dirname, 'merge.sh'), args, cpOpts); 12 | }; 13 | -------------------------------------------------------------------------------- /merge.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # A git merge driver for repos with translations and i18n, the driver helps 3 | # resolve .po file conflicts when merging or rebasing gettext catalogs. 4 | # https://github.com/beck/git-po-merge 5 | set -eu 6 | 7 | # if additional options are ever added will need to use getopts 8 | silent=false 9 | if [ ${1:-loud} = '-s' ] 10 | then 11 | silent=true 12 | shift 13 | fi 14 | 15 | if [ $# -ne 3 ] 16 | then 17 | echo "usage: git-po-merge [-s] our.po base.po their.po" 18 | exit 1 19 | fi 20 | 21 | ours=$1 22 | base=$2 23 | theirs=$3 24 | 25 | 26 | function log { 27 | if [ $silent = false ] 28 | then 29 | echo "$@" 30 | fi 31 | } 32 | 33 | function elog { 34 | log "$@" >&2 35 | } 36 | 37 | function verify_msgcat { 38 | if ! $(msgcat --version > /dev/null 2>&1) 39 | then 40 | elog 41 | elog "ERROR in git-po-merge: msgcat is not found." 42 | elog " Installing gettext should include msgcat." 43 | elog " Falling back to three way merge." 44 | elog 45 | git merge-file -L "ours" -L "base" -L "theirs" "$ours" "$base" "$theirs" 46 | exit 1 47 | fi 48 | } 49 | 50 | function get_langheader { 51 | grep -m 1 -e '^\"Language:\s.*\\n\"$' "$ours" 52 | } 53 | 54 | function get_pluralheader { 55 | grep -m 1 -e '^\"Plural-Forms:\s.*\\n\"$' "$ours" 56 | } 57 | 58 | function resolvepo { 59 | log -n "Resolving po conflict with git-merge-po... " 60 | local merge_opts="--sort-output --no-location --width=80" 61 | local headerpo=$(mktemp -t headers.XXXXXX.po) 62 | local temp=$(mktemp -t temp.XXXXXX.po) 63 | 64 | # fix gettext nonsense and noise from 3rd party tools 65 | local noise="-e /^#.Generated.by.grunt.*/d" 66 | noise="$noise -e s/charset=CHARSET/charset=UTF-8/" 67 | cp "$ours" "$temp" && sed $noise "$temp" > "$ours" 68 | cp "$base" "$temp" && sed $noise "$temp" > "$base" 69 | cp "$theirs" "$temp" && sed $noise "$temp" > "$theirs" 70 | 71 | # reduce all three to a single file 72 | msgcat "$base" "$ours" "$theirs" $merge_opts --output-file="$temp" 73 | 74 | # set a minimalist header 75 | echo 'msgid ""' >> "$headerpo" 76 | echo 'msgstr ""' >> "$headerpo" 77 | echo '"Content-Type: text/plain; charset=UTF-8\n"' >> "$headerpo" 78 | echo '"MIME-Version: 1.0\n"' >> "$headerpo" 79 | echo "$(get_langheader)" >> "$headerpo" 80 | echo "$(get_pluralheader)" >> "$headerpo" 81 | 82 | msgcat "$headerpo" "$temp" --use-first $merge_opts --output-file="$ours" 83 | 84 | # cleanup 85 | rm -rf "$temp" "$headerpo" 86 | } 87 | 88 | 89 | function rename_conflict_titles { 90 | # replace tempfile names with "ours", "theirs", "base" 91 | # msgcat shows confilcts using delimiter comments like: 92 | # #-#-#-#-# .merge_file_IE83XW #-#-#-#-# 93 | local temp=$(mktemp -t temp.XXXXXX.po) 94 | sed -e "s|$ours|ours|" -e "s|$theirs|theirs|" -e "s|$base|base|" "$ours" > "$temp" 95 | mv "$temp" "$ours" 96 | } 97 | 98 | 99 | function check_for_conflicts { 100 | # check if msgcat conflict comments are present 101 | if $(grep --silent "#-#-#-#-#" "$ours") 102 | then 103 | elog 104 | elog "CONFLICT, search for '#-#-#-#-#' in the po files." 105 | elog 106 | exit 1 107 | else 108 | log "done." 109 | fi 110 | } 111 | 112 | verify_msgcat 113 | resolvepo 114 | rename_conflict_titles 115 | check_for_conflicts 116 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "git-po-merge", 3 | "version": "0.1.0", 4 | "description": "A git merge driver for Gettext .PO files", 5 | "bin": "merge.sh", 6 | "main": "index.js", 7 | "scripts": { 8 | "test": "mocha" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/beck/git-po-merge.git" 13 | }, 14 | "keywords": [ 15 | "git", 16 | "gettext", 17 | "po", 18 | "merge", 19 | "conflict", 20 | "translations", 21 | "i18n" 22 | ], 23 | "author": "Doug Beck", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/beck/git-po-merge/issues" 27 | }, 28 | "homepage": "https://github.com/beck/git-po-merge", 29 | "devDependencies": { 30 | "jsgreat": "^0.1.5", 31 | "mocha": "^2.2.1" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/catches conflicts and fails/base.po: -------------------------------------------------------------------------------- 1 | msgid "hello" 2 | msgstr "" 3 | -------------------------------------------------------------------------------- /test/catches conflicts and fails/expected.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Content-Type: text/plain; charset=UTF-8\n" 4 | "MIME-Version: 1.0\n" 5 | 6 | #, fuzzy 7 | msgid "hello" 8 | msgstr "" 9 | "#-#-#-#-# ours.po #-#-#-#-#\n" 10 | "bonjour\n" 11 | "#-#-#-#-# theirs.po #-#-#-#-#\n" 12 | "salut" 13 | -------------------------------------------------------------------------------- /test/catches conflicts and fails/ours.po: -------------------------------------------------------------------------------- 1 | msgid "hello" 2 | msgstr "bonjour" 3 | -------------------------------------------------------------------------------- /test/catches conflicts and fails/theirs.po: -------------------------------------------------------------------------------- 1 | msgid "hello" 2 | msgstr "salut" 3 | -------------------------------------------------------------------------------- /test/merges a single addition/base.po: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beck/git-po-merge/7c8199326c4693e13dd9871dc0d609b154095c27/test/merges a single addition/base.po -------------------------------------------------------------------------------- /test/merges a single addition/expected.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Content-Type: text/plain; charset=UTF-8\n" 4 | "MIME-Version: 1.0\n" 5 | 6 | msgid "Hello World" 7 | msgstr "Bonjour tout le monde" 8 | -------------------------------------------------------------------------------- /test/merges a single addition/ours.po: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/beck/git-po-merge/7c8199326c4693e13dd9871dc0d609b154095c27/test/merges a single addition/ours.po -------------------------------------------------------------------------------- /test/merges a single addition/theirs.po: -------------------------------------------------------------------------------- 1 | msgid "Hello World" 2 | msgstr "Bonjour tout le monde" 3 | -------------------------------------------------------------------------------- /test/merges pos of different widths/base.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam nec fermentum justo, accumsan ultrices risus. Donec porta rutrum nibh. Quisque tortor tortor, feugiat sed ex non, dictum fermentum dui. Donec at magna leo. Nulla facilisi. Interdum et malesuada fames ac ante ipsum primis in faucibus. Fusce ut posuere nibh.\n" 3 | "Donec consequat aliquam nisl. Mauris at lorem eu risus condimentum congue finibus at ligula. Suspendisse pulvinar tincidunt nibh vitae feugiat. In euismod neque in nisl semper, quis congue nisl molestie. Donec ac risus eget leo vulputate porttitor vitae sit amet ante. Aliquam pretium neque magna, scelerisque gravida nunc suscipit rhoncus. Vestibulum at tempor mauris, nec mollis sem. Donec bibendum eget ante rhoncus accumsan." 4 | msgstr "" 5 | -------------------------------------------------------------------------------- /test/merges pos of different widths/expected.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Content-Type: text/plain; charset=UTF-8\n" 4 | "MIME-Version: 1.0\n" 5 | 6 | msgid "" 7 | "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam nec fermentum " 8 | "justo, accumsan ultrices risus. Donec porta rutrum nibh. Quisque tortor " 9 | "tortor, feugiat sed ex non, dictum fermentum dui. Donec at magna leo. Nulla " 10 | "facilisi. Interdum et malesuada fames ac ante ipsum primis in faucibus. Fusce " 11 | "ut posuere nibh.\n" 12 | "Donec consequat aliquam nisl. Mauris at lorem eu risus condimentum congue " 13 | "finibus at ligula. Suspendisse pulvinar tincidunt nibh vitae feugiat. In " 14 | "euismod neque in nisl semper, quis congue nisl molestie. Donec ac risus eget " 15 | "leo vulputate porttitor vitae sit amet ante. Aliquam pretium neque magna, " 16 | "scelerisque gravida nunc suscipit rhoncus. Vestibulum at tempor mauris, nec " 17 | "mollis sem. Donec bibendum eget ante rhoncus accumsan." 18 | msgstr "" 19 | -------------------------------------------------------------------------------- /test/merges pos of different widths/ours.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam nec " 3 | "fermentum justo, accumsan ultrices risus. Donec porta rutrum nibh. " 4 | "Quisque tortor tortor, feugiat sed ex non, dictum fermentum dui. " 5 | "Donec at magna leo. Nulla facilisi. Interdum et malesuada fames ac " 6 | "ante ipsum primis in faucibus. Fusce ut posuere nibh.\n" 7 | "Donec consequat aliquam nisl. Mauris at lorem eu risus condimentum " 8 | "congue finibus at ligula. Suspendisse pulvinar tincidunt nibh vitae " 9 | "feugiat. In euismod neque in nisl semper, quis congue nisl molestie. " 10 | "Donec ac risus eget leo vulputate porttitor vitae sit amet ante. " 11 | "Aliquam pretium neque magna, scelerisque gravida nunc suscipit " 12 | "rhoncus. Vestibulum at tempor mauris, nec mollis sem. Donec bibendum " 13 | "eget ante rhoncus accumsan." 14 | msgstr "" 15 | -------------------------------------------------------------------------------- /test/merges pos of different widths/theirs.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Content-Type: " 4 | "text/plain; " 5 | "charset=UTF-8\n" 6 | "MIME-Version: " 7 | "1.0\n" 8 | 9 | msgid "" 10 | "Lorem ipsum dolor " 11 | "sit amet, " 12 | "consectetur " 13 | "adipiscing elit. " 14 | "Nam nec fermentum " 15 | "justo, accumsan " 16 | "ultrices risus. " 17 | "Donec porta " 18 | "rutrum nibh. " 19 | "Quisque tortor " 20 | "tortor, feugiat " 21 | "sed ex non, " 22 | "dictum fermentum " 23 | "dui. Donec at " 24 | "magna leo. Nulla " 25 | "facilisi. " 26 | "Interdum et " 27 | "malesuada fames " 28 | "ac ante ipsum " 29 | "primis in " 30 | "faucibus. Fusce " 31 | "ut posuere nibh.\n" 32 | "Donec consequat " 33 | "aliquam nisl. " 34 | "Mauris at lorem " 35 | "eu risus " 36 | "condimentum " 37 | "congue finibus at " 38 | "ligula. " 39 | "Suspendisse " 40 | "pulvinar " 41 | "tincidunt nibh " 42 | "vitae feugiat. In " 43 | "euismod neque in " 44 | "nisl semper, quis " 45 | "congue nisl " 46 | "molestie. Donec " 47 | "ac risus eget leo " 48 | "vulputate " 49 | "porttitor vitae " 50 | "sit amet ante. " 51 | "Aliquam pretium " 52 | "neque magna, " 53 | "scelerisque " 54 | "gravida nunc " 55 | "suscipit rhoncus. " 56 | "Vestibulum at " 57 | "tempor mauris, " 58 | "nec mollis sem. " 59 | "Donec bibendum " 60 | "eget ante rhoncus " 61 | "accumsan." 62 | msgstr "" 63 | -------------------------------------------------------------------------------- /test/strips long headers/base.po: -------------------------------------------------------------------------------- 1 | # Gettext headers are dumb. 2 | # 3 | # If the first file it scans does not have a non-ascii character, it will 4 | # set charset=CHARSET (how does that make sense?) 5 | # 6 | # try it: 7 | # echo 'gettext("a");' | xgettext --from-code=utf-8 --language=C --output=- - 8 | # echo 'gettext("′");' | xgettext --from-code=utf-8 --language=C --output=- - 9 | # Hoping to use --omit-header, it then chokes on utf-8 10 | # echo 'gettext("′");' | xgettext --from-code=utf-8 --language=C --output=- --omit-header - 11 | # 12 | # SOME DESCRIPTIVE TITLE. 13 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER 14 | # This file is distributed under the same license as the PACKAGE package. 15 | # FIRST AUTHOR , YEAR. 16 | # 17 | #, fuzzy 18 | msgid "" 19 | msgstr "" 20 | "Project-Id-Version: PACKAGE VERSION\n" 21 | "Report-Msgid-Bugs-To: \n" 22 | "POT-Creation-Date: 2015-03-28 16:48-0400\n" 23 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 24 | "Last-Translator: FULL NAME \n" 25 | "Language-Team: LANGUAGE \n" 26 | "Language: \n" 27 | "MIME-Version: 1.0\n" 28 | "Content-Type: text/plain; charset=CHARSET\n" 29 | "Content-Transfer-Encoding: 8bit\n" 30 | 31 | #: standard input:1 32 | msgid "Hello World" 33 | msgstr "Bonjour tout le monde" 34 | -------------------------------------------------------------------------------- /test/strips long headers/expected.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Content-Type: text/plain; charset=UTF-8\n" 4 | "MIME-Version: 1.0\n" 5 | "Language: fr\n" 6 | "Plural-Forms: nplurals=2; plural=(n > 1);\n" 7 | 8 | msgid "Hello World" 9 | msgstr "Bonjour tout le monde" 10 | -------------------------------------------------------------------------------- /test/strips long headers/ours.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: PACKAGE VERSION\n" 4 | "Report-Msgid-Bugs-To: \n" 5 | "POT-Creation-Date: 2013-03-28 16:16+0000\n" 6 | "PO-Revision-Date: 2013-03-28 17:36+0000\n" 7 | "Last-Translator: doug\n" 8 | "Language-Team: French \n" 9 | "Language: fr\n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | "Plural-Forms: nplurals=2; plural=(n > 1);\n" 14 | "X-Generator: Weblate 1.4-dev\n" 15 | 16 | msgid "Hello World" 17 | msgstr "Bonjour tout le monde" 18 | -------------------------------------------------------------------------------- /test/strips long headers/theirs.po: -------------------------------------------------------------------------------- 1 | # Generated by grunt-xgettext on Tue Mar 11 2014 11:34:34 GMT-0400 (EDT) 2 | 3 | msgid "Hello World" 4 | msgstr "Bonjour tout le monde" 5 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var assert = require('assert'); 3 | var path = require('path'); 4 | var fs = require('fs'); 5 | 6 | var pomerge = require('../index'); 7 | 8 | function isDir(p) { 9 | return fs.statSync(path.join(__dirname, p)).isDirectory(); 10 | } 11 | 12 | function getTestDirs() { 13 | return fs.readdirSync(__dirname).filter(isDir); 14 | } 15 | 16 | describe('git-po-merge', function() { 17 | 18 | var restore = []; 19 | var save = function(files) { 20 | var safeFile = function(f) { 21 | restore.push({path:f, content: fs.readFileSync(f).toString()}); 22 | }; 23 | files.map(safeFile); 24 | }; 25 | afterEach(function() { 26 | var restoreFile = function (f) { 27 | fs.writeFileSync(f.path, f.content); 28 | }; 29 | restore.map(restoreFile); 30 | }); 31 | 32 | getTestDirs().map(function(dir) { 33 | 34 | it(dir, function() { 35 | var ours = path.join(__dirname, dir, 'ours.po'); 36 | var base = path.join(__dirname, dir, 'base.po'); 37 | var theirs = path.join(__dirname, dir, 'theirs.po'); 38 | var expected = path.join(__dirname, dir, 'expected.po'); 39 | 40 | save([ours, base, theirs]); 41 | 42 | var shouldFail = dir.indexOf('fail') > 0; 43 | var failed = false; 44 | try { 45 | pomerge(ours, base, theirs, {silent: true}); 46 | } catch(e) { 47 | failed = true; 48 | } 49 | var merged = fs.readFileSync(ours).toString(); 50 | expected = fs.readFileSync(expected).toString(); 51 | 52 | assert.equal(shouldFail, failed); 53 | assert.equal(merged, expected); 54 | 55 | }); 56 | 57 | }); 58 | 59 | }); 60 | --------------------------------------------------------------------------------