Skip to content

fix(gitclone): skip and remove leftover clone temp dirs#362

Merged
alecthomas merged 2 commits into
mainfrom
aat/skip-leftover-clone-temp-dirs
Jun 26, 2026
Merged

fix(gitclone): skip and remove leftover clone temp dirs#362
alecthomas merged 2 commits into
mainfrom
aat/skip-leftover-clone-temp-dirs

Conversation

@alecthomas

Copy link
Copy Markdown
Collaborator

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.

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.
@alecthomas alecthomas requested a review from a team as a code owner June 26, 2026 01:23
@alecthomas alecthomas requested review from inez and removed request for a team June 26, 2026 01:23
@alecthomas alecthomas enabled auto-merge (squash) June 26, 2026 01:23
@alecthomas alecthomas merged commit c811d61 into main Jun 26, 2026
7 checks passed
@alecthomas alecthomas deleted the aat/skip-leftover-clone-temp-dirs branch June 26, 2026 01:25

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +237 to +241
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)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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 this pull request may close these issues.

1 participant