Fix bug in custom conflict_resolution

Fix #563
This commit is contained in:
Markus Unterwaditzer 2017-02-26 23:21:22 +01:00
parent b3e389cb59
commit e457586b29
2 changed files with 30 additions and 3 deletions

View file

@ -0,0 +1,23 @@
import os
from vdirsyncer.cli.config import _resolve_conflict_via_command
from vdirsyncer.utils.vobject import Item
def test_conflict_resolution_command():
def check_call(command):
command, a_tmp, b_tmp = command
assert command == os.path.expanduser('~/command')
with open(a_tmp) as f:
assert f.read() == a.raw
with open(b_tmp) as f:
assert f.read() == b.raw
with open(b_tmp, 'w') as f:
f.write(a.raw)
a = Item('UID:AAAAAAA')
b = Item('UID:BBBBBBB')
assert _resolve_conflict_via_command(
a, b, ['~/command'], 'a', 'b',
_check_call=check_call
).raw == a.raw

View file

@ -306,10 +306,13 @@ class CollectionConfig(object):
load_config = Config.from_filename_or_environment
def _resolve_conflict_via_command(a, b, command, a_name, b_name):
def _resolve_conflict_via_command(a, b, command, a_name, b_name,
_check_call=None):
import tempfile
import shutil
import subprocess
if _check_call is None:
from subprocess import check_call as _check_call
from ..utils.vobject import Item
@ -323,7 +326,8 @@ def _resolve_conflict_via_command(a, b, command, a_name, b_name):
with open(b_tmp, 'w') as f:
f.write(b.raw)
subprocess.check_call(command + [a_tmp, b_tmp])
command[0] = expand_path(command[0])
_check_call(command + [a_tmp, b_tmp])
with open(a_tmp) as f:
new_a = f.read()