@danielstyle/featflow 0.6.4 → 0.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/README.zh-CN.md +6 -4
- package/bin/featflow.mjs +4 -0
- package/package.json +1 -1
- package/skills/featflow/SKILL.md +2 -1
- package/src/commands/finish.mjs +35 -3
- package/src/commands/status.mjs +17 -0
- package/src/commands/sync-dev.mjs +400 -0
- package/src/commands/worktree.mjs +38 -2
- package/src/config.mjs +34 -0
package/README.md
CHANGED
|
@@ -133,7 +133,8 @@ main (release, protected)
|
|
|
133
133
|
|
|
134
134
|
- Run once per checkout: `featflow setup alice` (auto-fetches remote branches, interactively offers to bootstrap a missing `origin/dev` — or pass `--bootstrap-integration` — creates/tracks `alice` from `origin/dev`, saves `git config featflow.developerBranch alice`, and enables hooks). `featflow init` can also trigger this step directly in `developer-branch` mode.
|
|
135
135
|
- Daily tasks branch from `alice` as `<prefix>/alice-<task>` (never `alice/...`, because Git cannot store both `alice` and `alice/...` refs simultaneously).
|
|
136
|
-
- `featflow
|
|
136
|
+
- `featflow sync-dev` syncs the latest `origin/dev` back into `alice` (also runs automatically before `featflow worktree` and `featflow finish` by default; aborts cleanly on merge conflicts and can be skipped with `--no-sync-dev` or configured via `syncIntegration` in `.featflow.json`).
|
|
137
|
+
- `featflow finish feat/alice-oauth-pkce` syncs `origin/dev` into `alice`, merges into `alice`, pushes `alice`, removes the clean task worktree and local branch, and never merges directly into `dev` or `main`.
|
|
137
138
|
- Team integration (`alice -> dev`) and release promotion (`dev -> main`) happen via explicit pull requests.
|
|
138
139
|
|
|
139
140
|
---
|
|
@@ -147,10 +148,11 @@ main (release, protected)
|
|
|
147
148
|
| `featflow hooks <install\|uninstall\|status>` | Manage Git hooks: `--local` (default) adds/removes fenced blocks inside `.git/hooks/` without modifying repo files or overwriting custom hooks; `--repo` installs tracked `.githooks/`. |
|
|
148
149
|
| `featflow init [options]` | Auto-detect repo config, inject managed `AGENTS.md`/`CLAUDE.md` block, check global Skills & CLI readiness, and interactively pick guardrails & AI coding-agent hooks with arrow-key single/multi-select prompts. Reuses global Skills by default (pass `--with-repo-skills` to embed `.agents/skills/` in the repo, or `--install-global-skills` to auto-sync global skills). Supports `--preset <minimal\|standard\|full>`, `--minimal`, `--merge`, `--with-codex-agents`, `--agent-hooks <antigravity,claude-code,codex,cursor\|all\|none>`, and `--yes`. |
|
|
149
150
|
| `featflow sync [options]` | Sync repo-managed templates, `.githooks/`, `AGENTS.md`/`CLAUDE.md` blocks, and repo-embedded Skills (when present or opted in via `--with-repo-skills`) without modifying `.featflow.json`, feature records, or custom doc content. Pass `--check` in CI to fail on drift, or `--only skill,issues-skill,regression-skill,templates,githooks,agent-docs`. |
|
|
151
|
+
| `featflow sync-dev [options]` | Sync the shared integration branch (e.g. `origin/dev`) back into your personal developer branch in `developer-branch` mode (`--no-push`, `--abort-on-conflict`, `--dry-run`). |
|
|
150
152
|
| `featflow setup [dev-branch]` | Configure personal developer branch (in `developer-branch` mode), auto-fetch remote branches, optionally bootstrap a missing integration branch (`--bootstrap-integration`), and safely enable Git hooks without clobbering Husky/Lefthook. |
|
|
151
|
-
| `featflow status` | Inspect workflow mode, branch/remote status, all worktrees, active/paused feature records, and next recommended step. |
|
|
152
|
-
| `featflow worktree <branch> [path] [base]` | Create a typed task branch in a dedicated sibling worktree and run configured `postWorktreeCreate` commands. |
|
|
153
|
-
| `featflow finish <branch>` | Merge/push a verified task branch, safely exit the task worktree, delete the clean worktree & local branch, and prune other merged task branches. Supports `--no-push`, `--pr`, `--dry-run`, `--keep-worktree`, `--keep-branch`. |
|
|
153
|
+
| `featflow status` | Inspect workflow mode, branch/remote status, commits behind `origin/dev`, all worktrees, active/paused feature records, and next recommended step. |
|
|
154
|
+
| `featflow worktree <branch> [path] [base]` | Create a typed task branch in a dedicated sibling worktree (auto-syncing `origin/dev` into your developer branch first in `developer-branch` mode; `--no-sync-dev` to skip) and run configured `postWorktreeCreate` commands. |
|
|
155
|
+
| `featflow finish <branch>` | Merge/push a verified task branch (auto-syncing `origin/dev` in `developer-branch` mode), safely exit the task worktree, delete the clean worktree & local branch, and prune other merged task branches. Supports `--no-push`, `--no-sync-dev`, `--pr`, `--dry-run`, `--keep-worktree`, `--keep-branch`. |
|
|
154
156
|
| `featflow issue <subcommand>` | Optional GitHub Issues closed-loop CLI (`create`, `list`, `view`, `claim`, `review`, `release`, `labels:sync`) powered by `gh`. Atomically preflights worktree creation before claiming, supports optional screenshot uploads via `issues.assetsRepo`, and syncs optional `featflow-issues` Skill via `featflow init --with-issues` / `featflow sync`. |
|
|
155
157
|
| `featflow size-check [options]` | Optional multi-language file line-count budget checker with legacy baseline ratchet (`--changed`, `--update-baseline`, `--json`), configured via `fileSizeBudget` in `.featflow.json`. |
|
|
156
158
|
| `featflow regression <impact\|check\|validate>` | Optional Regression Guardian CLI for YAML/JSON regression ledgers (`regression.ledgerFile`): find impacted bug invariants for changed files, run guard commands, or validate ledger integrity. |
|
package/README.zh-CN.md
CHANGED
|
@@ -133,7 +133,8 @@ main (发布分支,受保护)
|
|
|
133
133
|
|
|
134
134
|
- 每个本地克隆首次执行一次:`featflow setup alice`(自动 fetch 远端分支,若远端缺少 `origin/dev` 会交互引导创建并推送——或传 `--bootstrap-integration`——随后基于 `origin/dev` 创建/跟踪 `alice`,写入 `git config featflow.developerBranch alice`,并安全启用 hooks)。在 `developer-branch` 模式下运行 `featflow init` 也可直接联动完成此步骤。
|
|
135
135
|
- 日常任务从 `alice` 分叉,命名为 `<prefix>/alice-<task>`(不要用 `alice/...`,因为 Git 不允许同名分支与命名空间前缀并存)。
|
|
136
|
-
- `featflow
|
|
136
|
+
- `featflow sync-dev` 可随时将最新 `origin/dev` 同步回 `alice`(默认也会在 `featflow worktree` 和 `featflow finish` 前自动执行;遇冲突自动 `git merge --abort` 安全中止,可用 `--no-sync-dev` 单次跳过或在 `.featflow.json` 的 `syncIntegration` 中配置)。
|
|
137
|
+
- `featflow finish feat/alice-oauth-pkce` 先同步 `origin/dev` 到 `alice`,再合并并推送 `alice`,清理干净的任务 worktree 与本地分支,**绝不直接改动 `dev` 或 `main`**。
|
|
137
138
|
- 需要团队集成(`alice -> dev`)或发布(`dev -> main`)时再显式提 PR。
|
|
138
139
|
|
|
139
140
|
---
|
|
@@ -147,10 +148,11 @@ main (发布分支,受保护)
|
|
|
147
148
|
| `featflow hooks <install\|uninstall\|status>` | 管理 Git hooks:`--local`(默认)在 `.git/hooks/` 中无损增删托管块,保留已有自定义 hook 且不改仓库文件;`--repo` 生成入库的 `.githooks/`。 |
|
|
148
149
|
| `featflow init` | 自动探测项目配置、无损注入 `AGENTS.md`/`CLAUDE.md` 托管块、体检全局 Skill 与 CLI 就绪状态,并在 TTY 下提供方向键单选与多选勾选框。默认直接复用全局 Skills(需入库可显式加 `--with-repo-skills`,非交互自动同步全局可加 `--install-global-skills`)。支持 `--preset <minimal\|standard\|full>`、`--minimal`、`--merge`、`--with-codex-agents`、`--agent-hooks <antigravity,claude-code,codex,cursor\|all\|none>` 与 `--yes`。 |
|
|
149
150
|
| `featflow sync` | 从当前安装的 `featflow` 同步更新项目内模板、`.githooks/`、`AGENTS.md`/`CLAUDE.md` 托管块,以及已入库(或显式 `--with-repo-skills`)的项目级 Skill,不改动 `.featflow.json`、已有记录及托管块外自定义文档。支持 `--check` 放进 CI 防漂移、`--only skill,issues-skill,regression-skill,templates,githooks,agent-docs` 按需同步。 |
|
|
151
|
+
| `featflow sync-dev` | 在 `developer-branch` 模式下将最新集成分支(如 `origin/dev`)安全合并回个人开发分支(支持 `--no-push`、`--abort-on-conflict`、`--dry-run`)。 |
|
|
150
152
|
| `featflow setup [branch]` | 初始化个人开发分支(`developer-branch` 模式)、自动 fetch 远端分支、按需引导创建缺失的集成分支(`--bootstrap-integration`)并安全配置 Git hooks。 |
|
|
151
|
-
| `featflow status` |
|
|
152
|
-
| `featflow worktree <branch>` | 为任务分支创建独立 worktree
|
|
153
|
-
| `featflow finish <branch>` |
|
|
153
|
+
| `featflow status` | 查看当前模式、分支状态、落后 `origin/dev` 提交数、所有 worktree、进行中/暂停中的 feature 记录和下一步建议。 |
|
|
154
|
+
| `featflow worktree <branch>` | 为任务分支创建独立 worktree(`developer-branch` 模式下默认先将 `origin/dev` 同步回个人开发分支,可用 `--no-sync-dev` 跳过),并自动执行 `.featflow.json` 中配置的 `postWorktreeCreate` 命令。 |
|
|
155
|
+
| `featflow finish <branch>` | 完成并收尾任务分支(`developer-branch` 模式下默认先同步 `origin/dev`,再合并/推送、自动切出待删 worktree、移除干净 worktree 与本地分支)。支持 `--no-push`、`--no-sync-dev`、`--pr`、`--dry-run`、`--keep-worktree`、`--keep-branch`。 |
|
|
154
156
|
| `featflow issue <subcommand>` | 可选的 GitHub Issues 闭环 CLI(`create` / `list` / `view` / `claim` / `review` / `release` / `labels:sync`,仅在调用时依赖 `gh`)。认领前先预检本地 worktree 再改远端状态,支持通过 `.featflow.json` 的 `issues.assetsRepo` 托管截图,并可通过 `featflow init --with-issues` / `featflow sync` 同步可选 `featflow-issues` Skill。 |
|
|
155
157
|
| `featflow size-check [options]` | 可选的多语言文件行数预算守卫(支持历史基线只减不增棘轮、`--changed`、`--update-baseline`、`--json` 及 `post-tool-use` / `pre-commit` 即时拦截),通过 `.featflow.json` 的 `fileSizeBudget` 按需启用。 |
|
|
156
158
|
| `featflow regression <impact\|check\|validate>` | 可选的回归守卫账本 CLI(支持 YAML/JSON 账本):按改动文件检索命中的历史 Bug 不变量、运行守卫命令或校验账本完整性,配套可选 `featflow-regression` Skill。 |
|
package/bin/featflow.mjs
CHANGED
|
@@ -21,6 +21,7 @@ import { runSetup } from "../src/commands/setup.mjs";
|
|
|
21
21
|
import { runSizeCheck } from "../src/commands/size-check.mjs";
|
|
22
22
|
import { runSkills } from "../src/commands/skills.mjs";
|
|
23
23
|
import { runStatus } from "../src/commands/status.mjs";
|
|
24
|
+
import { runSyncDev } from "../src/commands/sync-dev.mjs";
|
|
24
25
|
import { runSync } from "../src/commands/sync.mjs";
|
|
25
26
|
import { runVerify } from "../src/commands/verify.mjs";
|
|
26
27
|
import { runWorktree } from "../src/commands/worktree.mjs";
|
|
@@ -39,6 +40,7 @@ Commands:
|
|
|
39
40
|
hooks Install/uninstall/inspect Git hooks (--local into .git/hooks/ or --repo into .githooks/)
|
|
40
41
|
init Auto-detect repo config, inject AGENTS.md block, and scaffold featflow (--minimal for lightweight)
|
|
41
42
|
sync Sync managed Skill, templates, .githooks, and AGENTS.md blocks (--check for CI)
|
|
43
|
+
sync-dev Sync integration branch (e.g. origin/dev) back into your personal developer branch
|
|
42
44
|
setup Configure developer branch (if applicable) and safely enable Git hooks
|
|
43
45
|
status Show workflow mode, branch/worktree state, active features, and next step
|
|
44
46
|
worktree Create a typed task branch in a dedicated Git worktree
|
|
@@ -68,6 +70,8 @@ const commands = {
|
|
|
68
70
|
hooks: runHooks,
|
|
69
71
|
init: runInit,
|
|
70
72
|
sync: runSync,
|
|
73
|
+
"sync-dev": runSyncDev,
|
|
74
|
+
"sync-integration": runSyncDev,
|
|
71
75
|
setup: runSetup,
|
|
72
76
|
status: runStatus,
|
|
73
77
|
worktree: runWorktree,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danielstyle/featflow",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
4
4
|
"description": "AI-native feature workflow: Skill + CLI + Git/Agent Hooks for discovery-first planning, Git worktree isolation, GitHub Issues closed loop, and safe branch lifecycles.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/skills/featflow/SKILL.md
CHANGED
|
@@ -45,8 +45,9 @@ Inspect `.featflow.json` (or run `featflow status`) to determine the repository'
|
|
|
45
45
|
- **`developer-branch` mode (team workflow)**:
|
|
46
46
|
- Protected branches: `main` (release) and `dev` (team integration).
|
|
47
47
|
- Personal developer branch: stored in `git config featflow.developerBranch` (configured once via `featflow setup <name>`).
|
|
48
|
+
- Integration sync: `featflow sync-dev` merges the latest `origin/dev` into your personal developer branch; `featflow worktree` and `featflow finish` also auto-sync `origin/dev` into your developer branch by default (cleanly aborting with `git merge --abort` on conflicts; configurable via `.featflow.json` `syncIntegration` or skipped once with `--no-sync-dev`).
|
|
48
49
|
- Task branch format: `<prefix>/<developer>-<short-kebab-title>` (e.g., `feat/alice-oauth-pkce`). Never use `<developer>/...` because Git cannot store both `<developer>` and `<developer>/...` refs simultaneously.
|
|
49
|
-
- Finish: `featflow finish <branch>`
|
|
50
|
+
- Finish: `featflow finish <branch>` syncs `origin/dev` into the personal developer branch, merges the task branch, pushes it (unless `--no-push`), and removes the clean worktree and local task branch. Open `<developer> -> dev` or `dev -> main` PRs only when the user explicitly requests team integration or release promotion.
|
|
50
51
|
|
|
51
52
|
## Branch Prefix Policy
|
|
52
53
|
|
package/src/commands/finish.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
|
|
3
|
-
import { loadConfig, resolveWorktreeParent } from "../config.mjs";
|
|
3
|
+
import { loadConfig, resolveSyncIntegrationConfig, resolveWorktreeParent } from "../config.mjs";
|
|
4
4
|
import {
|
|
5
5
|
ensureCleanWorktree,
|
|
6
6
|
fail,
|
|
@@ -17,14 +17,16 @@ import {
|
|
|
17
17
|
} from "../git.mjs";
|
|
18
18
|
import { setupInstructions } from "../policy.mjs";
|
|
19
19
|
import { cleanupMergedTaskBranches } from "./cleanup.mjs";
|
|
20
|
+
import { syncDeveloperBranchWithIntegration } from "./sync-dev.mjs";
|
|
20
21
|
|
|
21
22
|
const usage = `
|
|
22
23
|
Usage:
|
|
23
24
|
featflow finish <task-branch> [options]
|
|
24
25
|
|
|
25
26
|
Completes a verified task branch:
|
|
26
|
-
- In developer-branch mode:
|
|
27
|
-
|
|
27
|
+
- In developer-branch mode: syncs the integration branch (e.g. origin/dev)
|
|
28
|
+
into your personal developer branch (unless --no-sync-dev or --no-push),
|
|
29
|
+
merges the task branch, pushes it, and removes the clean task worktree & branch.
|
|
28
30
|
- In trunk mode (finishTarget=merge): merges into baseBranch, pushes if remote exists
|
|
29
31
|
(unless --no-push), and removes the clean task worktree & branch.
|
|
30
32
|
- In trunk mode (finishTarget=pr or --pr): pushes the task branch so you can open a PR,
|
|
@@ -36,6 +38,7 @@ Options:
|
|
|
36
38
|
--worktree <path> Override the task worktree path.
|
|
37
39
|
--pr Push task branch for a pull request instead of merging locally.
|
|
38
40
|
--no-push Skip fetching from and pushing to the remote.
|
|
41
|
+
--no-sync-dev Skip syncing the integration branch into your developer branch.
|
|
39
42
|
--dry-run Print mutating commands without running them.
|
|
40
43
|
--keep-worktree Do not remove the task worktree.
|
|
41
44
|
--keep-branch Do not delete the local task branch.
|
|
@@ -49,6 +52,7 @@ function parseArgs(argv) {
|
|
|
49
52
|
keepBranch: false,
|
|
50
53
|
keepWorktree: false,
|
|
51
54
|
noPush: false,
|
|
55
|
+
noSyncDev: false,
|
|
52
56
|
pr: false,
|
|
53
57
|
remote: "",
|
|
54
58
|
taskBranch: "",
|
|
@@ -70,6 +74,10 @@ function parseArgs(argv) {
|
|
|
70
74
|
options.noPush = true;
|
|
71
75
|
continue;
|
|
72
76
|
}
|
|
77
|
+
if (arg === "--no-sync-dev") {
|
|
78
|
+
options.noSyncDev = true;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
73
81
|
if (arg === "--pr") {
|
|
74
82
|
options.pr = true;
|
|
75
83
|
continue;
|
|
@@ -198,6 +206,30 @@ export async function runFinish(argv) {
|
|
|
198
206
|
}
|
|
199
207
|
}
|
|
200
208
|
|
|
209
|
+
const syncCfg = resolveSyncIntegrationConfig(config);
|
|
210
|
+
if (
|
|
211
|
+
config.mode === "developer-branch" &&
|
|
212
|
+
syncCfg.onFinish &&
|
|
213
|
+
!options.noSyncDev &&
|
|
214
|
+
!options.noPush
|
|
215
|
+
) {
|
|
216
|
+
try {
|
|
217
|
+
syncDeveloperBranchWithIntegration(repoRoot, config, {
|
|
218
|
+
developer: targetBranch,
|
|
219
|
+
remote,
|
|
220
|
+
targetWorktreePath: targetWorktree.path,
|
|
221
|
+
dryRun: options.dryRun,
|
|
222
|
+
dryRunMissing: Boolean(targetWorktree.dryRunMissing),
|
|
223
|
+
fetch: hasRemote,
|
|
224
|
+
push: false,
|
|
225
|
+
abortOnConflict: true,
|
|
226
|
+
skipIfMissingIntegration: true,
|
|
227
|
+
});
|
|
228
|
+
} catch (error) {
|
|
229
|
+
fail(error instanceof Error ? error.message : String(error));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
201
233
|
// Move out of task worktree BEFORE merging so post-merge hooks & worktree removal succeed
|
|
202
234
|
if (taskWorktree && !options.keepWorktree && isInsidePath(process.cwd(), taskWorktree.path)) {
|
|
203
235
|
process.chdir(targetWorktree.path);
|
package/src/commands/status.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
} from "../git.mjs";
|
|
12
12
|
import { listFeatureFiles } from "../plan.mjs";
|
|
13
13
|
import { setupInstructions } from "../policy.mjs";
|
|
14
|
+
import { countCommitsBehind } from "./sync-dev.mjs";
|
|
14
15
|
|
|
15
16
|
const usage = `
|
|
16
17
|
Usage:
|
|
@@ -80,6 +81,22 @@ export async function runStatus(argv) {
|
|
|
80
81
|
}
|
|
81
82
|
const devWt = findWorktreeForBranch(worktrees, devBranch);
|
|
82
83
|
console.log(`Developer worktree: ${devWt?.path ?? "(not checked out)"}`);
|
|
84
|
+
const integrationRef =
|
|
85
|
+
hasRemote && remoteTrackingBranchExists(config.remote, config.integrationBranch, repoRoot)
|
|
86
|
+
? `${config.remote}/${config.integrationBranch}`
|
|
87
|
+
: localBranchExists(config.integrationBranch, repoRoot)
|
|
88
|
+
? config.integrationBranch
|
|
89
|
+
: "";
|
|
90
|
+
if (integrationRef && localBranchExists(devBranch, repoRoot)) {
|
|
91
|
+
const behind = countCommitsBehind(devBranch, integrationRef, repoRoot);
|
|
92
|
+
if (behind !== null) {
|
|
93
|
+
console.log(
|
|
94
|
+
behind > 0
|
|
95
|
+
? `Sync with ${integrationRef}: behind by ${String(behind)} commit(s) (run \`featflow sync-dev\`)`
|
|
96
|
+
: `Sync with ${integrationRef}: up to date`,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
83
100
|
}
|
|
84
101
|
|
|
85
102
|
console.log(`Worktrees (${worktrees.length}):`);
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
import { loadConfig } from "../config.mjs";
|
|
7
|
+
import {
|
|
8
|
+
ensureCleanWorktree,
|
|
9
|
+
fail,
|
|
10
|
+
findWorktreeForBranch,
|
|
11
|
+
formatCommand,
|
|
12
|
+
gitConfigGet,
|
|
13
|
+
gitWorktrees,
|
|
14
|
+
isAncestor,
|
|
15
|
+
localBranchExists,
|
|
16
|
+
remoteExists,
|
|
17
|
+
remoteTrackingBranchExists,
|
|
18
|
+
runReadSoft,
|
|
19
|
+
runWrite,
|
|
20
|
+
statusShort,
|
|
21
|
+
} from "../git.mjs";
|
|
22
|
+
import { setupInstructions } from "../policy.mjs";
|
|
23
|
+
|
|
24
|
+
const usage = `
|
|
25
|
+
Usage:
|
|
26
|
+
featflow sync-dev [options]
|
|
27
|
+
|
|
28
|
+
Syncs the shared integration branch (for example origin/dev) back into your
|
|
29
|
+
personal developer branch in developer-branch mode.
|
|
30
|
+
|
|
31
|
+
Options:
|
|
32
|
+
--developer <branch> Override configured developer branch.
|
|
33
|
+
--remote <name> Remote to fetch/push. Defaults to config.remote.
|
|
34
|
+
--no-push Merge locally without pushing the developer branch.
|
|
35
|
+
--abort-on-conflict Automatically run "git merge --abort" if conflicts occur.
|
|
36
|
+
--dry-run Print mutating commands without executing them.
|
|
37
|
+
-h, --help Show this help.
|
|
38
|
+
`.trim();
|
|
39
|
+
|
|
40
|
+
function parseArgs(argv) {
|
|
41
|
+
const options = {
|
|
42
|
+
abortOnConflict: false,
|
|
43
|
+
developer: "",
|
|
44
|
+
dryRun: false,
|
|
45
|
+
noPush: false,
|
|
46
|
+
remote: "",
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
50
|
+
const arg = argv[i];
|
|
51
|
+
if (arg === "-h" || arg === "--help") {
|
|
52
|
+
console.log(usage);
|
|
53
|
+
process.exit(0);
|
|
54
|
+
}
|
|
55
|
+
if (arg === "--dry-run") {
|
|
56
|
+
options.dryRun = true;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (arg === "--no-push") {
|
|
60
|
+
options.noPush = true;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (arg === "--abort-on-conflict") {
|
|
64
|
+
options.abortOnConflict = true;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (arg === "--developer" || arg === "--remote") {
|
|
68
|
+
const value = argv[++i] ?? "";
|
|
69
|
+
if (!value) {
|
|
70
|
+
fail(`Missing value for ${arg}.`, usage);
|
|
71
|
+
}
|
|
72
|
+
options[arg.slice(2)] = value;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (arg.startsWith("--developer=") || arg.startsWith("--remote=")) {
|
|
76
|
+
const idx = arg.indexOf("=");
|
|
77
|
+
const key = arg.slice(2, idx);
|
|
78
|
+
const value = arg.slice(idx + 1);
|
|
79
|
+
if (!value) {
|
|
80
|
+
fail(`Missing value for --${key}.`, usage);
|
|
81
|
+
}
|
|
82
|
+
options[key] = value;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
fail(`Unknown option: ${arg}`, usage);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return options;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function runGitAction(args, cwd, { dryRun = false, silent = false } = {}) {
|
|
92
|
+
if (dryRun) {
|
|
93
|
+
if (!silent) {
|
|
94
|
+
runWrite("git", args, cwd, { dryRun: true });
|
|
95
|
+
}
|
|
96
|
+
return { status: 0, stdout: "", stderr: "" };
|
|
97
|
+
}
|
|
98
|
+
const result = spawnSync("git", args, {
|
|
99
|
+
cwd,
|
|
100
|
+
encoding: "utf8",
|
|
101
|
+
stdio: silent ? ["ignore", "pipe", "pipe"] : "inherit",
|
|
102
|
+
});
|
|
103
|
+
if (result.error) {
|
|
104
|
+
throw new Error(`${formatCommand("git", args)} failed: ${result.error.message}`);
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
status: result.status ?? 1,
|
|
108
|
+
stdout: (result.stdout ?? "").trim(),
|
|
109
|
+
stderr: (result.stderr ?? "").trim(),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function listConflictedFiles(cwd) {
|
|
114
|
+
const res = runReadSoft("git", ["diff", "--name-only", "--diff-filter=U"], cwd);
|
|
115
|
+
if (res.status !== 0 || !res.stdout) {
|
|
116
|
+
return [];
|
|
117
|
+
}
|
|
118
|
+
return res.stdout
|
|
119
|
+
.split(/\r?\n/)
|
|
120
|
+
.map((line) => line.trim())
|
|
121
|
+
.filter(Boolean);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function countCommitsBehind(targetRef, baseRef, cwd) {
|
|
125
|
+
const res = runReadSoft("git", ["rev-list", "--count", `${targetRef}..${baseRef}`], cwd);
|
|
126
|
+
if (res.status !== 0 || !res.stdout) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
const count = Number(res.stdout);
|
|
130
|
+
return Number.isFinite(count) ? count : null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function createTempDeveloperWorktree(repoRoot, devBranch) {
|
|
134
|
+
const tempParent = mkdtempSync(path.join(tmpdir(), "featflow-sync-dev-"));
|
|
135
|
+
const tempWorktree = path.join(tempParent, "wt");
|
|
136
|
+
const addRes = runGitAction(["worktree", "add", tempWorktree, devBranch], repoRoot, { silent: true });
|
|
137
|
+
if (addRes.status !== 0) {
|
|
138
|
+
rmSync(tempParent, { force: true, recursive: true });
|
|
139
|
+
throw new Error(
|
|
140
|
+
`Failed to prepare temporary worktree for "${devBranch}"${addRes.stderr ? `:\n${addRes.stderr}` : "."}`,
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
path: tempWorktree,
|
|
145
|
+
cleanup() {
|
|
146
|
+
runGitAction(["worktree", "remove", "--force", tempWorktree], repoRoot, { silent: true });
|
|
147
|
+
rmSync(tempParent, { force: true, recursive: true });
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Safely syncs `integrationBranch` (e.g. `origin/dev`) into the configured
|
|
154
|
+
* personal developer branch (e.g. `daniel`).
|
|
155
|
+
*/
|
|
156
|
+
export function syncDeveloperBranchWithIntegration(repoRoot, config, options = {}) {
|
|
157
|
+
const silent = Boolean(options.silent);
|
|
158
|
+
const dryRun = Boolean(options.dryRun);
|
|
159
|
+
const log = (msg) => {
|
|
160
|
+
if (!silent) {
|
|
161
|
+
console.log(msg);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const warn = (msg) => {
|
|
165
|
+
if (!silent) {
|
|
166
|
+
console.warn(msg);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
if (config.mode !== "developer-branch") {
|
|
171
|
+
if (options.strictMode) {
|
|
172
|
+
throw new Error(
|
|
173
|
+
`featflow sync-dev is only available in developer-branch mode (current mode: "${config.mode}").`,
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
return { status: "skipped", reason: "not-developer-branch-mode" };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const integrationBranch = config.integrationBranch || config.baseBranch || "dev";
|
|
180
|
+
const remote = options.remote || config.remote || "origin";
|
|
181
|
+
const devBranch = options.developer || gitConfigGet(config.developerBranchConfigKey, repoRoot);
|
|
182
|
+
|
|
183
|
+
if (!devBranch) {
|
|
184
|
+
throw new Error(setupInstructions(config));
|
|
185
|
+
}
|
|
186
|
+
if (devBranch === integrationBranch) {
|
|
187
|
+
return { status: "skipped", reason: "same-branch", devBranch, integrationRef: integrationBranch };
|
|
188
|
+
}
|
|
189
|
+
if (!localBranchExists(devBranch, repoRoot)) {
|
|
190
|
+
throw new Error(`Local developer branch "${devBranch}" does not exist.`);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const existingDevWorktree =
|
|
194
|
+
options.targetWorktreePath || findWorktreeForBranch(gitWorktrees(repoRoot), devBranch)?.path || "";
|
|
195
|
+
const gitCwd = existingDevWorktree || repoRoot;
|
|
196
|
+
|
|
197
|
+
if (existingDevWorktree && !options.dryRunMissing) {
|
|
198
|
+
const dirty = statusShort(existingDevWorktree);
|
|
199
|
+
if (dirty) {
|
|
200
|
+
if (options.skipIfDirty) {
|
|
201
|
+
warn(
|
|
202
|
+
`Note: developer worktree ${existingDevWorktree} has uncommitted changes; skipping auto-sync with ${remote}/${integrationBranch}.`,
|
|
203
|
+
);
|
|
204
|
+
return { status: "skipped", reason: "dirty-worktree", devBranch };
|
|
205
|
+
}
|
|
206
|
+
ensureCleanWorktree(existingDevWorktree, "developer");
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const hasRemote = remoteExists(remote, gitCwd);
|
|
211
|
+
const shouldFetch = hasRemote && options.fetch !== false;
|
|
212
|
+
|
|
213
|
+
if (shouldFetch) {
|
|
214
|
+
const fetchInt = runGitAction(["fetch", remote, integrationBranch], gitCwd, {
|
|
215
|
+
dryRun,
|
|
216
|
+
silent: dryRun ? silent : true,
|
|
217
|
+
});
|
|
218
|
+
if (fetchInt.status !== 0) {
|
|
219
|
+
if (options.bestEffortFetch) {
|
|
220
|
+
warn(`Warning: could not fetch ${remote}/${integrationBranch}; continuing with local refs.`);
|
|
221
|
+
} else {
|
|
222
|
+
throw new Error(
|
|
223
|
+
`Failed to fetch ${remote}/${integrationBranch}${fetchInt.stderr ? `:\n${fetchInt.stderr}` : "."}`,
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const fetchDev = runGitAction(["fetch", remote, devBranch], gitCwd, {
|
|
229
|
+
dryRun,
|
|
230
|
+
silent: dryRun ? silent : true,
|
|
231
|
+
});
|
|
232
|
+
if (
|
|
233
|
+
!dryRun &&
|
|
234
|
+
fetchDev.status === 0 &&
|
|
235
|
+
remoteTrackingBranchExists(remote, devBranch, gitCwd) &&
|
|
236
|
+
!isAncestor(`${remote}/${devBranch}`, devBranch, gitCwd)
|
|
237
|
+
) {
|
|
238
|
+
if (existingDevWorktree) {
|
|
239
|
+
const ffRes = runGitAction(["merge", "--ff-only", `${remote}/${devBranch}`], existingDevWorktree, {
|
|
240
|
+
dryRun,
|
|
241
|
+
silent,
|
|
242
|
+
});
|
|
243
|
+
if (ffRes.status !== 0) {
|
|
244
|
+
throw new Error(
|
|
245
|
+
`Local "${devBranch}" has diverged from "${remote}/${devBranch}". Reconcile "${devBranch}" with "${remote}/${devBranch}" before syncing ${integrationBranch}.`,
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
} else if (isAncestor(devBranch, `${remote}/${devBranch}`, gitCwd)) {
|
|
249
|
+
runGitAction(["branch", "-f", devBranch, `${remote}/${devBranch}`], gitCwd, { dryRun, silent });
|
|
250
|
+
} else {
|
|
251
|
+
throw new Error(
|
|
252
|
+
`Local "${devBranch}" has diverged from "${remote}/${devBranch}". Switch to "${devBranch}" and reconcile before syncing ${integrationBranch}.`,
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
let integrationRef = "";
|
|
259
|
+
if (hasRemote && remoteTrackingBranchExists(remote, integrationBranch, gitCwd)) {
|
|
260
|
+
integrationRef = `${remote}/${integrationBranch}`;
|
|
261
|
+
} else if (!hasRemote && localBranchExists(integrationBranch, gitCwd)) {
|
|
262
|
+
integrationRef = integrationBranch;
|
|
263
|
+
} else if (dryRun && hasRemote) {
|
|
264
|
+
integrationRef = `${remote}/${integrationBranch}`;
|
|
265
|
+
} else {
|
|
266
|
+
if (options.skipIfMissingIntegration) {
|
|
267
|
+
return {
|
|
268
|
+
status: "skipped",
|
|
269
|
+
reason: "missing-integration-ref",
|
|
270
|
+
devBranch,
|
|
271
|
+
integrationRef: hasRemote ? `${remote}/${integrationBranch}` : integrationBranch,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
throw new Error(
|
|
275
|
+
`Integration branch ref "${hasRemote ? `${remote}/${integrationBranch}` : integrationBranch}" was not found.`,
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (!dryRun && isAncestor(integrationRef, devBranch, gitCwd)) {
|
|
280
|
+
return {
|
|
281
|
+
status: "up-to-date",
|
|
282
|
+
devBranch,
|
|
283
|
+
integrationRef,
|
|
284
|
+
commitsMerged: 0,
|
|
285
|
+
pushed: false,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const behindCount = dryRun ? null : countCommitsBehind(devBranch, integrationRef, gitCwd);
|
|
290
|
+
const countLabel = behindCount && behindCount > 0 ? ` (${String(behindCount)} new commit(s))` : "";
|
|
291
|
+
log(`Syncing developer branch "${devBranch}" with ${integrationRef}${countLabel}...`);
|
|
292
|
+
|
|
293
|
+
let tempWorktree = null;
|
|
294
|
+
try {
|
|
295
|
+
if (!existingDevWorktree && !dryRun && isAncestor(devBranch, integrationRef, gitCwd)) {
|
|
296
|
+
// Fast-forward directly without requiring a checked-out worktree on devBranch.
|
|
297
|
+
const ffBranchRes = runGitAction(["branch", "-f", devBranch, integrationRef], gitCwd, { silent });
|
|
298
|
+
if (ffBranchRes.status !== 0) {
|
|
299
|
+
throw new Error(
|
|
300
|
+
`Failed to fast-forward "${devBranch}" to ${integrationRef}${ffBranchRes.stderr ? `:\n${ffBranchRes.stderr}` : "."}`,
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
} else {
|
|
304
|
+
let mergeCwd = existingDevWorktree;
|
|
305
|
+
if (!mergeCwd) {
|
|
306
|
+
if (dryRun) {
|
|
307
|
+
mergeCwd = repoRoot;
|
|
308
|
+
} else {
|
|
309
|
+
tempWorktree = createTempDeveloperWorktree(repoRoot, devBranch);
|
|
310
|
+
mergeCwd = tempWorktree.path;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const mergeRes = runGitAction(["merge", "--no-edit", integrationRef], mergeCwd, {
|
|
315
|
+
dryRun,
|
|
316
|
+
silent,
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
if (mergeRes.status !== 0) {
|
|
320
|
+
const conflicts = listConflictedFiles(mergeCwd);
|
|
321
|
+
const conflictSummary =
|
|
322
|
+
conflicts.length > 0 ? `\nConflicted files:\n${conflicts.map((file) => ` - ${file}`).join("\n")}` : "";
|
|
323
|
+
|
|
324
|
+
if (options.abortOnConflict || tempWorktree) {
|
|
325
|
+
runGitAction(["merge", "--abort"], mergeCwd, { silent: true });
|
|
326
|
+
const nextStep = tempWorktree
|
|
327
|
+
? `Switch to "${devBranch}" and resolve conflicts explicitly with: git switch ${devBranch} && featflow sync-dev`
|
|
328
|
+
: "Resolve conflicts explicitly with: featflow sync-dev\nOr skip auto-sync once with: --no-sync-dev";
|
|
329
|
+
throw new Error(
|
|
330
|
+
`Auto-sync of "${devBranch}" with ${integrationRef} hit merge conflicts and was cleanly aborted (git merge --abort).${conflictSummary}\n${nextStep}`,
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
throw new Error(
|
|
335
|
+
`Merge conflicts while syncing "${devBranch}" with ${integrationRef}.${conflictSummary}\nResolve conflicts in ${mergeCwd}, then run: git add <files> && git commit${hasRemote && options.push !== false ? ` && git push ${remote} ${devBranch}` : ""}\nOr abort with: git merge --abort`,
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const shouldPush = hasRemote && options.push !== false;
|
|
341
|
+
if (shouldPush) {
|
|
342
|
+
const pushCwd = existingDevWorktree || tempWorktree?.path || repoRoot;
|
|
343
|
+
const pushRes = runGitAction(["push", remote, devBranch], pushCwd, {
|
|
344
|
+
dryRun,
|
|
345
|
+
silent,
|
|
346
|
+
});
|
|
347
|
+
if (pushRes.status !== 0) {
|
|
348
|
+
throw new Error(
|
|
349
|
+
`Synced "${devBranch}" locally with ${integrationRef}, but failed to push to ${remote}/${devBranch}${pushRes.stderr ? `:\n${pushRes.stderr}` : "."}`,
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
return {
|
|
355
|
+
status: "synced",
|
|
356
|
+
devBranch,
|
|
357
|
+
integrationRef,
|
|
358
|
+
commitsMerged: behindCount ?? 0,
|
|
359
|
+
pushed: shouldPush,
|
|
360
|
+
};
|
|
361
|
+
} finally {
|
|
362
|
+
if (tempWorktree) {
|
|
363
|
+
tempWorktree.cleanup();
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export async function runSyncDev(argv) {
|
|
369
|
+
const options = parseArgs(argv);
|
|
370
|
+
const { config, repoRoot } = loadConfig(process.cwd());
|
|
371
|
+
|
|
372
|
+
try {
|
|
373
|
+
const result = syncDeveloperBranchWithIntegration(repoRoot, config, {
|
|
374
|
+
strictMode: true,
|
|
375
|
+
developer: options.developer,
|
|
376
|
+
remote: options.remote,
|
|
377
|
+
dryRun: options.dryRun,
|
|
378
|
+
push: !options.noPush,
|
|
379
|
+
abortOnConflict: options.abortOnConflict,
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
if (result.status === "up-to-date") {
|
|
383
|
+
console.log(`Developer branch "${result.devBranch}" is already up to date with ${result.integrationRef}.`);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (result.status === "synced") {
|
|
388
|
+
const prefix = options.dryRun ? "Dry run complete" : "Synced";
|
|
389
|
+
const suffix = result.pushed
|
|
390
|
+
? ` and pushed to ${options.remote || config.remote}/${result.devBranch}`
|
|
391
|
+
: " (local only)";
|
|
392
|
+
console.log(`${prefix}: "${result.devBranch}" now includes ${result.integrationRef}${suffix}.`);
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
console.log(`Skipped sync-dev (${result.reason ?? "no-op"}).`);
|
|
397
|
+
} catch (error) {
|
|
398
|
+
fail(error instanceof Error ? error.message : String(error));
|
|
399
|
+
}
|
|
400
|
+
}
|
|
@@ -2,7 +2,7 @@ import { spawnSync } from "node:child_process";
|
|
|
2
2
|
import { existsSync, mkdirSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
|
|
5
|
-
import { loadConfig, resolveWorktreeParent } from "../config.mjs";
|
|
5
|
+
import { loadConfig, resolveSyncIntegrationConfig, resolveWorktreeParent } from "../config.mjs";
|
|
6
6
|
import {
|
|
7
7
|
fail,
|
|
8
8
|
findWorktreeForBranch,
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
validateTaskBranchName,
|
|
16
16
|
} from "../git.mjs";
|
|
17
17
|
import { setupInstructions } from "../policy.mjs";
|
|
18
|
+
import { syncDeveloperBranchWithIntegration } from "./sync-dev.mjs";
|
|
18
19
|
|
|
19
20
|
const usage = `
|
|
20
21
|
Usage:
|
|
@@ -22,11 +23,15 @@ Usage:
|
|
|
22
23
|
featflow worktree <branch> --path <worktree-path> --base <base>
|
|
23
24
|
|
|
24
25
|
Creates a dedicated Git worktree for a typed task branch and runs any
|
|
25
|
-
configured postWorktreeCreate commands.
|
|
26
|
+
configured postWorktreeCreate commands. In developer-branch mode, automatically
|
|
27
|
+
syncs the integration branch (e.g. origin/dev) into your developer branch first
|
|
28
|
+
when clean (disable via --no-sync-dev or syncIntegration.onWorktree=false).
|
|
26
29
|
|
|
27
30
|
Options:
|
|
28
31
|
--path <path> Worktree directory path. Defaults to <worktreeParent>/<sanitized-branch>.
|
|
29
32
|
--base <ref> Base ref for a new branch. Defaults to developer branch or baseBranch.
|
|
33
|
+
--no-sync-dev Skip syncing the integration branch into your developer branch before branching.
|
|
34
|
+
--no-push Do not push the developer branch after auto-syncing the integration branch.
|
|
30
35
|
--skip-post-create Skip running configured postWorktreeCreate commands.
|
|
31
36
|
--dry-run Print commands without executing them.
|
|
32
37
|
-h, --help Show this help.
|
|
@@ -38,6 +43,8 @@ function parseArgs(argv) {
|
|
|
38
43
|
path: "",
|
|
39
44
|
base: "",
|
|
40
45
|
baseProvided: false,
|
|
46
|
+
noPush: false,
|
|
47
|
+
noSyncDev: false,
|
|
41
48
|
skipPostCreate: false,
|
|
42
49
|
dryRun: false,
|
|
43
50
|
};
|
|
@@ -53,6 +60,14 @@ function parseArgs(argv) {
|
|
|
53
60
|
options.skipPostCreate = true;
|
|
54
61
|
continue;
|
|
55
62
|
}
|
|
63
|
+
if (arg === "--no-sync-dev") {
|
|
64
|
+
options.noSyncDev = true;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (arg === "--no-push") {
|
|
68
|
+
options.noPush = true;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
56
71
|
if (arg === "--dry-run") {
|
|
57
72
|
options.dryRun = true;
|
|
58
73
|
continue;
|
|
@@ -165,6 +180,27 @@ export function createTaskWorktree(repoRoot, config, options = {}, preflighted =
|
|
|
165
180
|
const plan = preflighted ?? preflightTaskWorktree(repoRoot, config, options);
|
|
166
181
|
const execWrite = options.captureOutput ? runCapturedWrite : runWrite;
|
|
167
182
|
|
|
183
|
+
const syncCfg = resolveSyncIntegrationConfig(config);
|
|
184
|
+
if (
|
|
185
|
+
config.mode === "developer-branch" &&
|
|
186
|
+
syncCfg.onWorktree &&
|
|
187
|
+
!options.baseProvided &&
|
|
188
|
+
!options.noSyncDev &&
|
|
189
|
+
!plan.branchExists
|
|
190
|
+
) {
|
|
191
|
+
syncDeveloperBranchWithIntegration(repoRoot, config, {
|
|
192
|
+
developer: plan.baseRef,
|
|
193
|
+
dryRun: Boolean(options.dryRun),
|
|
194
|
+
push: syncCfg.pushAfterSync && !options.noPush,
|
|
195
|
+
abortOnConflict: true,
|
|
196
|
+
skipIfDirty: true,
|
|
197
|
+
skipIfUncheckedOut: true,
|
|
198
|
+
skipIfMissingIntegration: true,
|
|
199
|
+
bestEffortFetch: true,
|
|
200
|
+
silent: Boolean(options.captureOutput),
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
168
204
|
if (!options.dryRun) {
|
|
169
205
|
mkdirSync(path.dirname(plan.worktreePath), { recursive: true });
|
|
170
206
|
}
|
package/src/config.mjs
CHANGED
|
@@ -48,6 +48,12 @@ export const DEFAULT_REGRESSION_CONFIG = {
|
|
|
48
48
|
enforceInStopGate: false,
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
+
export const DEFAULT_SYNC_INTEGRATION_CONFIG = {
|
|
52
|
+
onWorktree: true,
|
|
53
|
+
onFinish: true,
|
|
54
|
+
pushAfterSync: true,
|
|
55
|
+
};
|
|
56
|
+
|
|
51
57
|
export const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
52
58
|
|
|
53
59
|
export function presetConfig(mode = "trunk") {
|
|
@@ -214,6 +220,33 @@ export function resolveRegressionConfig(config) {
|
|
|
214
220
|
return { ...DEFAULT_REGRESSION_CONFIG };
|
|
215
221
|
}
|
|
216
222
|
|
|
223
|
+
export function normalizeSyncIntegrationConfig(rawSync) {
|
|
224
|
+
if (rawSync === false) {
|
|
225
|
+
return { onWorktree: false, onFinish: false, pushAfterSync: false };
|
|
226
|
+
}
|
|
227
|
+
if (rawSync === true) {
|
|
228
|
+
return { ...DEFAULT_SYNC_INTEGRATION_CONFIG };
|
|
229
|
+
}
|
|
230
|
+
if (!isPlainObject(rawSync)) {
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
onWorktree: rawSync.onWorktree !== false,
|
|
235
|
+
onFinish: rawSync.onFinish !== false,
|
|
236
|
+
pushAfterSync: rawSync.pushAfterSync !== false,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export function resolveSyncIntegrationConfig(config) {
|
|
241
|
+
if (config?.mode !== "developer-branch") {
|
|
242
|
+
return { onWorktree: false, onFinish: false, pushAfterSync: false };
|
|
243
|
+
}
|
|
244
|
+
if (config && isPlainObject(config.syncIntegration)) {
|
|
245
|
+
return normalizeSyncIntegrationConfig(config.syncIntegration);
|
|
246
|
+
}
|
|
247
|
+
return { ...DEFAULT_SYNC_INTEGRATION_CONFIG };
|
|
248
|
+
}
|
|
249
|
+
|
|
217
250
|
export function resolveWorktreeParent(repoRoot, config) {
|
|
218
251
|
const mainRoot = findMainRepoRoot(repoRoot) ?? repoRoot;
|
|
219
252
|
if (config.worktreeParent) {
|
|
@@ -263,6 +296,7 @@ export function loadConfig(startCwd = process.cwd()) {
|
|
|
263
296
|
issues: normalizeIssuesConfig(raw.issues),
|
|
264
297
|
fileSizeBudget: normalizeFileSizeBudget(raw.fileSizeBudget),
|
|
265
298
|
regression: normalizeRegressionConfig(raw.regression),
|
|
299
|
+
syncIntegration: normalizeSyncIntegrationConfig(raw.syncIntegration),
|
|
266
300
|
protectedBranches: Array.isArray(raw.protectedBranches)
|
|
267
301
|
? raw.protectedBranches.filter((item) => typeof item === "string" && item.trim().length > 0)
|
|
268
302
|
: base.protectedBranches,
|