1
0
Fork 0
mirror of synced 2024-12-04 06:35:36 -05:00

Compare commits

..

7 commits

Author SHA1 Message Date
Erik Flodin
04df6e42e0
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 #490).
* Use git ls-files to filter out which tracked files to consider for alt
  processing. Should speed up auto-alt (#505).
* Use nocasematch when comparing distro and distro_family. Fixed #455.
2024-11-29 23:37:19 +01:00
Erik Flodin
6ee9b472d1
Merge pull request #507 from AVM-Martin/fix/reset-yadm-work-index
fix(clone): reset index of YADM_WORK
2024-11-29 23:10:35 +01:00
AVM.Martin
ae3a149449
style: use pathspec for consistency 2024-11-26 19:22:18 +07:00
AVM.Martin
85e8c1ddfc
docs: fix comment 2024-11-26 19:21:18 +07:00
AVM.Martin
a7939bec7b
style: join arguments 2024-11-26 19:20:59 +07:00
AVM.Martin
aba434274e
fix(clone): reset index of YADM_WORK 2024-07-21 07:02:49 +07:00
AVM.Martin
12c51e130b
test(clone): run inside YADM_WORK sub-directory
Whenever using `clone` command inside YADM_WORK sub-directory, we need
to checkout the correct repo contents.

Steps to reproduce:

```bash
mkdir $HOME/subdir
cd $HOME/subdir

yadm clone --bootstrap "<repo-url>"
yadm status
```
2024-07-21 07:02:49 +07:00
4 changed files with 41 additions and 9 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"##default,arch.not{tst_arch}"
suffix = f"##template,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,3 +326,31 @@ 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_in_distro_and_family(runner, yadm):
"""Test replacing spaces in distro / distro_family with underscores"""
def test_underscores_and_upper_case_in_distro_and_family(runner, yadm):
"""Test replacing spaces with underscores and lowering case in distro / distro_family"""
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,10 +191,14 @@ function score_file() {
[ "$value" = "$local_system" ] && delta=2
;;
d|distro)
[ "${value// /_}" = "${local_distro// /_}" ] && delta=4
shopt -s nocasematch
[[ "${value// /_}" = "${local_distro// /_}" ]] && delta=4
shopt -u nocasematch
;;
f|distro_family)
[ "${value// /_}" = "${local_distro_family// /_}" ] && delta=8
shopt -s nocasematch
[[ "${value// /_}" = "${local_distro_family// /_}" ]] && delta=8
shopt -u nocasematch
;;
c|class)
in_list "$value" "${local_classes[@]}" && delta=16
@ -435,7 +439,7 @@ EOF
-v distro="$local_distro" \
-v distro_family="$local_distro_family" \
-v source="$input" \
-v source_dir="$(dirname "$input")" \
-v source_dir="$(builtin_dirname "$input")" \
"$awk_pgm" \
"$input" "${local_classes[@]}" > "$temp_file" || rm -f "$temp_file"
@ -799,7 +803,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"