From 12c51e130b2fe042c8945ef5afa724817c9add25 Mon Sep 17 00:00:00 2001 From: "AVM.Martin" Date: Sun, 21 Jul 2024 04:58:42 +0700 Subject: [PATCH 1/5] 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 "" yadm status ``` --- test/test_clone.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/test_clone.py b/test/test_clone.py index 1cae929..30beafb 100644 --- a/test/test_clone.py +++ b/test/test_clone.py @@ -326,3 +326,32 @@ 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] + args += [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) + + # test that the conflicts are preserved in the work tree + run = runner(command=yadm_cmd("status", "-uno", "--porcelain"), cwd=subdir) + assert run.success + assert run.out == "" + assert run.err == "" From aba434274e87c96c9e59cb3eaed51d7cf399a7bd Mon Sep 17 00:00:00 2001 From: "AVM.Martin" Date: Sun, 21 Jul 2024 04:58:42 +0700 Subject: [PATCH 2/5] fix(clone): reset index of YADM_WORK --- yadm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yadm b/yadm index 09da278..fddf6c0 100755 --- a/yadm +++ b/yadm @@ -827,7 +827,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 -- "$YADM_WORK" if [ "$YADM_WORK" = "$HOME" ]; then debug "Determining if repo tracks private directories" From a7939bec7ba89c39bd55471ae33103db9d435c6c Mon Sep 17 00:00:00 2001 From: "AVM.Martin" Date: Tue, 26 Nov 2024 19:20:59 +0700 Subject: [PATCH 3/5] style: join arguments --- test/test_clone.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/test_clone.py b/test/test_clone.py index 30beafb..266ebcc 100644 --- a/test/test_clone.py +++ b/test/test_clone.py @@ -343,8 +343,7 @@ def test_clone_subdirectory(runner, paths, yadm_cmd, repo_config): remote_url = f"file://{paths.remote}" # run the clone command - args = ["clone", "-w", paths.work] - args += [remote_url] + args = ["clone", "-w", paths.work, remote_url] run = runner(command=yadm_cmd(*args), cwd=subdir) # clone should succeed, and repo should be configured properly From 85e8c1ddfcbb7d206cc6945fc1fdf25e100c9b4a Mon Sep 17 00:00:00 2001 From: "AVM.Martin" Date: Tue, 26 Nov 2024 19:21:18 +0700 Subject: [PATCH 4/5] docs: fix comment --- test/test_clone.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_clone.py b/test/test_clone.py index 266ebcc..83a96c8 100644 --- a/test/test_clone.py +++ b/test/test_clone.py @@ -349,7 +349,7 @@ def test_clone_subdirectory(runner, paths, yadm_cmd, repo_config): # clone should succeed, and repo should be configured properly assert successful_clone(run, paths, repo_config) - # test that the conflicts are preserved in the work tree + # 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 == "" From ae3a1494497702d16f2331a8d39c136c6e11f066 Mon Sep 17 00:00:00 2001 From: "AVM.Martin" Date: Tue, 26 Nov 2024 19:22:18 +0700 Subject: [PATCH 5/5] style: use pathspec for consistency --- yadm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yadm b/yadm index fddf6c0..2dec60a 100755 --- a/yadm +++ b/yadm @@ -827,7 +827,7 @@ function clone() { rm -rf "$wc" # then reset the index as the --no-checkout flag makes the index empty - "$GIT_PROGRAM" reset --quiet -- "$YADM_WORK" + "$GIT_PROGRAM" reset --quiet -- ":/" if [ "$YADM_WORK" = "$HOME" ]; then debug "Determining if repo tracks private directories"