Skip to content

fix(init-workspace): preserve dangling store pre-commit symlink - #1124

Merged
c-vigo merged 4 commits into
devfrom
bugfix/1117-dangling-store-symlink
Jul 15, 2026
Merged

c-vigo merged 4 commits into
devfrom
bugfix/1117-dangling-store-symlink

Conversation

@c-vigo

@c-vigo c-vigo commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Description

In direnv mode a flake-hooks consumer's .pre-commit-config.yaml is a symlink into the host /nix/store. install.sh runs init-workspace.sh inside the devcontainer image where that store is not mounted, so the symlink is dangling from the container's viewpoint. The preserve/exclude gate used [[ -e ]] (which follows the link), reported the file absent, and rsync -avL wrote the real ~6 KB template over the symlink — which in turn prevented the #1092 ignore auto-seed (its gate is correctly target-based, but the symlink no longer existed when it ran). Net result on every direnv-mode flake-hooks upgrade: a committed, non-ignored template shadowing the flake-generated config. Observed on the vig-os/commit-action 1.2.0 → 1.2.1 upgrade (vig-os/commit-action#80).

Closes #1117

Type of Change

  • feat -- New feature
  • fix -- Bug fix
  • docs -- Documentation only
  • chore -- Maintenance task (deps, config, etc.)
  • refactor -- Code restructuring (no behavior change)
  • test -- Adding or updating tests
  • ci -- CI/CD pipeline changes
  • build -- Build system or dependency changes
  • revert -- Reverts a previous commit
  • style -- Code style (formatting, whitespace)

Modifiers

  • Breaking change (!) -- This change breaks backward compatibility

Changes Made

Changelog Entry

Fixed

Testing

  • Tests pass locally (just test)
  • Manual testing performed (describe below)

Manual Testing Details

  • TDD: both regression tests committed failing (RED — symlink clobbered into a regular file; --preview misclassified as ADDED), turned GREEN by the fix.
  • Full tests/bats/init-workspace.bats: 200 tests, 0 failures, exit 0 (implementation run + independent review run).
  • prek run --all-files: green.

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly (edit docs/templates/, then run just docs)
  • I have updated CHANGELOG.md in the [Unreleased] section (and pasted the entry above)
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Additional Notes

Part of the commit-action-deployment bug batch. Known adjacent, deliberately not fixed here: print_preserved_template_diff still gates on -f, so the #878 divergence diff is not printed for a dangling symlink — harmless (a store symlink has no meaningful template diff and cannot be validated while unmounted). #1111 (root-.gitignore migration, same function) follows in a separate PR after this one merges.

Refs: #1117

c-vigo added 3 commits July 15, 2026 15:30
A flake-hooks consumer's .pre-commit-config.yaml is a symlink into the host
/nix/store, which is not mounted inside the image where init-workspace runs, so
the symlink is dangling from the container's view. The preserve/exclude gate,
the add/preserve report, and the divergence guard tested presence with -e/-f,
which follow the link and reported it absent — so rsync -avL overwrote the
symlink with the template config and the #1092 ignore auto-seed never fired.

Add a path_present helper (-e || -L) that treats a symlink of any kind as
present, and route all three gates through it, so the symlink survives untouched
and the ignore seed still runs.

Refs: #1117
@c-vigo c-vigo self-assigned this Jul 15, 2026
@c-vigo
c-vigo merged commit 71395be into dev Jul 15, 2026
13 checks passed
@c-vigo
c-vigo deleted the bugfix/1117-dangling-store-symlink branch July 15, 2026 14:24
c-vigo added a commit that referenced this pull request Jul 15, 2026
…tignore.project (#1129)

## Description

The #1092 fix made `.gitignore.project` the durable, preserved home for
repo-root ignores, but the upgrade that introduces it seeds it empty:
any root ignores a consumer had previously hand-added directly to the
managed root `.gitignore` (`.DS_Store`, editor/OS cruft, project paths)
were silently dropped when the upgrade regenerated the file from the
template. Of the issue's two suggested fixes, this implements the
preferred one — **auto-migrate** the consumer's lines into
`.gitignore.project` — with the upgrade-note listing as its natural side
output.

Closes #1111

## Type of Change

- [ ] `feat` -- New feature
- [x] `fix` -- Bug fix
- [ ] `docs` -- Documentation only
- [ ] `chore` -- Maintenance task (deps, config, etc.)
- [ ] `refactor` -- Code restructuring (no behavior change)
- [ ] `test` -- Adding or updating tests
- [ ] `ci` -- CI/CD pipeline changes
- [ ] `build` -- Build system or dependency changes
- [ ] `revert` -- Reverts a previous commit
- [ ] `style` -- Code style (formatting, whitespace)

### Modifiers

- [ ] Breaking change (`!`) -- This change breaks backward compatibility

## Changes Made

- `assets/init-workspace.sh`:
- Snapshot the consumer's old root `.gitignore` before the rsync
overwrite (placed with the other pre-overwrite state captures).
- New single-responsibility `migrate_root_gitignore()`, called just
before `render_gitignore()`: appends to `.gitignore.project` every
old-root line that is non-blank, non-comment, not a managed entry
(template base + active language fragments + the #1092 seed), and not
already in `.gitignore.project`. Append-only (never reorders/rewrites
the consumer's existing entries), deduplicated, and idempotent — after
the first migration the lines live in `.gitignore.project`, so later
upgrades re-add nothing. Prints `Migrated N consumer line(s) into
.gitignore.project (#1111):` with the list.
- The migrated lines flow into the regenerated root `.gitignore` via
`render_gitignore()`'s existing `.gitignore.project` append — no
separate write.
- `tests/bats/init-workspace.bats`: three regression tests — migrate
(lines land in `.gitignore.project` and remain effective in the rendered
root `.gitignore`, note printed), idempotence (second upgrade adds
nothing), managed-lines-not-migrated.

## Changelog Entry

### Fixed
- **Migrate hand-added root `.gitignore` lines into `.gitignore.project`
on upgrade** ([#1111](#1111))
- The upgrade that introduced the #1092 `.gitignore.project` seam seeded
it empty, silently dropping any root ignores a consumer had hand-added
to the managed root `.gitignore` (regenerated from the template every
upgrade).
- Consumer-added entries (non-blank, non-comment, not
template/fragment/seed-managed, not already present) are now migrated
append-only into `.gitignore.project` before the render — deduplicated,
idempotent across upgrades, with an upgrade note listing what moved.

## Testing

- [x] Tests pass locally (`just test`)
- [x] Manual testing performed (describe below)

### Manual Testing Details

- TDD: all three regression tests committed failing (RED — no migration:
note absent, `.DS_Store` missing from `.gitignore.project`), turned
GREEN by the fix.
- Full `tests/bats/init-workspace.bats`: 204 tests, 0 failures
(implementation run + independent review run).
- `prek run --all-files`: green (including shellcheck on the new
function).

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have updated the documentation accordingly (edit
`docs/templates/`, then run `just docs`)
- [x] I have updated `CHANGELOG.md` in the `[Unreleased]` section (and
pasted the entry above)
- [x] My changes generate no new warnings or errors
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [x] Any dependent changes have been merged and published

## Additional Notes

Wave 2 of the commit-action-deployment bug batch, branched after #1124
(same `render_gitignore()` region) merged. Deliberate design choice
worth noting: a template example line a consumer *uncommented* (e.g.
activating `.idea/`) migrates into `.gitignore.project` — correct data
preservation, since their active ignore survives the upgrade.

Refs: #1111
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