Skip to content

Phase 2: Fix git-divergence on OpenNeuro re-import - #994

Merged
neuromechanist merged 2 commits into
feature/issue-989-epic-import-stabilityfrom
feature/issue-990-phase2-reimport-divergence
Jul 22, 2026
Merged

neuromechanist merged 2 commits into
feature/issue-989-epic-import-stabilityfrom
feature/issue-990-phase2-reimport-divergence

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Re-importing an OpenNeuro dataset onto an already-published nemarDatasets repo failed at prepare: a fresh OpenNeuro clone's main diverges from origin/main (each import adds its own metadata commit on the same files), so pushToGitHub's rebase conflicts and hard-fails 'diverging commits and auto-rebase failed'. This blocked re-copying the 14 quarantined #967 recovery stragglers.

Fix: new Step 4c in prepareImport (src/lib/import-openneuro.ts) — on a re-import (origin/main resolves + current branch is main), git fetch origin main + git reset --hard origin/main BEFORE the metadata seed, so the seed is idempotent / fast-forward and the push succeeds. Pure decideReimportMainReset guards out detached-HEAD and adjusted/* (DataLad) branches. First-import path (origin has no main) is a fully-skipped no-op. pushToGitHub's rebase is untouched (stays as the backstop for genuine concurrent-push divergence). The data copy phase is server-side S3 by annex key, independent of main history.

Same-version assumption (recovery use case) is documented; a genuinely new upstream snapshot is out of scope, tracked as a drift-guard follow-up #993.

Test plan

Real (no-mock) local-git tests via the existing bare-repo harness:

  • decideReimportMainReset pure unit (5 cases: sha+main, null, empty-string, adjusted/main, HEAD).
  • Regression guard: reproduces the exact diverging-commits push failure without Step 4c.
  • Fix: proves a genuine fast-forward (merge-base --is-ancestor) with both metadata commits preserved (third-clone check).
  • Gap 1: same-version idempotent recovery (identical metadata -> 'nothing to commit' -> no-op fast-forward push) — the primary recovery path.
  • Gap 2: first-import must-not-regress (origin has no main -> Step 4c skipped -> plain push succeeds).

Verified locally: root tsc + Biome clean; CI pure-tier 2504 tests, 0 fail. Two Sonnet reviewers, no blocking findings (drift-guard deferred to #993).

Closes #990
Part of epic #989

Re-importing an OpenNeuro dataset onto an already-published
nemarDatasets repo always makes a fresh clone whose main shares no
metadata history with origin. Step 6's new metadata commit then
collides with the first import's metadata commit on push, and
pushToGitHub's rebase hard-fails with "diverging commits and
auto-rebase failed".

Add Step 4c: after the git-annex branch merge (Step 4b) and before
the S3 remote setup (Step 5), fetch origin/main and, only on a plain
main branch with a resolvable origin tip, reset local main onto it.
Detached HEAD and git-annex adjusted branches are excluded since
pushToGitHub already special-cases them. First imports (no origin
main yet) are unaffected. Scoped to same-version recovery; a
genuinely new upstream snapshot is out of scope.

decideReimportMainReset is the pure gate, unit-tested directly.
git-annex-remote.test.ts adds a real bare-repo regression guard that
reproduces the diverging-push failure, plus a fix test proving the
Step 4c sequence turns the same re-import into a fast-forward push.
Two real bare-repo tests reviewers flagged as missing coverage:

- Same-version recovery (the primary #967 use case): re-import with
  metadata content identical to the first import is a no-op commit
  and a no-op push, not an error.
- First-import regression guard: origin has no main ref yet, so
  Step 4c's fetch fails and the block is skipped entirely, leaving
  the ordinary first-import push untouched.

Also references the tracked follow-up (#993) for new-version drift
detection in the Step 4c out-of-scope comment.
@neuromechanist
neuromechanist merged commit 8d379c8 into feature/issue-989-epic-import-stability Jul 22, 2026
1 check passed
@neuromechanist
neuromechanist deleted the feature/issue-990-phase2-reimport-divergence branch July 22, 2026 20:48

This branch was previously deployed

1 inactive deployment
npm — 2f15ab45 Deployed Jul 22, 2026 by neuromechanist via publish #1807
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