1
0
Fork 0
mirror of synced 2024-12-04 14:45:36 -05:00

Compare commits

..

1 commit

Author SHA1 Message Date
Erik Flodin
3abfd103cf
Refactor alt handling
* Simplify score_file() by using case in instead of nested ifs with regexps.
* Merge record_score() and record_template().
* Alt condition processing no longer stops when a template condition is seen
  but continues processing to verify that all conditions are valid (as the
  documentation says it should). Fixes #478.
* Support alt dirs with deeply nested tracked files (fixes #495).
* Use git ls-files to filter out which tracked files to consider for alt
  processing. Should speed up auto-alt (#505).
2024-11-29 00:13:43 +01:00
4 changed files with 9 additions and 41 deletions

View file

@ -175,7 +175,7 @@ def test_alt_template_with_condition(runner, paths, tst_arch):
"""Test template with extra condition"""
yadm_dir, yadm_data = setup_standard_yadm_dir(paths)
suffix = f"##template,arch.not{tst_arch}"
suffix = f"##default,arch.not{tst_arch}"
utils.create_alt_files(paths, suffix)
run = runner([paths.pgm, "-Y", yadm_dir, "--yadm-data", yadm_data, "alt"])
assert run.success

View file

@ -326,31 +326,3 @@ def test_no_repo(
def verify_head(paths, branch):
"""Assert the local repo has the correct head branch"""
assert paths.repo.join("HEAD").read() == f"ref: refs/heads/{branch}\n"
@pytest.mark.usefixtures("remote")
def test_clone_subdirectory(runner, paths, yadm_cmd, repo_config):
"""Test clone from sub-directory of YADM_WORK"""
# clear out the work path
paths.work.remove()
paths.work.mkdir()
# create sub-directory
subdir = paths.work.mkdir("subdir")
# determine remote url
remote_url = f"file://{paths.remote}"
# run the clone command
args = ["clone", "-w", paths.work, remote_url]
run = runner(command=yadm_cmd(*args), cwd=subdir)
# clone should succeed, and repo should be configured properly
assert successful_clone(run, paths, repo_config)
# ensure that no changes found as this is a clean dotfiles clone
run = runner(command=yadm_cmd("status", "-uno", "--porcelain"), cwd=subdir)
assert run.success
assert run.out == ""
assert run.err == ""

View file

@ -289,15 +289,15 @@ def test_template_recording(runner, yadm, cmd_generated):
assert run.out.rstrip() == expected
def test_underscores_and_upper_case_in_distro_and_family(runner, yadm):
"""Test replacing spaces with underscores and lowering case in distro / distro_family"""
def test_underscores_in_distro_and_family(runner, yadm):
"""Test replacing spaces in distro / distro_family with underscores"""
local_distro = "test distro"
local_distro_family = "test family"
filenames = {
"filename##distro.Test Distro": 1004,
"filename##distro.test distro": 1004,
"filename##distro.test-distro": 0,
"filename##distro.test_distro": 1004,
"filename##distro_family.test FAMILY": 1008,
"filename##distro_family.test family": 1008,
"filename##distro_family.test-family": 0,
"filename##distro_family.test_family": 1008,
}

12
yadm
View file

@ -191,14 +191,10 @@ function score_file() {
[ "$value" = "$local_system" ] && delta=2
;;
d|distro)
shopt -s nocasematch
[[ "${value// /_}" = "${local_distro// /_}" ]] && delta=4
shopt -u nocasematch
[ "${value// /_}" = "${local_distro// /_}" ] && delta=4
;;
f|distro_family)
shopt -s nocasematch
[[ "${value// /_}" = "${local_distro_family// /_}" ]] && delta=8
shopt -u nocasematch
[ "${value// /_}" = "${local_distro_family// /_}" ] && delta=8
;;
c|class)
in_list "$value" "${local_classes[@]}" && delta=16
@ -439,7 +435,7 @@ EOF
-v distro="$local_distro" \
-v distro_family="$local_distro_family" \
-v source="$input" \
-v source_dir="$(builtin_dirname "$input")" \
-v source_dir="$(dirname "$input")" \
"$awk_pgm" \
"$input" "${local_classes[@]}" > "$temp_file" || rm -f "$temp_file"
@ -803,7 +799,7 @@ function clone() {
rm -rf "$wc"
# then reset the index as the --no-checkout flag makes the index empty
"$GIT_PROGRAM" reset --quiet -- ":/"
"$GIT_PROGRAM" reset --quiet -- .
if [ "$YADM_WORK" = "$HOME" ]; then
debug "Determining if repo tracks private directories"