From 574945f0101ce39ca7fe1da25e534fc3ca9e027b Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Wed, 9 Oct 2019 08:25:02 -0500 Subject: [PATCH] Change yadm.cygwin-copy to yadm.alt-copy This removes the constraint of only allowing the copy option on Cygwin systems. Now any system can configure this option. --- test/conftest.py | 16 +++------ test/test_alt_copy.py | 61 ++++++++++++++++++++++++++++++++++ test/test_cygwin_copy.py | 71 ---------------------------------------- yadm | 9 ++--- yadm.1 | 16 ++++++--- 5 files changed, 81 insertions(+), 92 deletions(-) create mode 100644 test/test_alt_copy.py delete mode 100644 test/test_cygwin_copy.py diff --git a/test/conftest.py b/test/conftest.py index b1cf16f..805ee92 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -63,12 +63,6 @@ def tst_sys(): return platform.system() -@pytest.fixture(scope='session') -def cygwin_sys(): - """CYGWIN uname id""" - return 'CYGWIN_NT-6.1-WOW64' - - @pytest.fixture(scope='session') def supported_commands(): """List of supported commands @@ -105,10 +99,10 @@ def supported_configs(): 'local.hostname', 'local.os', 'local.user', + 'yadm.alt-copy', 'yadm.auto-alt', 'yadm.auto-perms', 'yadm.auto-private-dirs', - 'yadm.cygwin-copy', 'yadm.git-program', 'yadm.gpg-perms', 'yadm.gpg-program', @@ -444,7 +438,7 @@ class DataSet(): @pytest.fixture(scope='session') -def ds1_dset(tst_sys, cygwin_sys): +def ds1_dset(tst_sys): """Meta-data for dataset one files""" dset = DataSet() dset.add_file('t1') @@ -457,10 +451,8 @@ def ds1_dset(tst_sys, cygwin_sys): dset.add_file(f'test alt/test alt##S.H') dset.add_file(f'test alt/test alt##S.H.U') dset.add_file(f'test alt/test alt##C.S.H.U') - dset.add_file(f'test_cygwin_copy##{tst_sys}') - dset.add_file(f'test_cygwin_copy##{cygwin_sys}') - dset.add_file(f'test_cygwin_copy##os.{tst_sys}') - dset.add_file(f'test_cygwin_copy##os.{cygwin_sys}') + dset.add_file(f'test_alt_copy##{tst_sys}') + dset.add_file(f'test_alt_copy##os.{tst_sys}') dset.add_file('u1', tracked=False) dset.add_file('d2/u2', tracked=False) dset.add_file('.ssh/p1', tracked=False, private=True) diff --git a/test/test_alt_copy.py b/test/test_alt_copy.py new file mode 100644 index 0000000..b26848f --- /dev/null +++ b/test/test_alt_copy.py @@ -0,0 +1,61 @@ +"""Test yadm.alt-copy""" + +import os +import pytest + + +@pytest.mark.parametrize( + 'cygwin', + [pytest.param(True, marks=pytest.mark.deprecated), False], + ids=['cygwin', 'no-cygwin']) +@pytest.mark.parametrize( + 'compatibility', [True, False], ids=['compat', 'no-compat']) +@pytest.mark.parametrize( + 'setting, expect_link, pre_existing', [ + (None, True, None), + (True, False, None), + (False, True, None), + (True, False, 'link'), + (True, False, 'file'), + ], + ids=[ + 'unset', + 'true', + 'false', + 'pre-existing symlink', + 'pre-existing file', + ]) +@pytest.mark.usefixtures('ds1_copy') +def test_alt_copy( + runner, yadm_y, paths, tst_sys, + setting, expect_link, pre_existing, + compatibility, cygwin): + """Test yadm.alt-copy""" + + option = 'yadm.cygwin-copy' if cygwin else 'yadm.alt-copy' + + if setting is not None: + os.system(' '.join(yadm_y('config', option, str(setting)))) + + if compatibility: + expected_content = f'test_alt_copy##{tst_sys}' + else: + expected_content = f'test_alt_copy##os.{tst_sys}' + + alt_path = paths.work.join('test_alt_copy') + if pre_existing == 'symlink': + alt_path.mklinkto(expected_content) + elif pre_existing == 'file': + alt_path.write('wrong content') + + env = os.environ.copy() + if compatibility: + env['YADM_COMPATIBILITY'] = '1' + + run = runner(yadm_y('alt'), env=env) + assert run.success + assert run.err == '' + assert 'Linking' in run.out + + assert alt_path.read() == expected_content + assert alt_path.islink() == expect_link diff --git a/test/test_cygwin_copy.py b/test/test_cygwin_copy.py deleted file mode 100644 index 47dbb61..0000000 --- a/test/test_cygwin_copy.py +++ /dev/null @@ -1,71 +0,0 @@ -"""Test yadm.cygwin_copy""" - -import os -import pytest - - -@pytest.mark.parametrize( - 'compatibility', [True, False], ids=['compat', 'no-compat']) -@pytest.mark.parametrize( - 'setting, is_cygwin, expect_link, pre_existing', [ - (None, False, True, None), - (True, False, True, None), - (False, False, True, None), - (None, True, True, None), - (True, True, False, None), - (False, True, True, None), - (True, True, False, 'link'), - (True, True, False, 'file'), - ], - ids=[ - 'unset, non-cygwin', - 'true, non-cygwin', - 'false, non-cygwin', - 'unset, cygwin', - 'true, cygwin', - 'false, cygwin', - 'pre-existing symlink', - 'pre-existing file', - ]) -@pytest.mark.usefixtures('ds1_copy') -def test_cygwin_copy( - runner, yadm_y, paths, cygwin_sys, tst_sys, - setting, is_cygwin, expect_link, pre_existing, - compatibility): - """Test yadm.cygwin_copy""" - - if setting is not None: - os.system(' '.join(yadm_y('config', 'yadm.cygwin-copy', str(setting)))) - - if compatibility: - expected_content = f'test_cygwin_copy##{tst_sys}' - else: - expected_content = f'test_cygwin_copy##os.{tst_sys}' - - alt_path = paths.work.join('test_cygwin_copy') - if pre_existing == 'symlink': - alt_path.mklinkto(expected_content) - elif pre_existing == 'file': - alt_path.write('wrong content') - - uname_path = paths.root.join('tmp').mkdir() - if is_cygwin: - uname = uname_path.join('uname') - uname.write(f'#!/bin/sh\necho "{cygwin_sys}"\n') - uname.chmod(0o777) - if compatibility: - expected_content = f'test_cygwin_copy##{cygwin_sys}' - else: - expected_content = f'test_cygwin_copy##os.{cygwin_sys}' - env = os.environ.copy() - env['PATH'] = ':'.join([str(uname_path), env['PATH']]) - if compatibility: - env['YADM_COMPATIBILITY'] = '1' - - run = runner(yadm_y('alt'), env=env) - assert run.success - assert run.err == '' - assert 'Linking' in run.out - - assert alt_path.read() == expected_content - assert alt_path.islink() == expect_link diff --git a/yadm b/yadm index c3ec5c5..887da84 100755 --- a/yadm +++ b/yadm @@ -389,9 +389,10 @@ function alt() { # decide if a copy should be done instead of a symbolic link local do_copy=0 - [[ $OPERATING_SYSTEM =~ ^(CYGWIN|MSYS) ]] && - [ "$(config --bool yadm.cygwin-copy)" == "true" ] && - do_copy=1 + [ "$(config --bool yadm.alt-copy)" == "true" ] && do_copy=1 + + # deprecated yadm.cygwin-copy option (to be removed) + [ "$(config --bool yadm.cygwin-copy)" == "true" ] && do_copy=1 cd_work "Alternates" || return @@ -966,10 +967,10 @@ local.class local.hostname local.os local.user +yadm.alt-copy yadm.auto-alt yadm.auto-perms yadm.auto-private-dirs -yadm.cygwin-copy yadm.git-program yadm.gpg-perms yadm.gpg-program diff --git a/yadm.1 b/yadm.1 index a1b5be5..35a2294 100644 --- a/yadm.1 +++ b/yadm.1 @@ -331,6 +331,17 @@ yadm config yadm.auto-alt false The following is the full list of supported configurations: .TP +.B yadm.alt-copy +If set to "true", alternate files will be copies instead of symbolic links. +This might be desirable, because some systems may not properly support +symlinks. + +NOTE: The deprecated +.I yadm.cygwin-copy +option used by older versions of yadm has been replaced by +.IR yadm.alt-copy . +The old option will be removed in the next version of yadm. +.TP .B yadm.auto-alt Disable the automatic linking described in the section ALTERNATES. If disabled, you may still run "yadm alt" manually to create the alternate links. This @@ -372,11 +383,6 @@ By default, the first "gpg" found in $PATH is used. .B yadm.git-program Specify an alternate program to use instead of "git". By default, the first "git" found in $PATH is used. -.TP -.B yadm.cygwin-copy -If set to "true", for Cygwin hosts, alternate files will be copies instead of -symbolic links. This might be desirable, because non-Cygwin software may not -properly interpret Cygwin symlinks. .RE The following four "local" configurations are not stored in the