Files
josh-sync/Makefile
SBPro dc2cdea360 Release 2.2.0 — unified onboard strategy + safety hardening
Folds `josh-sync adopt` into `josh-sync onboard <target>` as the adopt
strategy alongside the original reset flow. Strategy resolves by
precedence: --mode flag > targets[].history_lock config (preserve|rewrite)
> auto-detect via `git ls-remote --heads`. `josh-sync adopt` is kept as
a thin alias. Adds the new `targets[].history_lock` config field
(validated at parse time) and folds `<target>/adopt.json` state into
`<target>/onboard.json` with a `.strategy` field; legacy state files
are read with a backward-compat fallback.

Safety hardening (from a multi-angle review of the unification):
- auto-detect distinguishes auth/network failure from empty repo
- resume validates --mode against the strategy saved in state
- `josh-sync adopt` rejects a conflicting --mode in the forwarded args
- missing import-PR lookup dies in both strategies (was WARN+continue
  for reset, which could create duplicate import PRs on resume)
- --restart durably removes the legacy adopt.json from the state branch
- adopt_branch is now a subshell function (EXIT trap can't clobber callers)
- strategy value validated after resolve/load (reset|adopt)
- --mode with missing/empty value dies with a usage hint
- migrate-pr against an adopt-strategy target dies with a specific hint
- reset importing asserts archived_url is present (no "null" → git clone)

End-to-end + CLI bats coverage added (tests/unit/adopt_e2e.bats,
tests/unit/cli.bats). 72 tests, shellcheck clean.

Makefile dist bundle header now correctly interpolates VERSION and
line count.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 03:32:04 +01:00

43 lines
1.4 KiB
Makefile

.PHONY: lint test build clean
# Lint all shell scripts with shellcheck
lint:
@echo "Running shellcheck..."
shellcheck -x lib/*.sh bin/josh-sync
@echo "All checks passed."
# Run bats-core unit tests
test:
@echo "Running tests..."
bats tests/unit/
@echo "All tests passed."
# Bundle into a single self-contained script
build: dist/josh-sync
dist/josh-sync: bin/josh-sync lib/*.sh VERSION
@mkdir -p dist
@echo "Bundling josh-sync..."
@echo '#!/usr/bin/env bash' > dist/josh-sync
@echo "# josh-sync $$(cat VERSION) — bundled distribution" >> dist/josh-sync
@echo '# Generated by: make build' >> dist/josh-sync
@echo '' >> dist/josh-sync
@# Inline all library modules (strip shebangs and source directives)
@for f in lib/core.sh lib/config.sh lib/auth.sh lib/state.sh lib/sync.sh lib/adopt.sh lib/onboard.sh; do \
echo "# --- $$f ---" >> dist/josh-sync; \
grep -v '^#!/' "$$f" | grep -v '^# shellcheck source=' >> dist/josh-sync; \
echo '' >> dist/josh-sync; \
done
@# Append CLI (strip shebangs, source directives, and source commands)
@echo '# --- bin/josh-sync ---' >> dist/josh-sync
@grep -v '^#!/' bin/josh-sync \
| grep -v '^# shellcheck source=' \
| grep -v '^source "\$${JOSH_LIB_DIR}/' \
| sed '/^JOSH_LIB_DIR=/,/^source/d' \
>> dist/josh-sync
@chmod +x dist/josh-sync
@echo "Built: dist/josh-sync ($$(wc -l < dist/josh-sync) lines)"
clean:
rm -rf dist/