瀏覽代碼

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.
Tim Byrne 5 年之前
父節點
當前提交
574945f010
共有 5 個文件被更改,包括 81 次插入92 次删除
  1. 4 12
      test/conftest.py
  2. 61 0
      test/test_alt_copy.py
  3. 0 71
      test/test_cygwin_copy.py
  4. 5 4
      yadm
  5. 11 5
      yadm.1

+ 4 - 12
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)

+ 61 - 0
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

+ 0 - 71
test/test_cygwin_copy.py

@@ -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

+ 5 - 4
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

+ 11 - 5
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