Skip to content

v1.15.1.0 fix(gstack-slug): subdir guard + .gstack-slug override + --reset (#1125)#1224

Open
gregario wants to merge 2 commits intogarrytan:mainfrom
gregario:fix/1125-gstack-slug-subdir-guard
Open

v1.15.1.0 fix(gstack-slug): subdir guard + .gstack-slug override + --reset (#1125)#1224
gregario wants to merge 2 commits intogarrytan:mainfrom
gregario:fix/1125-gstack-slug-subdir-guard

Conversation

@gregario
Copy link
Copy Markdown
Contributor

Summary

Fixes #1125gstack-slug inherits the outer repo's slug when \$PWD is a subdirectory of a different git repo, then locks the wrong slug into ~/.gstack/slug-cache/ with no recovery path.

Before

$ cd /Users/me/workspace                  # outer repo, origin = me/workspace
$ mkdir IoTopia && cd IoTopia              # standalone project, no .git
$ gstack-slug
SLUG=me-workspace                          # ← wrong: inherited from parent

~/.gstack/projects/me-workspace/ now collects artifacts for an unrelated project. Manual cleanup of both ~/.gstack/projects/ and ~/.gstack/slug-cache/ was needed to recover.

After

$ cd /Users/me/workspace/IoTopia
$ gstack-slug
SLUG=IoTopia                               # ← falls through to basename

# Or, set a per-project override:
$ echo my-real-project > .gstack-slug
$ gstack-slug --reset && gstack-slug
SLUG=my-real-project

Three changes

  1. Subdir guard. Compare git rev-parse --show-toplevel against \$PWD. If they differ, skip the remote-URL inference and fall through to .gstack-slug or basename. Eliminates the silent cross-contamination.
  2. .gstack-slug per-project override. A one-line file in \$PWD (sanitized to [a-zA-Z0-9._-]) wins over git inference. Cheap, explicit, survives gstack-upgrade.
  3. gstack-slug --reset. Removes the cache entry for the current PWD without manual cleanup of ~/.gstack/slug-cache/.

Mirrors the shape of @snowmaker's merged PR #897 (deterministic slugs across sessions): one bin/ script change, one regression test file, zero behavior change for the happy path.

Test plan

  • bun test test/gstack-slug.test.ts — 10 cases pass
    • Subdir guard regression (the reproducer from the issue)
    • PWD at toplevel still inherits remote slug (happy path unchanged)
    • No git repo at all falls back to basename (happy path unchanged)
    • .gstack-slug override at toplevel and in subdir
    • Override input sanitization (rejects ;, spaces, multi-line)
    • --reset clears the cache file; no-op when cache absent
    • Cache stability: cached slug persists when remote disappears
  • bun test (full free suite) — green
  • No changes to existing happy-path behavior

Files

  • bin/gstack-slug — fix
  • test/gstack-slug.test.ts — new, 10 cases
  • VERSION, CHANGELOG.md — release v1.15.1.0

🤖 Generated with Claude Code

gregario and others added 2 commits April 26, 2026 20:38
Fixes garrytan#1125.

`bin/gstack-slug` derives the project slug from `git remote get-url origin`,
which walks up parent directories. A standalone project living inside an
outer git repo silently inherited the outer's slug, contaminating
`~/.gstack/projects/{slug}/` with cross-project artifacts. The cache had
no invalidation path, so once wrong, it stayed wrong.

Three changes:

1. Subdir guard. Compare `git rev-parse --show-toplevel` against `$PWD`.
   When they differ, skip the remote-URL inference and fall through to
   `.gstack-slug` or basename. Eliminates the silent cross-contamination.

2. Per-project override. A `.gstack-slug` file in `$PWD` (one line,
   sanitized to [a-zA-Z0-9._-]) wins over git inference. Cheap,
   explicit, survives gstack-upgrade.

3. `--reset` flag. Removes the cache entry for the current PWD so users
   can recover from a previously-poisoned slug without manual cleanup of
   `~/.gstack/slug-cache/`.

Tests cover the regression (subdir does not inherit outer remote), both
override paths (toplevel and subdir), input sanitization, --reset
behavior, and cache stability across runs.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

gstack-slug inherits outer-repo slug when project is a subdirectory; cache is unrecoverable

1 participant