mirrors: git in a mirror finds the enclosing repository where the mirror is none, and sets its origin and prunes its refs #101

Open
opened 2026-11-18 08:10:23 +00:00 by xemmerling · 0 comments
Owner

A mirror's git commands run as git -C <mirror path> … (mirrors::Mirror::command) and leave it to git to find the repository. Mirror::fetch decides "there is a mirror" by <path>/HEAD existing, and then runs git -C <path> remote set-url origin <url> and git -C <path> remote update --prune. Where <path> holds a HEAD but is not a repository git accepts, git walks up, and the two commands act on whatever repository encloses the path.

What it did

08:02:27Z 11-18, on a laptop: a developer of mine ran t's suite with TMPDIR inside a git work tree of t (my instruction, wrong, and corrected). A test's mirror lay under that TMPDIR. The work tree's shared repository got remote.origin.url = file://…/target/p/.tmpezVUmP/forge/tilo/tilo.git and every refs/remotes/origin/* was pruned: all work trees of that clone had a test fixture as their forge until I set the URL back and fetched, six minutes later. Nothing was pushed there in between.

Why it is t's to close

In production a mirror lies under the server's data directory, inside no repository, so the same state (a HEAD and no repository) only makes git fail. But "git in the mirror" is the comment's promise, and what holds it today is where the directory happens to lie. Naming the repository to git holds it everywhere: --git-dir=<path> (the mirrors are bare) in Mirror::command, or GIT_CEILING_DIRECTORIES set to the mirror's parent, and a test that puts a mirror path with a bare HEAD file inside a repository and finds that repository's config and refs untouched after a fetch.

I have not looked for which test leaves a HEAD without a repository; the suite passes on the forge and on t-testing because their temporary directories are inside no repository.

11:52Z 11-18: fixed on main, 43549ba4

Mirror::command and the fetch's own command name the mirror to git (--git-dir <path>, the mirrors are bare) instead of -C <path>: on a path that is no repository git fails and touches nothing else. Every user of Mirror::command was read (those in mirrors.rs and ci/fix.rs read or write the repository alone; fix's temporary index is given by an absolute path). The tests' scratch repository in ci/notify.rs stood at the mirror's path as a non-bare one; it is bare now, committed to from a work tree beside it. One behaviour to know: a relative URL in a repository's config resolves from the server's directory, as the clone's always did, where the fetches after it resolved it from the mirror's.

The test, mirrors::tests::a_mirror_that_is_no_repository_leaves_the_repository_around_it_alone, puts a mirror path holding only a HEAD inside a repository of its own and holds that the fetch fails and that repository's origin URL and remote branch are as they were. On t-testing: with the fix it passes alone (r396f036ac9); with the two lines put back it fails, the fetch having returned Ok (r4863c25a74); the whole check set on the candidate fails issue 103's test only (r5511c8cec9).

What stays

  • src/node/mirror.rs, the node's own mirror cache: once <m>/HEAD exists it runs git -C <m> remote update --prune and git -C <m> index-pack --stdin --fix-thin. Its clone is renamed into place whole, so a HEAD without a repository is unlikely there, and a node's data directory lies inside no repository; the same naming of the repository would hold it by rule.
  • git::has_commit and git::has_commits run git -C <mirror> cat-file … through in_repo, which client work trees share. They only read, so at worst they answer from an enclosing repository.

I leave the issue open for these two.

A mirror's git commands run as `git -C <mirror path> …` (`mirrors::Mirror::command`) and leave it to git to find the repository. `Mirror::fetch` decides "there is a mirror" by `<path>/HEAD` existing, and then runs `git -C <path> remote set-url origin <url>` and `git -C <path> remote update --prune`. Where `<path>` holds a `HEAD` but is not a repository git accepts, git walks up, and the two commands act on whatever repository encloses the path. ## What it did 08:02:27Z 11-18, on a laptop: a developer of mine ran t's suite with `TMPDIR` inside a git work tree of t (my instruction, wrong, and corrected). A test's mirror lay under that `TMPDIR`. The work tree's shared repository got `remote.origin.url = file://…/target/p/.tmpezVUmP/forge/tilo/tilo.git` and every `refs/remotes/origin/*` was pruned: all work trees of that clone had a test fixture as their forge until I set the URL back and fetched, six minutes later. Nothing was pushed there in between. ## Why it is t's to close In production a mirror lies under the server's data directory, inside no repository, so the same state (a `HEAD` and no repository) only makes git fail. But "git in the mirror" is the comment's promise, and what holds it today is where the directory happens to lie. Naming the repository to git holds it everywhere: `--git-dir=<path>` (the mirrors are bare) in `Mirror::command`, or `GIT_CEILING_DIRECTORIES` set to the mirror's parent, and a test that puts a mirror path with a bare `HEAD` file inside a repository and finds that repository's config and refs untouched after a fetch. I have not looked for which test leaves a `HEAD` without a repository; the suite passes on the forge and on t-testing because their temporary directories are inside no repository. ## 11:52Z 11-18: fixed on main, 43549ba4 `Mirror::command` and the fetch's own command name the mirror to git (`--git-dir <path>`, the mirrors are bare) instead of `-C <path>`: on a path that is no repository git fails and touches nothing else. Every user of `Mirror::command` was read (those in `mirrors.rs` and `ci/fix.rs` read or write the repository alone; `fix`'s temporary index is given by an absolute path). The tests' scratch repository in `ci/notify.rs` stood at the mirror's path as a non-bare one; it is bare now, committed to from a work tree beside it. One behaviour to know: a relative URL in a repository's config resolves from the server's directory, as the clone's always did, where the fetches after it resolved it from the mirror's. The test, `mirrors::tests::a_mirror_that_is_no_repository_leaves_the_repository_around_it_alone`, puts a mirror path holding only a `HEAD` inside a repository of its own and holds that the fetch fails and that repository's `origin` URL and remote branch are as they were. On t-testing: with the fix it passes alone (r396f036ac9); with the two lines put back it fails, the fetch having returned Ok (r4863c25a74); the whole check set on the candidate fails issue 103's test only (r5511c8cec9). ## What stays - `src/node/mirror.rs`, the node's own mirror cache: once `<m>/HEAD` exists it runs `git -C <m> remote update --prune` and `git -C <m> index-pack --stdin --fix-thin`. Its clone is renamed into place whole, so a `HEAD` without a repository is unlikely there, and a node's data directory lies inside no repository; the same naming of the repository would hold it by rule. - `git::has_commit` and `git::has_commits` run `git -C <mirror> cat-file …` through `in_repo`, which client work trees share. They only read, so at worst they answer from an enclosing repository. I leave the issue open for these two.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
tilo/t#101
No description provided.