Facet
DeutschInstall
Team & product

See which features changed after git pull, with FACET

After each pull, list the features whose code changed while their FACET description did not, read only those diffs, and mark what you have reviewed so the next pull shows only what is new.

  • 7 min read
  • 6 steps
  • Git
  • Your coding agent

Monday morning, back from two weeks off. git pull brings in forty commits from five people. Somewhere in there, someone may have changed how the feature you are responsible for behaves, and the commit messages say "fix", "cleanup" and "address review". Reading every diff takes the morning; skipping them means you find out from a customer.

FACET keeps a short, checkable description of each feature, called a FACET recordA FACET record is a short, checkable description of one feature, kept as a YAML file next to the code. It states why the feature exists, the behaviour it promises as scenarios, and the tests that check it.In the glossary, next to your code and links the two with a comment in the code. By the end of this guide one command after each pull tells you which of your documented features had their code changed underneath them, and which records may now be wrong. facet drift compares the code with a baseline you choose, and facet drift accept remembers what you have already reviewed, so the next pull only shows what is new.

The commands below use a small example shop written in TypeScript, set up as in One answer instead of three. A colleague has pushed two commits to the shared repository while you were away.

Step 1Pull, then ask which features changed

Pull as usual:

sh
  • git pull

Then compare with where you were before the pull. Git keeps that commit as ORIG_HEAD after every pull:

sh
  • npx facet drift --baseline ORIG_HEAD
Terminal output: git pull fast-forwards and changes src/checkout/discount.ts and src/orders/refund.ts; npx facet drift --baseline ORIG_HEAD reports drift for checkout/discounts/redeem-code in src/checkout/discount.ts, 1 drifted anchor.Terminal output: git pull fast-forwards and changes src/checkout/discount.ts and src/orders/refund.ts; npx facet drift --baseline ORIG_HEAD reports drift for checkout/discounts/redeem-code in src/checkout/discount.ts, 1 drifted anchor.
Two files changed in the pull; one of them carries a documented feature.

DriftDrift is when code changes and the record describing it does not follow, so the two no longer match. facet drift lists the features whose anchored code changed since a chosen baseline.In the glossary means: code anchored to a record changed, and the record did not. Here, src/checkout/discount.ts carries the AnchorAn anchor is a comment in the source code, starting with @facet:, that names the record the code belongs to. FACET reads these comments to know where each feature is implemented.In the glossary of the discount-code record. That is the one feature to look at.

Plain npx facet drift without --baseline compares with HEAD, which after a pull already includes the new commits. It reports No drift found and adds a clean result covers only the uncommitted work. That is why the first comparison needs ORIG_HEAD.

Step 2Read only the change that matters

List what came in:

sh
  • git log --oneline ORIG_HEAD..HEAD
console
  • git log --oneline ORIG_HEAD..HEAD
  • 1b6bc04 feat(orders): shorten the refund window to 14 days
  • 37a56ea fix(checkout): the minimum order value excludes the threshold itself

Then read the diff of the file drift named, and nothing else:

sh
  • git diff ORIG_HEAD -- src/checkout/discount.ts
console
  • git diff ORIG_HEAD -- src/checkout/discount.ts
  • diff --git a/src/checkout/discount.ts b/src/checkout/discount.ts
  • index 36cb22c..618346b 100644
  • --- a/src/checkout/discount.ts
  • +++ b/src/checkout/discount.ts
  • @@ -33,7 +33,7 @@ export function redeemDiscountCode(cart: Cart, input: string, now = new Date()):
  •    if (!code) throw new ShopError("E2001");
  •    if (isExpired(code, now)) throw new ShopError("E2002");
  •    const total = subtotal(cart);
  • -  if (code.minSubtotal !== undefined && total < code.minSubtotal) throw new ShopError("E2003");
  • +  if (code.minSubtotal !== undefined && total <= code.minSubtotal) throw new ShopError("E2003");
  •    const discount = code.kind === "percent" ? Math.round((total * code.value) / 100) : Math.min(code.value, total);
  •    return { ...cart, discountCode: code.code, discount };
  •  }

One character with consequences: a cart whose subtotal is exactly the minimum order value used to get the discount. Now the shop refuses it with E2003. The record still says "below that value".

Step 3Bring the record in line, or push back

If the new behaviour is intended, change the ScenarioA scenario is one behaviour a feature promises, written in a record as Given/When/Then steps. Each scenario has an id that tests and other records can refer to.Read more here in docs/facets/features/checkout/discounts/redeem-code.yaml:

