> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gatojs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# gato update

> Move a GatoJS project to a newer kit version with a three-way merge: requirements, dry run, the per-file plan, conflicts, rollback and what to do afterwards.

```bash theme={null}
gato update <version> [--kit <source>] [--dry-run] [--no-install]
```

`gato update` moves a project from the kit version in `kitVersion` (`.wa/kit.json`) to the tag `v<version>`. It applies the kit's changes between the two versions to your project and keeps your local edits, with a three-way merge per file. It updates the core and every installed kit module together; you cannot update one module on its own. You review the result with `git diff` and commit it yourself.

```bash theme={null}
npx gato update 0.9.0 --dry-run
npx gato update 0.9.0
```

## Options

**version** `x.y.z` *required*

Target kit version without `v`: three numbers without leading zeros, optionally with a prerelease suffix (`0.9.0-rc.1`). There is no "latest" default. It must be higher than the project's `kitVersion` (semver comparison, so `0.10.0` is newer than `0.9.0`).

**--kit** `path | url`

Kit source, as for [`add` and `list`](https://docs.gatojs.com/cli/kit-source). Unlike those, `update` clones a local path too, so the content always comes from the tags `v<kitVersion>` and `v<version>`, never from a working tree.

**--dry-run** `boolean`

Print the plan and exit with `0` without changing the project, even when the plan has conflicts. Does not need a clean git tree, but still clones both kit versions.

**--no-install** `boolean`

Skip `npm install` at the end.

There is no `--force`: a conflict is a place to merge by hand, not an error to bypass.

## Before you start

* The project must be a git repository with a clean tree (`git status --porcelain` empty; ignored files do not count, untracked ones do). The clean tree is your safety net: `git restore . && git clean -fd` brings back the state from before the update.
* Both tags, `v<kitVersion>` and `v<version>`, must exist in the kit source.
* Run `--dry-run` first to see which files will change and where conflicts will be.

## Who computes the update

The plan depends on the rules of the target version: which files have regions, the schemas, how `package.json` is assembled, the generator. An older CLI could compute it wrongly. So the CLI you run does only the first checks, clones the target tag and hands the work to the CLI bundled with that tag (`.wa/bin/wa.mjs` in the clone), running in your project directory with its output in your terminal. If that process fails, the outer command exits with `1` without a message of its own; the inner one has already printed the error.

> [!NOTE]
>
> A project whose bundled CLI predates the `update` command prints the usage and exits with `1`. Run the target version's bundle from a clone in the project directory once: `KIT_DIR=$(mktemp -d) && git clone --depth 1 --branch v<version> https://github.com/webamigos/gatojs.git "$KIT_DIR" && node "$KIT_DIR/.wa/bin/wa.mjs" update <version>`. The bundle in a kit clone checks that the clone's version equals `<version>`. After the update the project carries the new bundle.

## Order of checks

Every check and the whole merge happen in memory, before the first write.

**1. Options and version**

No version: `Podaj wersję kitu` ("give the kit version"). Bad format, for example `v0.9.0`: `Nieprawidłowa wersja: v0.9.0; podaj na przykład 0.2.0` ("invalid version").

**2. Read .wa/kit.json**

As in every project command.

**3. Target version**

Equal to `kitVersion`: prints `Projekt ma już wa-kit <version>` ("the project already has this version") and exits with `0`, even on a dirty tree and offline. Lower: `Projekt ma wa-kit <x>, nowszą niż <version>; wa update nie obniża wersji` ("update does not downgrade").

**4. Clean git tree**

Skipped with `--dry-run`. Dirty tree: `Niezacommitowane zmiany w projekcie; zrób commit albo stash przed wa update` ("commit or stash first"). Not a repository: `<dir> nie jest repozytorium git; wa update wymaga gita, żeby dało się cofnąć zmiany`. No `git` command: `Nie znaleziono polecenia git; zainstaluj git, żeby uruchomić wa update`.

**5. Kit source**

A rejected source gives `Nieprawidłowe źródło wa-kit: <source>` ([Kit source](https://docs.gatojs.com/cli/kit-source.md)).

**6. Bundle version**

Only when you run the bundle from a kit clone: the clone's version must equal `<version>`, otherwise `Bundel pochodzi z wa-kit <x>, a aktualizacja prowadzi do <version>`.

**7. Fetch both versions**

`git clone --branch v<version>` (with `--depth 1` for URLs) into a temporary directory, removed afterwards, also after an error. A missing tag gives `Nie udało się pobrać wa-kit v<version> z <source>. …` with git's message above it. A tag whose `kit/kit.json` has another version gives `Kit w <clone> ma wersję <x>, oczekiwano <version>`. The target's own CLI then repeats checks 2 to 5 and clones the base version `v<kitVersion>`.

**8. Read both versions**

Every kit module in `.wa/kit.json` must exist in both: `Moduł <x> nie istnieje w wa-kit <version>` ("does not exist in that kit version"). A module removed or renamed in the kit needs a manual decision.

**9. Requirements**

Every `requires` of the installed modules at the target version must be installed: `Moduł <x> w wa-kit <version> wymaga niezainstalowanych modułów: <list>`. `update` never adds modules. Project modules are left as they are.

**10. Plan every file**

Including the merges. A path that resolves outside the project gives `Ścieżka poza projektem: <path>`; a `git merge-file` failure gives `git merge-file: <git message>`.

**11. Dry run**

With `--dry-run`, print the plan and exit with `0`.

**12. Write**

Before the first write, no target (planned files, `.wa/kit.json`, generated files, files with regions) may have a symlink anywhere in its path inside the project: `Dowiązanie symboliczne na ścieżce zapisu: <path>` ("symlink on a write path"), with nothing changed. Then files are written, then `.wa/kit.json`. A write failure is rolled back.

**13. Finish**

Without conflicts: `gato generate`, hints, and `npm install` unless `--no-install`. With conflicts: all three are skipped.

## The plan for each file

The plan covers the files of the installed kit modules in both versions (except kit-only files, generated files and `package-lock.json`) plus `package.json`. Each path has three sides:

* **base:** the file from tag `v<kitVersion>`, with your project names in place of the placeholders;
* **kit:** the same for tag `v<version>`;
* **project:** the file on your disk.

For `package.json`, base and kit are assembled from the manifests of your installed modules at each version, so a dependency or script change in the kit merges with your own scripts and dependencies.

| Base | Kit | Project | Result | Line in the output |
| - | - | - | - | - |
| present | same as base | anything | unchanged | — |
| present | changed | same as base | kit content | `zaktualizowano` (updated) |
| present | changed | same as kit | unchanged | — |
| present | changed | differs from both | three-way merge | `scalono` (merged) or `konflikt` (conflict); no line if the merge equals the project |
| present | changed | missing | file does not come back | `do decyzji` (needs a decision): deleted in the project, changed in the kit |
| present | removed | same as base | deleted, with empty directories | `usunięto` (deleted) |
| present | removed | differs from base | file stays | `do decyzji`: changed in the project, deleted in the kit |
| absent | added | missing | added | `dodano` (added) |
| absent | added | same as kit | unchanged | — |
| absent | added | different | project content stays | `konflikt`: a project file on the path of a new kit file |

Details:

* **Equality** is computed like the hashes in `.wa/kit.json`: files with `wa:*` regions are compared without the region contents, all other files byte for byte.
* **Base that does not match the recorded hash.** A project may have been created from a kit working tree rather than a tag. "Project same as base" therefore needs both the file to equal the tagged base and the recorded hash to equal the base's hash. Otherwise the file is treated as changed in the project, so it is merged or marked for a decision, never overwritten or deleted. The CLI counts such files in a `Uwaga: <n> plików różni się od v<kitVersion> z tagu; …` warning.
* **Merging** uses `git merge-file -p --diff3` with the labels `projekt`, `v<kitVersion>` and `v<version>`.
* **Files with regions** have their region contents cleared on all three sides before the merge, so region differences never conflict. `gato generate` refills them.
* **Binary files** (a NUL byte on any side) are not merged: changes on both sides give a conflict and the project's version stays.
* **Permission bits** of an updated, added, merged or conflicted file come from the target kit version.

## Output

The header and one line per planned file, grouped in the order updated, merged, added, deleted, conflict, needs a decision, alphabetically within each group:

```text theme={null}
Aktualizacja wa-kit 0.8.1 → 0.9.0
  zaktualizowano src/shared/lib/auth/org-context.ts
  scalono        src/shared/lib/env.ts
  dodano         src/shared/lib/rate-limit.ts
  usunięto       src/shared/lib/legacy.ts
  konflikt       src/features/uploads/services/upload-purposes.ts
  do decyzji     src/shared/lib/old-helper.ts (zmieniony w projekcie, usunięty w kicie)
```

The paths above are illustrative.

* `--dry-run` starts with `Plan aktualizacji wa-kit <x> → <version> (bez zmian w projekcie)` ("plan, no changes to the project").
* When the kit changed none of your files, the header is followed by `  bez zmian w plikach` ("no file changes"); `.wa/kit.json` still gets the new version.
* Without `--dry-run`, the plan is printed only after a successful write.
* Above it you see one line of git output per clone. They are not errors.

## Conflicts and files that need a decision

A text conflict leaves `diff3`-style markers with the base in the middle:

```text theme={null}
<<<<<<< projekt
export const kitMarker = "project";
||||||| v0.8.1
export const kitMarker = "v0.8.1";
=======
export const kitMarker = "v0.9.0";
>>>>>>> v0.9.0
```

| After the write | `.wa/kit.json` | generate, hints, `npm install` | Exit code | Last lines |
| - | - | - | - | - |
| No conflicts, nothing to decide | New version | Run | `0` | Hints or the plan |
| Only files that need a decision | New version | Run | `1` | Hints or the plan |
| At least one conflict | New version | Skipped | `1` | `Rozwiąż konflikty, potem: npm run wa -- generate && npm install` and `Cofnięcie całej aktualizacji: git restore . && git clean -fd` |

The last two lines mean "resolve the conflicts, then run generate and npm install" and "to undo the whole update: `git restore . && git clean -fd`".

* `.wa/kit.json` is written even with conflicts: once you resolve the markers, the project is at the target version. Running `update <version>` again only says the project already has it, so a second run does not resolve conflicts.
* With conflicts, `gato generate` and `npm install` do not run, because markers can break regions and `package.json`. Until you run `generate`, generated files and regions may not match your modules. There are no migration or variable hints either: check `git diff -- prisma/schema .env.example` yourself.
* Files that need a decision have no markers, so generate and install do run, but the exit code is still `1`: scripts and agents get the same "needs a human" signal as for a conflict. Such a file has no entry in the module's `files` in `.wa/kit.json`.
* A file you deleted does not come back. A project file on the path of a new kit file is not overwritten; copy the kit file by hand from a clone of tag `v<version>` (files listed in `placeholderFiles` still carry the kit's placeholder names there, such as `wa-app`).

To finish:

**1. Resolve**

Resolve the markers in every `konflikt` file and decide on every `do decyzji` file: delete it, keep it as project code, or carry the changes over.

**2. Regenerate and install**

`npx gato generate`, then `npm install`.

**3. Migration and variables**

As in [After the update](#after-the-update).

**4. Commit**

To undo everything before committing: `git restore . && git clean -fd`, then `npm install` so `node_modules` matches the restored lockfile. `git clean -fd` keeps files ignored by `.gitignore`; `git status --ignored` shows them. To undo one file: `git restore <file>`.

## What it writes

* Files according to the plan: added, updated, merged, with conflict markers, deleted (with empty directories above them). A binary conflict and a conflict on a new kit file's path leave the project file unchanged.
* `package.json` according to the plan.
* `.wa/kit.json`: `kitVersion` set to the target, and for each kit module the target `version` and `manifest` and `files` hashes of the **kit's** content (not the merged content). `package.json` and `package-lock.json` keep `managed`. Files that need a decision and files absent from the target have no entry. `kitRepo`, `project`, `locales` and `projectModules` stay as they are. Because the hashes come from the kit, a merged file with local changes still counts as changed for `gato remove`, and the next update has the right base.

`update` does not change `.env` or `package-lock.json`. The lockfile changes only with `npm install`, so with `--no-install` or after conflicts it stays old until the first install.

## After the update

Without conflicts, after `gato generate`, the CLI prints hints:

| Line | When |
| - | - |
| `npx prisma migrate dev --name kit-<version>` | The kit changed, added or removed a `prisma/schema/**` file of an installed module. |
| `Nowe zmienne w .env.example: <list>; uzupełnij .env` | The target manifests of installed modules declare variables the base did not ("new variables in `.env.example`; fill in `.env`"). |

Then:

1. **Migration:** run the printed command with the database up and commit the migration. The kit ships no migrations ([Database and migrations](https://docs.gatojs.com/guides/database-and-migrations.md)).
2. **`.env`:** copy new variables from the `wa:modules` region of `.env.example` and set values.
3. With `--no-install`, run `npm install`, which also updates `package-lock.json`.
4. **Review:** `git diff`, `npm run verify`, commit (with `package-lock.json`).

## Rollback and its limits

* **A failure before writing** (checks 1 to 11) changes nothing: every file, merges included, is built in memory.
* **A write failure** (for example a full disk, or a file where a directory should be) is rolled back: the original content and permission bits of changed and deleted files are restored, added files and directories the command created are removed, and `.wa/kit.json` is restored. A cleanup step that fails prints `Nie udało się posprzątać: <path> (<code>)`; the original error comes last, with a second line `Sprawdź git status; całość cofa: git restore . && git clean -fd` ("check git status; this undoes everything").
* **A `gato generate` failure** is not rolled back: files and `.wa/kit.json` are already at the new version. The command exits with `1` and `Zaktualizowano do wa-kit <version>, ale wa generate się nie powiódł. Uruchom: npm run wa -- generate`. Hints and install do not run. Fix the cause, run `generate`, then `npm install`.
* **An `npm install` failure** is not rolled back: `Zaktualizowano do wa-kit <version>, ale npm install się nie powiódł. Uruchom: npm install`, exit `1`. Hints are printed before it.
* **A conflict** is not a write failure and rolls nothing back.

## Project modules

`update` leaves your [project modules](https://docs.gatojs.com/cli/kit-json.md#project-modules) and their entries untouched. A kit file you edited is merged like any local change. See [Working with the kit](https://docs.gatojs.com/guides/working-with-the-kit.md) for how kit changes reach projects.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.