Skip to content

Commit 379448d

Browse files
committed
Make BuildTree read-only: never write to stack.json from graph/view
BuildTree was silently rewriting orphaned branches to trunk and saving. A read-only command (graph, view) should not mutate state. Now only modifies in-memory config for display, never calls Save().
1 parent 52598c9 commit 379448d

1 file changed

Lines changed: 2 additions & 7 deletions

File tree

internal/stack/tree.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,15 @@ func BuildTree() *BranchStack {
5353
}
5454
}
5555

56-
// Clean stale parent references (parent branch was deleted)
57-
changed := false
56+
// For display purposes, treat branches whose parent was deleted as parented to trunk.
57+
// Do NOT save this - graph is read-only.
5858
for name, meta := range cfg.Branches {
5959
if _, exists := branchSHAs[meta.Parent]; !exists {
60-
// Parent no longer exists, default to trunk
6160
if meta.Parent != mainBranch {
6261
cfg.Branches[name] = &BranchMeta{Parent: mainBranch, ParentHead: meta.ParentHead}
63-
changed = true
6462
}
6563
}
6664
}
67-
if changed {
68-
_ = cfg.Save()
69-
}
7065

7166
// No self-healing: only show branches explicitly in stack.json.
7267
// Use `gx stack` to add branches to the stack.

0 commit comments

Comments
 (0)