aro lists the repositories of GitHub organizations and users, GitLab groups and Forgejo instances, clones them in one of two layouts, keeps every clone up to date without losing local work, and generates tmux sessions for airmux or sesh and ttt workspaces for them. It runs on babashka and calls git, curl and, for tunnels, ssh.
aro fetch [SOURCE...] # list the sources' repositories into the inventory
aro list # print every repository with layout, branch and directory
aro list --dirs [REPO...] # print the canonical directory of every checkout, one per line, e.g. for breto
aro generate [--out DIR] # write the sessions and ttt workspaces
aro compare [--toml FILE]... # compare with the files on disk, print suggested config
aro clone [REPO...] [--max N] # clone what is missing, one at a time, at most N
aro update [REPO...] [--jobs N] # fetch and update every clone
aro mirror [REPO...] [--jobs N] # fetch and push origin's default branch and tags to the mirrors
aro maintain --schedule S [REPO...] # run git's maintenance tasks for hourly, daily or weekly
aro prune [REPO...] [--dry-run] # delete local branches origin's default branch holds
aro prune [REPO...] --switch-merged # first return checkouts on merged branches home
aro orphans [--delete] # list clones no repository names, remove those without local work
aro layout REPO worktrees|plain [--keep B] # switch a clone between the layoutsaro clone --max N clones at most N missing repositories and leaves the rest to the next run, so a timer works through a large backlog over several days instead of saturating the link in one go. --delay SECONDS, or :delay in the config, waits between two clones.
REPO is an id such as github.com:metio/aro, a clone URL, or a directory inside a clone, so aro layout . worktrees works from within a repository. The config is read from $XDG_CONFIG_HOME/aro/config.edn unless --config names another file.
aro fetch is the only command that talks to a forge. It writes what each source listed to the inventory file, and every other command reads that file. A source that fails keeps the records of its last successful fetch, so a forge that is unreachable for the moment changes nothing. Several machines can share one inventory: point :inventory at a file in a repository they all pull, and let one machine run aro fetch with a :fetched hook that commits and pushes it.
{:inventory "/home/me/dotfiles/aro-inventory.edn"
:hooks {:fetched ["/home/me/.local/bin/git-commit-and-push-file" "{inventory}" "chore: update the aro inventory"]}}Comment lines at the top of the inventory, such as a license header, survive a rewrite.
{:sources
[{:id "metio" :github {:org "metio"} :token-command ["gh" "auth" "token"]}
{:id "me" :github {:user "sebhoss"}}
{:id "codeberg" :forgejo {:url "https://codeberg.org" :user "sebhoss"} :session-dir "me"}
{:id "work" :gitlab {:url "https://git.example.org" :group "team"}
:token-command ["passage" "show" "git.example.org/token"]
:tunnel {:ssh "admin@git.example.org" :target "localhost:443"}
:layout :worktrees}]}| Key | Meaning |
|---|---|
:github, :gitlab, :forgejo |
The forge and the organization, user or group to list: :org or :user on GitHub and Forgejo, :group or :user on GitLab, or :membership true for every GitLab project the token's account is a member of. GitLab groups include their subgroups, and leave out projects of other namespaces shared with the group. GitLab and Forgejo take the instance's :url; GitHub takes one only for a GitHub Enterprise server, as its API URL such as https://ghe.example.org/api/v3, and its repositories are then recorded under that server's host. |
:token-command |
A command printing a token on its first line, for private repositories. A :user with a token lists the repositories the token's account owns, private ones included; a token of another account lists none. |
:tunnel |
An SSH port forward for a forge API that only listens on its own host. |
:host |
The host recorded for the repositories, when the URL differs from the host used for cloning. |
:archived, :forks |
true keeps archived repositories or forks, which are left out otherwise. Disabled GitHub repositories, which cannot be cloned, are always left out. |
:layout |
The layout of the source's clones, overriding the top-level :layout (default :plain). |
:root |
The namespace session files are relative to. Defaults to the organization, user or group. |
:session-dir |
The directory below the airmux directory for the source's sessions. Defaults to the id. |
A :tunnel runs ssh -N -L 127.0.0.1:PORT:TARGET SSH on a free local port for the duration of the fetch, and curl reaches the forge's URL through --connect-to. The request keeps the forge's host name, so TLS still checks the forge's own certificate. The SSH destination must be an account that may forward ports; the git account of a forge usually may not.
Overrides go in :repositories, keyed by id; repositories the forges do not list go in :add. An id may be written in any spelling REPO accepts, in overrides, :mirrors and a group's :include and :exclude alike.
{:repositories {"github.com:metio/aro" {:layout :worktrees :branch "main"}
"github.com:sebhoss/dotfiles" {:dir "~/.local/share/chezmoi"
:session {:pane_commands ["alias s='nix develop'"]}}
"github.com:metio/old" {:include true}
"github.com:metio/noise" {:exclude true}}
:add [{:id "gitlab.com:someone/project" :source "me" :default-branch "master"}]}:dir is absolute, starts with ~, or is relative to :git-root (default ~/git). Without one, a clone lives at <git-root>/<host>/<path>. :mirrors lists the ids of copies of the repository on other forges, such as ["gitlab.com:someone/project" "codeberg.org:someone/project"], which aro mirror keeps in line with the repository, as described under Mirror sync. A GitHub repository can name its mirrors in a custom property mirrors as well, a string of ids separated by whitespace such as "gitlab.com:someone/project codeberg.org:someone/project"; its ids come first, followed by those of :mirrors, and an id both list counts once. A mirror gets no clone or session of its own, even when a source lists it. aro update removes any push URL of origin, so git push reaches the repository alone. :session replaces keys of the generated session, a nil value removes one, and :session false generates none. :session-file moves the session to another path below the airmux directory. Repositories of the same name in different namespaces get the last segment of their namespace in front of the generated session_name, such as charts-grafana and dashboards-grafana, unless :session sets one.
A group collects repositories into a ttt workspace and, with :session, a session opening it.
{:groups [{:id "helm-charts"
:match [{:namespace "team/helm-charts"} {:topic "helm"}]
:include ["git.example.org:team/tools/chart-tests"]
:exclude ["git.example.org:team/helm-charts/attic"]
:dirs ["~/notes/helm"]
:ttt "team-helm-charts.ttt"
:session {:file "work/helm-charts/all.yml" :session_name "team helm charts"}}]
:sessions {"metio/jaas.yml" {:session_name "jaas" :windows [...]}}}Each map in :match selects the repositories for which all its keys hold: :namespace, :namespace-prefix, :topic, :property, :host or :source. :property maps custom property names to values, such as {:property {:release "maven-central"}}, and holds when the repository has each of them; a multi-select property holds when one of its values is the one named. Custom properties come from GitHub, which lists them with each repository of an organization. :dirs adds folders that are no repository to the workspace, resolved like a repository's :dir. :sessions are written as they are, for sessions spanning several repositories.
The plain layout is an ordinary clone. The worktrees layout is a bare repository in .git with a worktree per branch next to it: the default branch tracking its upstream, and development started from it without an upstream.
aro layout REPO worktrees moves the checkout as it is into a worktree named after its branch, with uncommitted changes, the index, untracked and ignored files included, and adds the default branch and development next to it. aro layout REPO plain keeps the worktree of the default branch, or of --keep, as the plain clone. The other worktrees are removed and their branches remain. A worktree to remove that holds uncommitted changes, untracked or ignored files, or a detached HEAD with commits no branch holds, refuses the switch before anything changes, and the error lists them. Both directions refuse a clone with a merge or rebase in progress, and switching to worktrees refuses one with submodules. Set the repository's :layout in the config afterwards, so sessions and new clones follow.
aro orphans lists every clone below :git-root that is neither the clone of a configured repository nor inside a group's :dirs, such as clones of repositories that were archived, moved or deleted on their forge. Each line names what the clone holds only locally. aro orphans --delete removes the orphans holding nothing of that kind, along with the directories they leave empty, and keeps the rest with the reason. A clone counts as holding local work when a checkout has uncommitted changes or untracked files, when it has stash entries, when a branch, tag, note or detached HEAD reaches commits no remote-tracking branch holds, or when git cannot read it. Ignored files do not count, so build output and editor settings are removed with the clone.
aro update fetches every clone and brings each checked-out branch up to date with its upstream, or, for the default branch and development without an upstream, with the default branch of origin. It never loses local work:
- Uncommitted changes, staged and untracked files included, are stashed first and applied again afterwards, with the index as it was.
- A branch without commits of its own is fast-forwarded, and a branch with commits of its own is rebased.
- When the rebase conflicts, or the changes do not apply cleanly on the updated branch, the checkout goes back to the commit it was on with its changes as they were, and the branch is skipped. Changes to a file the update also changes stay in place when they merge without conflict.
- An update that starts tracking a file the clone holds as an ignored file, such as a local
.env, is skipped, since it would overwrite that file. - A detached HEAD, a merge or rebase in progress, a branch without upstream, and a branch whose upstream is gone are skipped.
With :push-mirrors true in the config, aro update also syncs the mirrors of each repository after fetching it, as aro mirror does.
Skipped branches print [SKIP] with the reason. A failed fetch prints [ERROR] and makes the command exit non-zero, which suits a systemd timer with OnFailure=. Git runs with GIT_TERMINAL_PROMPT=0 and, unless GIT_SSH_COMMAND, GIT_SSH or a core.sshCommand for the checkout is set, ssh -o BatchMode=yes, so a run without a terminal fails instead of waiting for input. A configured ssh command is used as it is, so add -o BatchMode=yes to it for unattended runs.
aro mirror fetches each clone whose repository has mirrors, from :mirrors or the custom property mirrors, and pushes the commit of origin's default branch to the default branch of every mirror, along with origin's tags. Other branches stay on origin. No push is forced:
- A mirror without the branch gets it, and one whose branch is behind origin's is fast-forwarded.
- A mirror whose branch is ahead of origin's or has diverged from it is left as it is and reported with
[WARN], naming the repository, the mirror and both commits. - Tags the mirror lacks are pushed, and a tag the mirror holds at another object is left as it is and reported with
[WARN]. - A mirror that cannot be reached or rejects the push is reported with
[WARN], and the other mirrors and repositories are synced all the same.
Warnings leave the exit code at zero; a failed fetch of origin prints [ERROR] and makes the command exit non-zero. The sync pushes from the clone's own objects, so commits that reach origin's default branch on the forge, through a merge queue, the web interface or a bot, reach the mirrors on the next run. aro update syncs the mirrors only with :push-mirrors true in the config (default false), so that one machine pushes to them while the others only fetch:
{:push-mirrors true
:repositories {"github.com:metio/ilo" {:mirrors ["gitlab.com:metio.wtf/ilo"]}}}A custom property mirrors on the repository, holding gitlab.com:metio.wtf/ilo, names the same mirror without the override. The property is read from the inventory, so a change of it takes effect with the next aro fetch.
aro maintain --schedule hourly|daily|weekly runs git maintenance run for that schedule in every clone, with the tasks of git's incremental strategy except prefetch, which aro update makes redundant: commit-graph hourly, loose-objects and incremental-repack daily, and pack-refs weekly. Without a strategy, a scheduled run has no tasks, and aro sets it for the run instead of in each clone's config. Clones that do not exist yet are skipped, so the list of clones comes from the config and the inventory alone. A templated systemd service running aro maintain --schedule=%i, started by a timer per schedule, keeps every clone maintained.
aro prune deletes the local branches whose commits the default branch of origin already holds, such as branches merged upstream and branches never committed to. The default branch, development and every branch a checkout has checked out stay. A branch whose upstream is gone but that holds commits origin lacks, such as one deleted after a squash merge, stays too and is reported with [SKIP]. --dry-run lists what would be deleted.
A checkout left on a feature branch keeps that branch, so with --switch-merged, aro prune first returns each checkout whose branch origin has merged to its home branch: the default branch in a plain clone, and in the worktrees layout the branch the worktree is named after. The development worktree goes back to development, main stays on main, and a worktree you added for a branch of its own has that branch as its home and stays as it is. The home branch then catches up with origin as in aro update, its own commits rebased, and the merged branch is deleted with the others; every deletion prints the commit the branch pointed at.
A branch counts as merged when origin's default branch holds its tip and the branch shows how it got there: its reflog records commits made on it, a merge commit brought it in, or its upstream is gone. A branch started from the default branch and only fast-forwarded since stays. A checkout keeps its branch, reported with [SKIP], during a merge or rebase, with uncommitted changes to tracked files, when another worktree has its home branch checked out, when the switch would overwrite ignored files, or while a process other than an idle shell has its working directory inside it. Untracked files carry over. Without /proc aro cannot see the processes and switches nothing.
--switch-merged on the command line switches right away. :switch-merged true in the config, or on a source or under :repositories, makes every aro prune switch, such as the one a timer runs, but only checkouts whose HEAD has not moved for :quiet-hours (default 24), so a branch you worked on recently stays checked out while you might still have it open:
{:switch-merged true
:quiet-hours 24}aro generate writes a session per repository and group for each session manager :session-managers names, by default [:airmux], and the workspaces to :ttt-dir (default $XDG_DATA_HOME/ttt). A manifest at :manifest (default $XDG_STATE_HOME/aro/generated) records what aro wrote, so a later run deletes files it no longer generates, those of a session manager taken off the list included, and leaves other files alone.
Sessions, their :session overrides and the custom :sessions are written in airmux's keys, and each session manager renders them in its own format:
| Session manager | Output |
|---|---|
:airmux |
A YAML file per session below :airmux-dir (default $XDG_CONFIG_HOME/airmux), at its session file. |
:sesh |
One TOML file, :sesh-file (default $XDG_CONFIG_HOME/sesh/aro.toml), for sesh.toml to read with import = ["~/.config/sesh/aro.toml"], so the rest of sesh.toml stays the user's. |
[:airmux :sesh] generates both. sesh opens a session's first window in its path and types its startup_command there; a first window without commands, such as {"shell" nil}, gets disable_startup_command, so the startup_command of sesh's [default_session] stays out of it. sesh opens every further window as a [[window]] that starts in the session's path, so aro gives that window a cd into its directory. sesh has no panes: a window keeps the first pane of its airmux window, its commands follow the session's and window's pane_commands, and aro generate warns about every pane and key that sesh cannot express, such as layout or on_start, and about sessions sharing a name, since sesh connects to the first of them. Windows written the same in several sessions, such as the worktree of the default branch, become one [[window]]. aro writes every clone's session, so sesh's [[wildcard]] patterns are only needed for directories aro does not manage.
aro compare reads the sessions and workspaces on disk and prints the config that would make aro generate them: layout overrides from the clones on disk, session keys that differ, files that match no repository, and group includes and excludes. A hand-written session naming directories that do not exist is reported as stale, and the generated keys are kept for it. --toml reads chezmoi data files listing repositories as [[x_git_repos]] tables with upstream, worktrees, branch and local.
The .breto.edn names the metio/toolchains groups that pin babashka and the lint tools CI runs. With that registry under the :registries of the breto config, breto env links them into the project:
eval "$(breto env)"
bb test0BSD.