From: Kiesel, Norbert Date: Tue, 02 Jun 2026 21:40:44 GMT Subject: [PATCH] worktree: record creation time and free-form note Message-ID: From 130cd5e4a25e6672b2a97268e1100b6ef03fa552 Mon Sep 17 00:00:00 2001 From: Norbert Kiesel Date: Mon, 1 Jun 2026 17:03:39 -0700 Subject: [PATCH] worktree: record creation time and free-form note Add per-worktree metadata so users can answer "what is this worktree for, and when did I make it?" without resorting to external notes. When `git worktree add` creates a linked worktree, it now writes a `created` file containing the unix timestamp. A new `--note ` option to `add`, and a new `git worktree annotate []` subcommand, store an optional free-form description in a `note` file next to the other administrative files. Passing `annotate` without a note clears it. The main worktree carries no metadata and cannot be annotated. `git worktree list` learns `--show-created` and `--show-note` for human-readable output, and `--sort=` (path or created, optionally prefixed with `-` to reverse) for ordering linked worktrees; the main worktree always stays first. Worktrees without a recorded timestamp (those created before this change) display as `created: unknown` and sort after timestamped ones. Porcelain output unconditionally emits `created` and `note` lines when the corresponding metadata is present. Tests cover add/annotate/list behaviour and the legacy-worktree case. The two existing porcelain assertions in t2402 are taught to strip the new `created` line so they continue to pass. Signed-off-by: Norbert Kiesel --- Documentation/git-worktree.adoc | 61 ++++++++++++- builtin/worktree.c | 152 +++++++++++++++++++++++++++++++- t/meson.build | 1 + t/t2402-worktree-list.sh | 10 ++- t/t2410-worktree-metadata.sh | 143 ++++++++++++++++++++++++++++++ worktree.c | 78 ++++++++++++++++ worktree.h | 23 +++++ 7 files changed, 459 insertions(+), 9 deletions(-) create mode 100755 t/t2410-worktree-metadata.sh diff --git a/Documentation/git-worktree.adoc b/Documentation/git-worktree.adoc index fbf8426cd9..200f3d7772 100644 --- a/Documentation/git-worktree.adoc +++ b/Documentation/git-worktree.adoc @@ -10,8 +10,11 @@ SYNOPSIS -------- [synopsis] git worktree add [-f] [--detach] [--checkout] [--lock [--reason ]] + [--note ] [--orphan] [(-b | -B) ] [] -git worktree list [-v | --porcelain [-z]] +git worktree annotate [] +git worktree list [-v | --porcelain [-z]] [--show-created] [--show-note] + [--sort=] git worktree lock [--reason ] git worktree move git worktree prune [-n] [-v] [--expire ] @@ -106,6 +109,15 @@ passed to the command. In the event the repository has a remote and command fails with a warning reminding the user to fetch from their remote first (or override by using `-f`/`--force`). +`annotate []`:: + +Set, replace, or clear a free-form note (description) on a linked worktree. +Useful for recording what a worktree was created for so it can be identified +later. With __, the worktree's note is set or replaced; without a note +argument, the existing note is cleared. The note for a worktree may also be +set at creation time with `git worktree add --note `. The main +worktree cannot be annotated. + `list`:: List details of each worktree. The main worktree is listed first, @@ -114,6 +126,20 @@ whether the worktree is bare, the revision currently checked out, the branch currently checked out (or "detached HEAD" if none), "locked" if the worktree is locked, "prunable" if the worktree can be pruned by the `prune` command. ++ +Each worktree's creation timestamp is recorded when it is created with +`git worktree add`. Worktrees created before this feature existed have no +recorded creation timestamp; for them, `list` reports `created: unknown` +in human output and omits the `created` line in `--porcelain` output. Pass +`--show-created` to include creation timestamps in human output. Worktrees +without a recorded timestamp sort last (or first when reversed) with +`--sort=created`. ++ +Pass `--show-note` to include any user-provided note in human output. In +`--porcelain` output, both `created` and `note` lines are emitted whenever +present. Use `--sort=` (where __ is `path` or `created`, +optionally prefixed with `-` to reverse) to order the linked worktrees; +the main worktree always remains first. `lock`:: @@ -286,6 +312,32 @@ _