fix(gitclone): skip and remove leftover clone temp dirs#362
Conversation
Interrupted clones can leave .clone-* temp directories behind whose repo subdirectory contains a HEAD file. DiscoverExisting treated these as real mirrors and warmExistingRepos ran startup fetches against the bogus upstream URL. Remove and skip them on discovery instead.
Git exports GIT_DIR, GIT_WORK_TREE and GIT_INDEX_FILE when running hooks. Test git commands inherited these and operated on the ambient repository instead of their temp dirs, polluting it with junk commits during the pre-push hook. Drop them in TestMain.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7c204f8ef4
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if strings.HasPrefix(info.Name(), cloneTempPrefix) { | ||
| logging.FromContext(ctx).InfoContext(ctx, "Removing leftover clone temp dir", "path", path) | ||
| if rmErr := os.RemoveAll(path); rmErr != nil { | ||
| return errors.Wrapf(rmErr, "remove leftover clone temp dir %s", path) | ||
| } |
There was a problem hiding this comment.
Restrict clone temp cleanup to actual scratch dirs
When an upstream URL contains a legitimate path component such as .clone-tools (which RepoPathFromURL maps directly under MirrorRoot), this walk reaches that mirror directory and removes it before checking for HEAD. That can delete usable mirrors on startup for generic Git hosts or repos/namespaces with this prefix; the cleanup should only remove directories known to be cachew clone scratch dirs rather than any directory whose basename starts with .clone-.
Useful? React with 👍 / 👎.
Interrupted clones can leave .clone-* temp directories behind whose
repo subdirectory contains a HEAD file. DiscoverExisting treated these
as real mirrors and warmExistingRepos ran startup fetches against the
bogus upstream URL. Remove and skip them on discovery instead.