Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(clone): reset index of YADM_WORK #507

Merged
merged 5 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions test/test_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == ""
2 changes: 1 addition & 1 deletion yadm
Original file line number Diff line number Diff line change
Expand Up @@ -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 -- ":/"

if [ "$YADM_WORK" = "$HOME" ]; then
debug "Determining if repo tracks private directories"
Expand Down