text
    - id: minimum-order-value      statement: |        Given a code with a minimum order value        When the cart subtotal is at or below that value        Then the shop refuses the code with E2003

If it is not intended, this is the moment to talk to the colleague, before customers notice. Either way, the record stops describing something the code no longer does.

Step 4Mark the review as done

Record that you have reviewed everything up to now:

sh
  • npx facet drift accept --outcome record-updated

Check the result:

sh
  • npx facet drift
Terminal output: npx facet drift accept --outcome record-updated prints Accepted baseline with a commit hash and time; npx facet drift then reports Baseline: accepted review, record-updated, and No drift found.Terminal output: npx facet drift accept --outcome record-updated prints Accepted baseline with a commit hash and time; npx facet drift then reports Baseline: accepted review, record-updated, and No drift found.
From now on, drift compares with the state you reviewed.

accept stores a snapshot of the working tree as a private git ref of this worktree (refs/worktree/facet/drift-baseline). It is not a branch or a tag, is never pushed and changes no file. --outcome is a note for yourself: behavior-unchanged (the default), record-updated or references-repaired.

Commit and push the corrected record:

sh
  • git add docs/facets/features/checkout/discounts/redeem-code.yaml
  • git commit -m "Minimum order value: equal to the minimum is now refused"
  • git push

Step 5Check it on the next pull

The next time you pull, plain drift is enough, because it now compares with your last review instead of HEAD. It also covers several pulls in a row, as long as you have not accepted in between:

sh
  • git pull
  • npx facet drift
Terminal output: git pull fast-forwards one change to src/checkout/discount.ts; npx facet drift against the accepted review reports drift for checkout/discounts/redeem-code, 1 drifted anchor.Terminal output: git pull fast-forwards one change to src/checkout/discount.ts; npx facet drift against the accepted review reports drift for checkout/discounts/redeem-code, 1 drifted anchor.
A new change to the discount code since your review shows up without any extra flag.

To read exactly what changed since your review, diff against the stored snapshot:

sh
  • git diff refs/worktree/facet/drift-baseline -- src/checkout/discount.ts
console
  • git diff refs/worktree/facet/drift-baseline -- src/checkout/discount.ts
  • diff --git a/src/checkout/discount.ts b/src/checkout/discount.ts
  • index 618346b..f15aa32 100644
  • --- a/src/checkout/discount.ts
  • +++ b/src/checkout/discount.ts
  • @@ -29,7 +29,7 @@ function isExpired(code: DiscountCode, now: Date): boolean {
  •  /** Redeems a code on a cart. Returns the new cart; throws a ShopError and leaves the cart unchanged otherwise. */
  •  export function redeemDiscountCode(cart: Cart, input: string, now = new Date()): Cart {
  •    if (cart.discountCode) throw new ShopError("E2004");
  • -  const code = discountCodes.find((entry) => entry.code === input.trim().toUpperCase());
  • +  const code = discountCodes.find((entry) => entry.code === input.toUpperCase().trim());
  •    if (!code) throw new ShopError("E2001");
  •    if (isExpired(code, now)) throw new ShopError("E2002");
  •    const total = subtotal(cart);

The order of two string operations changed; the behaviour did not. Accept only this file, with the default outcome behavior-unchanged:

sh
  • npx facet drift accept src/checkout/discount.ts

The next npx facet drift reports No drift found again. Named paths are accepted one by one; changes to other files stay reported until you review them too.

Step 6If drift says something else

  • Baseline: HEAD … no review recorded; a clean result covers only the uncommitted work: you are comparing with HEAD, which already contains the pulled commits. Use npx facet drift --baseline ORIG_HEAD right after the pull, or accept once so later runs compare with your review.
  • drift could not be determined: baseline … does not resolve to a commit: the revision you named does not exist, for example ORIG_HEAD in a clone that has never pulled. Name the commit you started from instead: --baseline HEAD@{1} right after a pull, or a hash from git reflog. ORIG_HEAD also moves with every later rebase, reset or merge, so use it right after the pull.
  • A file stays reported after you edited its record: once a review is recorded, editing a record no longer clears drift. Run npx facet drift accept for that file.
  • You want to start over: npx facet drift reset forgets the stored review, and drift compares with HEAD again.

For more on teams that change each other's features without noticing, read Your release was green. Ours is broken now..

Sources