Repository navigation
Description
Summary
Running flowtrace init <slug> from inside an existing Git repository reuses the ancestor repository instead of creating <slug>/.git. If the parent repository already has unrelated staged changes, Flowtrace includes those changes in its automatic initial commit.
This conflicts with the documented "one trace = one git repo" model and with the CLI's promise that commits stage exactly the declared paths.
Minimal reproduction
Using flowtrace 0.1.0 built from current main (1571c76365c02c13d50b943cedd36e3b21865757):
mkdir flowtrace-repro
cd flowtrace-repro
git init
git config user.name "Repro"
git config user.email "[email protected]"
echo "unrelated user work" > pre_staged.txt
git add pre_staged.txt
flowtrace init probe-trace
git show --name-only --pretty=format: HEAD
test -d probe-trace/.git && echo "nested repo exists" || echo "no nested repo"Actual behavior
The Flowtrace-created commit contains both files:
pre_staged.txt
probe-trace/trace.json
probe-trace/.git does not exist; the parent repository's current branch receives the commit. The previously staged user file is no longer merely staged because it has been committed by Flowtrace.
I reproduced this in an isolated repository on Windows 11 with PowerShell, GitHub CLI Git, Rust 1.96.0, and the current main commit above. The behavior follows from platform-independent libgit2 index handling, so it does not appear Windows-specific.
Expected behavior
Either:
flowtrace init probe-tracecreates an independent repository atprobe-trace/.git, matching the documented per-trace repository model; or- ancestor-repository reuse is an intentional, explicit mode, and Flowtrace guarantees that unrelated pre-existing index entries remain staged but are not included in its commit.
At minimum, Flowtrace should refuse to commit when it cannot preserve an already-dirty index safely.
Likely cause
open_or_init calls open(root) first, and Repository::open_ext walks upward to an ancestor repository. Therefore initialization under an existing repository never reaches Repository::init(root).
commit_files then loads the repository's existing index, adds the declared paths, and calls index.write_tree(). Existing staged entries remain in that index and consequently enter the new commit.
Impact
- Unrelated user work can be committed unexpectedly.
- The parent project's branch and history are mutated even though the user asked to initialize a separate trace.
- The resulting commit is authored as Flowtrace's fixed
trace <trace@local>identity, which makes the accidental commit less obvious. - This is especially risky for coding-agent workflows, where users commonly have partially staged work in the active repository.
Suggested regression coverage / fixes
- Add a test with a parent repository containing an unrelated staged file, then initialize a child trace and assert that the parent index and history remain untouched.
- Prefer
Repository::init(root)forflowtrace initunless shared-parent-repository behavior is explicitly requested. - For any intentional shared-repository mode, avoid constructing commits from the user's live index. Use an isolated/in-memory/temporary index based on
HEAD, overlay only declared paths, and leave the user's real index unchanged; alternatively fail clearly when unrelated staged entries exist.
Thanks for open-sourcing Flowtrace—the trace model is useful, and tightening this Git boundary would make it much safer to try inside real coding-agent workflows.
Activity