(adr-repository-aliases)=

# ADR 0001: Repository aliases

## Status

Proposed. 2026-12-05.

## Context

An entry's key does three jobs. It is the name a term matches on the command
line, the directory the repository is checked out to, and part of the identity
vcspull uses to decide that two files describe the same entry (the parent of
the checkout path plus the name).

```yaml
~/work/libtmux/:
  docs:
    repo: git+https://github.com/example/libtmux-docs.git
~/study/python/:
  docs:
    repo: git+https://github.com/example/python-docs.git
```

Generic directory names repeat across workspace roots: `docs`, `assets`,
`central`, `design`. `vcspull sync docs` selects every one of them, and
`vcspull status` prints `docs` once per checkout with nothing to tell them
apart. The only unambiguous term is the full path.

[#586](https://github.com/vcs-python/vcspull/issues/586) asks for a way to
address `~/work/libtmux/docs` as `libtmux-docs` while the directory stays
`docs`. Three questions decide what that means for a user:

- Does `docs` still match once the entry has another handle?
- Is the handle an added `alias`, the existing `name`, or a unique `id`?
- What happens when two entries hold the same handle, in one file or across
  {ref}`configuration scopes <config-scopes>`?

Two keys that look like answers exist in v1.70.1 and are not:

- `name:` renames the entry *and* its directory. `name: libtmux-docs` under
  the key `docs` checks out to `~/work/libtmux/libtmux-docs`, and `docs` stops
  matching. Adding it to an entry that is already cloned leaves the old
  directory behind and clones again.
- `path:` sets the checkout path verbatim, with no `~` or `$HOME` expansion,
  so a `name:` plus `path:` pair that keeps the directory needs an absolute
  path and cannot be shared between machines.

Each of the three designs was built as a prototype on v1.70.1 and used from a
shell in every scope (user dotfile, user config directory, project file,
`-f FILE`), through the commands that read configuration and the commands that
write it. The decision below is the design that was still standing, refined
through repeated adversarial review. It records behaviour, not an
implementation.

## Decision

An entry may carry `alias:`, one extra handle. An alias adds a way to select
the entry and changes nothing else: not the directory, not the name, not the
identity used to merge files.

```yaml
~/work/libtmux/:
  docs:
    repo: git+https://github.com/example/libtmux-docs.git
    alias: libtmux-docs
```

`docs` still matches. There is no `id`. `name:` keeps its meaning: `name:`
renames the entry and its directory; `alias:` adds a handle and changes
neither.

The rest of this section uses three terms. A *handle* is a name or an alias.
A *term* is what you type after a command. A *shared handle* is an alias that
equals another entry's alias or name.

### The value

1. An alias is one string. It starts with a letter, digit, or underscore,
   contains only letters, digits, `_`, `.`, and `-`, and is at most 255
   characters. Aliases are case-sensitive. Any other value fails when the file
   loads, with a message that states the rule. Directory names stay
   unrestricted.
2. An alias equal to its own entry's name adds nothing. It is ignored,
   {ref}`vcspull fmt <cli-fmt>` `--write` removes it, and it counts as "no
   alias" when one is attached.
3. An entry holds one alias.

### Matching

4. {ref}`vcspull sync <cli-sync>`, {ref}`vcspull list <cli-list>`,
   {ref}`vcspull status <cli-status>`, and
   {ref}`vcspull worktree <cli-worktree>` match a term against the name and
   the alias with the same glob rules, so `'libtmux-*'` selects by alias.
   {ref}`vcspull search <cli-search>` matches its regular expression against
   the alias too, with an `alias:` prefix and `--field alias`.
5. The same name under different workspace roots is normal and is never
   reported. Only an alias can make a handle shared.

### Shared handles

6. A command that reads configuration never fails on a shared handle, in one
   file or across files. The term selects every entry that holds the handle,
   the way `docs` selects every entry named `docs` today.
7. A command that writes configuration ({ref}`vcspull add <cli-add>`,
   {ref}`vcspull discover <cli-discover>`,
   {ref}`vcspull import <cli-import>`) refuses to create a shared handle and
   names the entry that holds it. One exception: when only a project file
   holds the other entry, the writer warns and writes, because a file you do
   not own cannot block your own configuration.
8. One sentence decides when a handle warning prints: *a handle warning prints
   when a term matches an alias and does not match that entry's own name.*
   `list docs` prints none, however many entries are named `docs`, unless
   another entry's alias is `docs`. `list '*'` and a command with no term
   print none, so a scheduled `sync --all` stays quiet. `list libtmux-docs`
   and `list 'libtmux-*'` print one when that alias is shared.
9. One warning prints per handle and command. Every warning has the same
   layout: what happened, the entries that hold the handle one per line with
   their file and scope, and the next step.
10. {ref}`vcspull config ls <cli-config>` lists every alias that is shared,
    ignored, or lost, without a term. `fmt` notes the shared and redundant
    aliases in the file it formats.

### Scopes

11. A nearer file replaces the same entry whole, as it does today, so a
    redefinition in one of your own files that omits the alias loses it. A
    term that names the lost alias gets a warning that says which file
    replaced the entry.
12. A project file never removes or replaces an alias that a user or system
    file declares. Your alias keeps working from inside a project that
    redefines the checkout.

### Writing an alias

13. `vcspull add PATH --alias X` adds a new entry with the alias. When PATH is
    already configured, it attaches the alias to that entry instead: it
    matches by directory, whatever the key or however `path:` is written,
    edits the definition vcspull uses, keeps key order, and changes nothing
    but the alias.
14. An attach is refused before any prompt, with the entry and file to edit by
    hand, when the answer is not one unambiguous edit:

    | Situation | Result |
    | --- | --- |
    | Two or more entries reach the directory | Refused, naming each by workspace root and key |
    | `-f FILE` names a file whose definition loses at load | Refused, naming the file that wins |
    | `-f FILE` names a file vcspull does not read, and a file it reads defines the entry | Refused, naming that file |
    | `-f FILE` names a file vcspull does not read, and nothing else defines the entry | Edited; the alias selects the entry in commands run with the same `-f` |
    | The entry is defined only in a project or system file | Refused unless `-f` names that file |
    | The entry already has an alias | Refused; edit the file to change it |
    | The entry is pinned | Refused; a pin protects it from every writer |
    | `--pin`, `--depth`, `--shallow`, `--name`, `-w`, or a different URL is passed | Refused |

15. Before it asks for confirmation, an attach renders the edited file and
    loads it the way a reading command would. It writes only when the entry
    has the alias and every other entry is unchanged.
16. `add` never changes or removes an alias; edit the file. `discover` and
    `import` never write one, and both treat an aliased checkout as already
    configured.

### Output

17. Human-readable rows show the alias after the name:

    ```text
    • docs (alias libtmux-docs) → ~/work/libtmux/docs
    ```

18. JSON rows carry `alias`, `null` when unset. `name` is unchanged, so a
    script that reads `name` keeps working.

## Options considered

### `alias:`, an added handle (chosen)

A configuration without the key behaves exactly as before, and a term that
matched yesterday matches today. The directory path stays the single identity
of an entry, so the scope rules in {ref}`config-scopes` stay true as written.

The cost is that an alias is not guaranteed unique. Rule 6 accepts that: a
shared alias behaves like a shared directory name, and rules 8 to 10 make it
visible. An earlier draft made a shared alias inside one file a load error.
That was withdrawn, because one mistake committed to a configuration shared
between machines made `list`, `status`, and `sync` exit 1 on every machine
that pulled it, and no vcspull command could repair the file.

### `name:` as a replacing handle

The handle replaces the name for matching and display while the directory
stays put. Rejected:

- `sync docs` in a script or scheduled job stops selecting the repository,
  with no error.
- `name:` already means "rename the entry and its directory". Giving it a
  second meaning changes what existing configurations do.
- A replaced name has to be unique or something silently loses it, and the
  prototype's uniqueness error let a project file stop every command in its
  tree.

### `id:`, a unique identifier

An exact handle that outranks names and never globs. Rejected:

- It adds a second identity beside the path-based one, and the two disagree
  across scopes. In the prototype, a project file that reused an id removed
  your checkout from `list` and pointed `sync` at its own, with exit 0.
- An id that outranks names lets a new entry retarget an existing term: adding
  an id `central` changes what `sync central` selects.
- Globs do not reach ids, so `'libtmux-*'` cannot select a family of
  repositories.

A unique alias would do the job of an id without a second identity. Rule 6
gives up enforced uniqueness on reads for the reason above; rule 7 keeps
vcspull's own writers from creating a duplicate.

## Consequences

- You can run `vcspull sync libtmux-docs`, and `status` rows for same-named
  checkouts are distinguishable.
- Configurations without `alias:` are unaffected, apart from the new `alias`
  field in JSON rows.
- The published configuration schema gains `alias` with the same pattern the
  loader enforces.
- A handle can select more than one entry. Scripts that need exactly one
  repository keep using a path term.
- `add` gains a second behaviour, attaching to an existing entry. Rules 13 to
  15 exist because that is the part of the design where a wrong edit is
  possible.
- Removing or renaming an alias is a manual edit.

## Not decided here

- **Aliases that start with `git`, `http`, `svn`, or `hg`.** `sync` reads such
  a term as a URL, the same limit a directory named `git-tools` has
  today ([#559](https://github.com/vcs-python/vcspull/issues/559)). An alias
  such as `git-tools` cannot be selected by `sync` until that is settled.
- **Where warnings print.** vcspull writes warnings to stdout, next to
  `--json` payloads. A handle warning in front of a JSON payload breaks a
  parser that reads stdout, and a shared alias makes that reachable. Moving
  warnings to stderr is a separate decision.
- **Conflicts between entries with the same name**
  ([#232](https://github.com/vcs-python/vcspull/issues/232)). This record
  covers aliases only.
- **More than one alias per entry.** A single string can widen to a list
  later without changing any rule above.
- **Case-insensitive filesystems.** Aliases compare case-sensitively. The
  prototype was not run on Windows or macOS.

## References

- [#586](https://github.com/vcs-python/vcspull/issues/586): Config has no way
  to give a repository an alias
- [#559](https://github.com/vcs-python/vcspull/issues/559): `sync` cannot
  match a name that starts with `http`, `git`, `svn`, or `hg`
- [#232](https://github.com/vcs-python/vcspull/issues/232): Name conflicts
- [#592](https://github.com/vcs-python/vcspull/issues/592): roadmap, which
  lists repository aliases
- {ref}`config-scopes`: how files in different scopes merge
