Repository navigation
Phase: git init falls back when -b is unsupported - #1676
Merged
neuromechanist merged 19 commits intoOct 8, 2026
Merged
neuromechanist merged 19 commits into
neuromechanist merged 19 commits into
Conversation
initDataset ran 'git init -b main', which git 2.25 (Ubuntu 20.04's system git, common on HPC images) rejects with "unknown switch `b'"; uploads failed at 'Initializing git-annex dataset' unless a newer git was shimmed onto PATH. initGitRepoOnMain now retries with a plain 'git init' and points the unborn HEAD at refs/heads/main, which is what -b does. Other init failures are reported as before.
git localizes its usage errors (German 'Unbekannter Schalter', French 'bascule inconnue'), so matching the English text left a non-English git 2.25 failing as in #1645. Fall back on exit status 129 instead and report every other failure as before. The helper is module-private now; the tests drive initDataset under a PATH stand-in for an older git binary, with English, German, French and empty stderr.
Modern git ignores -b for a repository that already exists, so HEAD stays on its branch and the upload's branch check renames it to main with its history. The fallback re-pointed HEAD unconditionally, which stranded the history on master and made main a one-commit root. Re-point only an unborn HEAD. The tests seed a two-commit master repository, run the upload's init and branch check under the older-git stand-in, and compare the end state with a modern git's. Tested.
A path under a file also fails downstream when the init error is swallowed, so a bare success flag did not catch a swallowed failure. Compare the reported error with what the real git prints for the same path. Tested.
The git stand-in refused three hard-coded calls through one field each. A list of answers keyed on the call's arguments lets later tests make any other call fail. No behavior change; the 17 tests still pass.
Seed the two-commit repository under the test's own git config with gpg signing off, and stop on any failing seed step. Add a canary that fails when GIT_CONFIG_GLOBAL is ignored (git < 2.32), which makes the version skips dead, so remove them. Ask the real git for its usage-error (129) and fatal (128) statuses in three locales, assert the modern control kept c1 and c2, fail clearly without git on PATH, and make the temp tree removable before cleanup. Tested.
A path starting with a dash was parsed as a switch: --bare silently created a bare repository in the working directory, and any other dash word was a usage error (exit 129) that the fallback then misread. Pass the path after -- in both git init calls. The test runs initDataset on a path named --bare in a scratch working directory under both a modern git and the older-git stand-in. Tested.
rev-parse exits 1 quietly both for an unborn branch and for a branch ref that exists but is corrupt, and 128 for an unreadable repository. The fallback read every non-zero status as unborn, so it re-pointed HEAD at main over a corrupt master and reported success while modern git refuses loudly. Resolving HEAD leaves it alone. Exit 1 is then confirmed unborn only when symbolic-ref names a branch whose ref show-ref reports absent; any other status is returned at once with git's own stderr and no write. An existing unborn master is named main immediately; a populated develop beside it is untouched. Statuses only, no text. Tested.
Every failure after git init -b is rejected now starts with 'git init -b main was rejected (exit 129);' and names the step that failed: plain git init, reading HEAD, or pointing HEAD at main. A silent failing step reports its exit status instead of a generic text that was identical for the first and second attempts. The caller prints these under 'Failed to initialize git-annex dataset', where a bare git error read like a git-annex problem. Tested, including the empty-stderr variants of both fallback steps.
initDataset built the env options after git init and initGitRepoOnMain rebuilt them from the raw env. Build them once, before the first call, and pass them in. No behavior change; the fallback and add-targets tests pass.
Say 129 means git rejected -b apart from the path, which now follows --, drop history and unverifiable claims about which systems ship an old git, describe the adjusted-branch rename accurately, document that an existing unborn branch is named main at once, and fix the test comments that misdescribed the stand-in, the caller of the branch check and a leftover count assertion. Comment and title changes only; the 32 tests still pass.
📦 Package PreviewYour package is ready to test! Version: 🤖 Updated on each push. |
The expression 'stderr.trim() || exit N' was spelled five ways. One helper, said(), returns git's words or the exit status, and the unreadable-HEAD reasons use early returns instead of a nested ternary. No behavior change; the 32 fallback tests pass.
runCommand only spreads options.env, so an empty env needs no conditional and no EnvOptions type. initGitRepoOnMain and readHeadState take the env record, and initDataset's own env options line is back where it was, which removes that hunk from the diff. No behavior change; the fallback and add-targets tests pass.
Answer.when is now the start of the call's arguments instead of a quoted shell pattern, which removes quoting at five call sites. The never-answering logging wrapper is makeShim(), and the words/no-words cases are explicit triples instead of a string special case. Every assertion keeps its meaning; the 32 tests pass.
Three near-identical seeders become seed(dir, branch, ...messages). Commits use -c user.name and user.email only: the gpgsign flag duplicated the test's GIT_CONFIG_GLOBAL file, and gitOk throwing on any failing step replaces the rev-list sanity check. The 32 tests pass.
The German, French and empty-text fallback cases killed the identical set of mutants, so the stand-in keeps English, German and empty text; the real-git locale test still asks git itself for 129 under C, German and French. The fatal-128 check folds into the path-cannot-be-created test. The parity-with-modern-git and dash-path tests stay: they are the only oracles for modern behavior and for --. 29 tests pass.
The throwing beforeAll canary failed the whole file on a developer's git older than 2.32. A plain init that lands on trunk proves both init.defaultBranch and GIT_CONFIG_GLOBAL, so one probe at module level replaces it: outside CI the suite skips with a warning, under CI the file throws, following requireOnCi in the Neurobagel deploy tests. Checked with a git stub that drops GIT_CONFIG_GLOBAL: 29 skipped and exit 0 locally, exit 1 with CI=true; 29 pass on the host git.
Four tests repeated success false, the fallback note, the mentioned text and no re-point. expectRefusal(shim, dir, mention) runs initDataset and asserts all four; the corrupt-ref test now reads git's own probe words before calling it. The 29 tests pass.
Dropping the ref === '' check left every test green. git show-ref --verify -q '' exits 1, the same status as an absent branch, so an empty branch name would read as unborn and HEAD would be re-pointed. A stand-in symbolic-ref that succeeds with no output now has to be refused; with the guard removed that test fails.
Contributor
Author
Review recordOne pass of the PR review toolkit (Sonnet agents): code review, test analysis, silent-failure hunt, comment analysis, then a propose-only simplifier. No critical findings. Every finding below was fixed unless it is listed under "Not done". Tip at the time of writing: Important
Suggestions and nice-to-have (all applied)
Verification
Not done (tracked follow-ups)
|
neuromechanist
merged commit Oct 8, 2026
bde6a22
into
feature/issue-1671-epic-bru-upload-fixes
14 checks passed
This was referenced Oct 8, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
initDatasetrangit init -b main, which git older than 2.28 rejects as an unknown switch, so uploads stopped at "Initializing git-annex dataset" (issue #1645).The initial branch is now set on any git version:
git init -b mainfirst, and when git answers with its usage-error status, a plaingit initfollowed by pointing an unborn HEAD atrefs/heads/main.The first commit is the contributor's original fix (PR #1650, bruAristimunha), preserved with authorship.
The commits on top are review refinements:
Unbekannter Schalter,bascule inconnue), so a text match would miss the fallback on a non-English locale; every other failure is reported as before (a fatal path error exits 128)rev-parse -q --verify HEADexiting 0 means HEAD resolves and is left alone; exiting exactly 1 is confirmed unborn only ifsymbolic-ref -q HEADnames a branch andshow-ref --verify -q <ref>exits exactly 1; any other status, or a branch ref that exists but is unreadable, is returned immediately with git's own text and nothing is written (a corruptrefs/heads/masteron an old git used to be re-pointed and reported as success, where modern git refuses loudly)mainwith its history intact instead of stranding the history onmaster-brejection says so (git init -b main was rejected (exit 129); plain git init failed: ...,could not point HEAD at main: ...) and silent failures reportexit N--before the path, so a path starting with-is a path (a path like--bareused to create a bare repository in the current directory)initGitRepoOnMainis module-private andisInitialBranchUnsupportedis gone, so the tests drive the real entry pointinitDatasetandensureLocalMainBranch; the export-surface test needs no changegitshim expressed as a list of answers keyed on the call (it logs every call, runs the real git for everything else, and answersinit -bwith a usage error and exit 129 in English, German and with empty stderr); real git and real git-annex do the rest; the seed repositories are built under the test's own git config with every step asserted; separate tests ask the real git for exit codes (129 for an unknown switch under C, German and French locales, 128 for a path that cannot be created)GIT_CONFIG_GLOBALneeds git 2.32, so the file skips with a loud message outside CI when git is older and throws in CI, which can never skip silentlyPart of epic #1671. Supersedes #1650 (contributor PR retargeted to the epic branch). Issue: #1645.
Behavior to know about
masteris namedmainimmediately by the fallback. Modern git leaves it onmasteruntil the later rename prompt and ends onrefs/heads/main(the adjusted branch renamed) with a straymaster; the fallback ends onadjusted/main(unlocked)with no stray branch, which is the healthier result.git init -balso reads as 129 in Bun; the cost is a redundant fallback attempt. A fix needsrunCommandto expose the signal.-bbegin withgit init -b main was rejected (exit 129);, which the callers print under "Failed to initialize git-annex dataset".Test plan
bun run typecheck(root and backend),biome checkandbun run linttest/git-init-branch-fallback.unit.test.ts30 pass withCIunset and withCI=true;test/git-annex-export-surface.unit.test.ts11; eight neighbor files that importinit.ts: all pass, 0 failtestRequest|TEST_API_URL|runCli\() finds nothing in the test file-bnever tried or fallback first fails 14 and 21, fall back on any non-zero exit fails 3, a non-129 failure swallowed fails 3, HEAD never re-pointed fails 7,--dropped from either call fails 14 and 9, the previous any-non-zero-is-unborn guard fails 5, each of the new probe statuses fails 1 to 2, fallback prefix dropped fails 9, the pinned empty-answer guard fails 1gitthat ignoresGIT_CONFIG_GLOBAL: outside CI all tests skip with a warning (exit 0), underCI=truethe file throws (exit 1)docker run ubuntu:20.04with apt git andgit init -b main /tmp/x; echo $?, expecting 129, and checksymbolic-ref -qandshow-refon a corrupt ref on that git.Follow-ups (not in this PR)
signalCodefromrunCommandso a SIGHUP is not read as a usage errorensureLocalMainBranchrenamesadjusted/master(unlocked)tomain; that is the existing behavior on modern git and is left alone