Skip to content

Commit 0d6ef44

Browse files
committed
docs(FR-2866): add pnpm-lock.yaml conflict resolution rule
Document the project convention for resolving pnpm-lock.yaml conflicts: always take main's version (via `git restore --source=main` or context- aware `git checkout --theirs`/`--ours`) and re-run `pnpm install` to let pnpm reconcile any new deps from the branch's package.json. This is the natural follow-up policy now that gitBranchLockfile is disabled and pnpm-lock.yaml is the single shared lockfile across all branches.
1 parent 492b168 commit 0d6ef44

1 file changed

Lines changed: 95 additions & 0 deletions

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# pnpm-lock.yaml Conflict Resolution Rule
2+
3+
When `pnpm-lock.yaml` conflicts during a merge, rebase, `gt sync`, or `gt restack`, **always take the main branch's version** rather than hand-merging the lockfile. Then run `pnpm install` to let pnpm reconcile any new dependencies from your branch's `package.json` / `pnpm-workspace.yaml`.
4+
5+
## Why
6+
7+
`pnpm-lock.yaml` is a large, auto-generated artifact. It is effectively a deterministic function of:
8+
9+
- `package.json` (in each workspace)
10+
- `pnpm-workspace.yaml` (catalog, overrides, patched dependencies, minimum release age policy)
11+
- pnpm's resolver
12+
13+
Hand-merging two versions of this file is error-prone — humans regularly miss transitive dependency mismatches, integrity hashes, or peer dependency notes, producing a lockfile that parses but doesn't correspond to a valid resolution state. CI then fails on `pnpm install --frozen-lockfile`, often in ways that point at the wrong root cause.
14+
15+
Since FR-2866 disabled `gitBranchLockfile`, every branch writes to the same canonical `pnpm-lock.yaml`. The cleanest resolution path is: take main's lockfile, then let pnpm re-resolve any new deps your branch added. pnpm will deterministically rewrite the file to match the post-merge `package.json` state — you don't lose your branch's dep changes, they're just re-derived.
16+
17+
## Pattern
18+
19+
### ✅ Recommended — `git restore --source=main` (context-independent)
20+
21+
```bash
22+
# Works the same in merge, rebase, gt sync, gt restack
23+
git restore --source=main pnpm-lock.yaml
24+
pnpm install
25+
git add pnpm-lock.yaml
26+
# then continue: git rebase --continue / gt continue / git commit
27+
```
28+
29+
`--source=main` explicitly names the source, so the command behaves identically whether you're in a merge or a rebase. Memorize this one form.
30+
31+
### ✅ Also correct — `git checkout --theirs` (during `git merge`)
32+
33+
```bash
34+
# After: git merge main → conflict in pnpm-lock.yaml
35+
git checkout --theirs pnpm-lock.yaml
36+
pnpm install
37+
git add pnpm-lock.yaml
38+
git commit
39+
```
40+
41+
In a **merge**, `--theirs` = the branch being merged in (main).
42+
43+
### ⚠️ Correct but reversed semantics — `git checkout --ours` (during rebase / `gt sync` / `gt restack`)
44+
45+
```bash
46+
# After: gt sync, gt restack, or git rebase main → conflict in pnpm-lock.yaml
47+
git checkout --ours pnpm-lock.yaml
48+
pnpm install
49+
git add pnpm-lock.yaml
50+
git rebase --continue # or: gt continue
51+
```
52+
53+
In a **rebase**, `--ours` and `--theirs` are swapped relative to merge: `--ours` = the base you're rebasing onto (main), `--theirs` = the commit being replayed (your branch). This is a well-known Git footgun. If you're unsure which context you're in, fall back to `git restore --source=main pnpm-lock.yaml` from the recommended pattern.
54+
55+
### ❌ Wrong — hand-merging the conflict markers
56+
57+
```yaml
58+
# DO NOT do this
59+
<<<<<<< HEAD
60+
'@some/pkg':
61+
version: 1.0.0
62+
=======
63+
'@some/pkg':
64+
version: 1.1.0
65+
>>>>>>> main
66+
```
67+
68+
Lockfile conflict regions can span hundreds of lines and reference interconnected `packages:`, `snapshots:`, and `importers:` sections. Hand-editing them produces lockfiles that pass parsing but fail `pnpm install --frozen-lockfile` in CI.
69+
70+
### ❌ Wrong — taking main's lockfile and skipping `pnpm install`
71+
72+
```bash
73+
git restore --source=main pnpm-lock.yaml
74+
git add pnpm-lock.yaml
75+
git commit # ← problem: if your branch added new deps to package.json,
76+
# they aren't in main's lockfile yet, so CI will fail on
77+
# pnpm install --frozen-lockfile.
78+
```
79+
80+
Always run `pnpm install` after restoring. pnpm will re-resolve any new deps your branch introduced and write a coherent lockfile.
81+
82+
## Rules
83+
84+
1. **Default**: `git restore --source=main pnpm-lock.yaml` — same command for merge and rebase.
85+
2. **Always follow up with `pnpm install`** so pnpm reconciles any new deps from your branch's `package.json` / `pnpm-workspace.yaml`.
86+
3. **Never hand-merge `pnpm-lock.yaml`** — the file is auto-generated; let the tool that owns it (pnpm) regenerate it.
87+
4. **Mind the rebase / merge swap** when using `--ours` / `--theirs`. In rebase, `--ours` is main; in merge, `--theirs` is main. When in doubt, use `--source=main`.
88+
5. **Same rule applies during `gt sync` and `gt restack`** — both use rebase semantics under the hood. Resolve with `git restore --source=main pnpm-lock.yaml`, run `pnpm install`, then `gt continue`.
89+
6. **Don't escalate routine lockfile conflicts** — they almost always resolve via this recipe. Escalate only if `pnpm install` itself fails after taking main's lockfile (which typically points at a real `package.json` / `pnpm-workspace.yaml` problem, not a lockfile problem).
90+
91+
## Related
92+
93+
- `pnpm-workspace.yaml` — the canonical source of truth for catalog, overrides, patched dependencies, and the `minimumReleaseAge` policy.
94+
- FR-2866 (PR #7359) — disabled `gitBranchLockfile`, making `pnpm-lock.yaml` the single shared lockfile across all branches.
95+
- pnpm docs on lockfile conflicts: <https://pnpm.io/git#dealing-with-merge-conflicts>

0 commit comments

Comments
 (0)