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

Our dulwich code can leave undesired files in the repo directory #348

Closed
nickjalbert opened this issue Mar 25, 2022 · 1 comment · Fixed by #358
Closed

Our dulwich code can leave undesired files in the repo directory #348

nickjalbert opened this issue Mar 25, 2022 · 1 comment · Fixed by #358

Comments

@nickjalbert
Copy link
Contributor

The problem is that we initially clone into the default branch (e.g. master or main usually) when we clone a directory, but then we may checkout another branch (via a porcelain.reset()). However this checkout/reset is buggy and/or unintuitive in that it doesn't clean up files that exist in master but do not exist in the branch you checked out.

See pcs/repo.py for the part of the code where we use porcelain.

This bug was mentioned in #342.

Here is a script to reproduce the problem:

from pathlib import Path

from dulwich import porcelain
from dulwich.objectspec import parse_commit

local_repo_path = Path("dulwich_bug")
assert not local_repo_path.exists(), "Delete ./dulwich_bug dir"
local_repo_path.mkdir(parents=True)
github_url = "https://github.com/agentos-project/agentos.git"
porcelain.clone(source=github_url, target=str(local_repo_path), checkout=True)
repo = porcelain.open_repo(local_repo_path)
to_checkout = "07bc71358b4360092b58d78f9eee6dc939e90b10"
treeish = parse_commit(repo, to_checkout).sha().hexdigest()
porcelain.reset(repo=repo, mode="hard", treeish=treeish)

# The hash we checkout does not have a pcs/ folder so no files should exist.
# Confirm here: https://github.com/agentos-project/agentos/tree/07bc71358b4360092b58d78f9eee6dc939e90b10
# The problem is that we initially clone into master (which does have a pcs/
# folder), then we reset to a commit that doesn't have the pcs/ folder
# BUT dulwich doesn't do what you'd expect and clean up the non-existent dir
test_path = local_repo_path / "pcs" / "component.py"
assert not test_path.exists(), f"The path {test_path} should not exist!"
@nickjalbert nickjalbert changed the title Our dulwich code unexpectedly leaves undesired files in the repo directory Our dulwich code can leave undesired files in the repo directory Mar 25, 2022
@nickjalbert
Copy link
Contributor Author

See also dulwich issue "porcelaine.reset is not deleting files locally #840"

nickjalbert added a commit to nickjalbert/agentos that referenced this issue Apr 13, 2022
nickjalbert added a commit to nickjalbert/agentos that referenced this issue Apr 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant