Skip to content

Commit a796caf

Browse files
Support configured develop trunk
1 parent fb65d02 commit a796caf

7 files changed

Lines changed: 51 additions & 7 deletions

File tree

.changeset/slow-rings-develop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@kitlangton/stack": patch
3+
---
4+
5+
Allow repos to configure trunk branches with `git config stack.trunks`.

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
- Bare `stack sync` must stay non-mutating, including scoped and keep-going runs.
1313
- Mutating commands need an explicit mode: `--apply`, or `merge --auto` for code-host auto-merge plus descendant repair.
14-
- Never mutate trunk branches like `dev`, `main`, or `master`.
14+
- Never mutate configured trunk branches like `dev`, `main`, or `master`.
1515
- Before rebasing a branch, create a local backup branch.
1616
- Before repair mutates Git or a hosted change, save an undo checkpoint. Merge child retargets use a pre-merge recovery journal; after the root lands, descendant repair starts from a post-merge baseline that never retargets children back onto the landed branch.
1717
- `stack undo` should restore the last applied mutation from the saved journal.

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ git config stack.codeHost github # or: gitlab
9999

100100
Use `STACK_CODE_HOST=github|gitlab` for a one-off override.
101101

102+
## Trunk Branches
103+
104+
By default, `stack` treats `dev`, `main`, and `master` as trunk branches. Repos
105+
that use another trunk, such as `develop`, can configure the trunk list:
106+
107+
```bash
108+
git config stack.trunks dev,develop,main,master
109+
```
110+
102111
## Example Output
103112

104113
```text

skills/stack/SKILL.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Install and authenticate the matching CLI before running `stack`. The
1919
`github.com` and `gitlab.com` hosts are detected automatically from `origin`.
2020
For an enterprise host, run `git config stack.codeHost github` or `git config
2121
stack.codeHost gitlab`; `STACK_CODE_HOST` is available as a temporary override.
22+
Repos that use a trunk outside the default `dev`, `main`, and `master` set can
23+
configure trunks with `git config stack.trunks dev,develop,main,master`.
2224

2325
Keep ordinary editing and commits on plain `git`. Use `stack` only for stack
2426
intent, stack inspection, sync, merge, and undo workflows.
@@ -229,7 +231,7 @@ stack blocks.
229231
- `stack merge` is dry-run by default.
230232
- Mutating commands need `--apply`, except `stack merge --auto` waits for the code
231233
host and repairs descendants after the root lands.
232-
- Never mutate trunk branches such as `dev`, `main`, or `master`.
234+
- Never mutate configured trunk branches such as `dev`, `main`, or `master`.
233235
- Before rebasing a branch, the tool creates a local backup branch.
234236
- If output is unclear, inspect with `stack status`, `stack history`, or command
235237
help before applying.

src/cli.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import pkg from "../package.json" with { type: "json" };
1313
import { BranchError, DirtyWorktreeError, ExecError, MergeBaseError } from "./domain/model.ts";
1414
import { renderStatus } from "./format.ts";
1515
import * as Proc from "./platform/proc.ts";
16-
import { StackConfig, trunks } from "./services/Config.ts";
16+
import { parseTrunksConfig, StackConfig, trunks } from "./services/Config.ts";
1717
import { CodeHost } from "./services/CodeHost.ts";
1818
import { CodeHostGitHub } from "./services/code-host/GitHub.ts";
1919
import { CodeHostGitLab } from "./services/code-host/GitLab.ts";
@@ -329,12 +329,19 @@ const live = (() => {
329329

330330
const dir = yield* proc.exec(root, "git", ["rev-parse", "--git-common-dir"]);
331331
const git = path.isAbsolute(dir) ? dir : path.join(root, dir);
332+
const configuredTrunksOut = yield* proc.exec(
333+
root,
334+
"git",
335+
["config", "--get", "stack.trunks"],
336+
[0, 1],
337+
);
338+
const configuredTrunks = parseTrunksConfig(configuredTrunksOut);
332339

333340
return StackConfig.layer({
334341
root,
335342
store: path.join(git, "stack", "state.json"),
336343
journal: path.join(git, "stack", "undo.json"),
337-
trunks,
344+
trunks: configuredTrunks.length > 0 ? configuredTrunks : trunks,
338345
});
339346
}),
340347
).pipe(Layer.provideMerge(proc));

src/services/Config.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ import * as Layer from "effect/Layer";
44
import * as Path from "effect/Path";
55
import { branchName, type BranchName } from "../domain/model.ts";
66

7-
export type Trunk = "dev" | "main" | "master";
7+
export type Trunk = "dev" | "develop" | "main" | "master";
88

9-
export const trunks: ReadonlyArray<Trunk> = ["dev", "main", "master"];
9+
export const trunks: ReadonlyArray<Exclude<Trunk, "develop">> = ["dev", "main", "master"];
10+
11+
export const parseTrunksConfig = (value: string): ReadonlyArray<string> =>
12+
value
13+
.split(/[\s,]+/)
14+
.map((item) => item.trim())
15+
.filter((item) => item.length > 0);
1016

1117
export interface StackConfigService {
1218
readonly root: string;

tests/stack.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import * as Proc from "../src/platform/proc.ts";
2323
import { RepairExecution } from "../src/repairExecution.ts";
2424
import * as StackBlock from "../src/stackBlock.ts";
2525
import * as StackGraph from "../src/stackGraph.ts";
26-
import { StackConfig } from "../src/services/Config.ts";
26+
import { parseTrunksConfig, StackConfig, trunks } from "../src/services/Config.ts";
2727
import { CodeHost } from "../src/services/CodeHost.ts";
2828
import { CodeHostGitHub } from "../src/services/code-host/GitHub.ts";
2929
import { CodeHostGitLab } from "../src/services/code-host/GitLab.ts";
@@ -1105,6 +1105,21 @@ const makeSyncNovel = () => {
11051105
};
11061106
};
11071107

1108+
describe("StackConfig", () => {
1109+
it("does not include develop in default trunks", () => {
1110+
expect(trunks).toEqual(["dev", "main", "master"]);
1111+
});
1112+
1113+
it("parses configured trunks", () => {
1114+
expect(parseTrunksConfig("dev,develop main\nmaster")).toEqual([
1115+
"dev",
1116+
"develop",
1117+
"main",
1118+
"master",
1119+
]);
1120+
});
1121+
});
1122+
11081123
describe("StackGraph", () => {
11091124
it("builds status nodes from explicit and inferred parents", () => {
11101125
const graph = StackGraph.make({

0 commit comments

Comments
 (0)