Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Per-repo lease

fetch, pull, gc, maintenance, repack, pack-refs, prune, remote prune, remote update and worktree prune take an exclusive flock on <common-dir>/drawbar-lease.lock before git runs and hold it until git exits, so linked worktrees of one clone take turns updating shared refs and packs. The shim finds the common dir with git rev-parse --git-common-dir, passing along the caller’s -C, -c, --git-dir, --work-tree, --bare and --config-env, and resolves a relative answer against the directory the caller’s -C flags lead to. A leased git also runs with gc.autoDetach and maintenance.autoDetach off, so the housekeeping it starts finishes before the lease is released. Every other command runs with no lock and no extra process.

A command waits for the lease for DRAWBAR_LEASE_WAIT seconds, else AGENT_GIT_LEASE_WAIT, else lease.timeout_secs from the config, else 120. When the wait runs out, drawbar exits 75 and prints one line naming the lock file and the fuser -v command that shows who holds it.

When git cannot name a common dir, for example outside a repository, the command runs unleased and git reports its own error. When the lock file exists but this user cannot read it, drawbar exits 75 without running git. The lock file is close-on-exec, so git and anything git starts never hold it, and the kernel releases it whenever the shim exits. When the shim takes the lease it sets the lock file’s modification time to now, which is how drawbar doctor tells how long the lease has been held. A user who cannot write the file leaves the time as it was.

While a leased git runs, the shim waits on it and forwards SIGTERM, SIGINT, SIGHUP and SIGQUIT to it. Once git exits, the shim exits with git’s status, or dies of the same signal git died of. See ADR 0005.

Fetches through drawbard

When drawbard (Running drawbard) listens on $XDG_RUNTIME_DIR/drawbar/drawbard.sock, a leased git fetch asks it to run the fetch and holds no lease while it waits. The daemon runs one real fetch, under this lease, for all the fetches in flight that would start the same git with the same arguments, environment and umask in the same directory, and each caller prints that fetch’s output and exits with its status. A fetch with its own refspec, GIT_SSH_COMMAND or credential variables differs from the others, so it gets a fetch of its own and waits its turn for the lease. A fetch with --append, --depth, --deepen, --shallow-since, --shallow-exclude or --unshallow would do something different the second time, and the daemon cannot pass on the refspecs a --stdin fetch reads, so the shim never sends those to the daemon. The shim sends the lease wait it resolved with the request, so the daemon waits as long as the shim would have. Git sees the caller’s environment as it is, except for PWD, OLDPWD, SHLVL and _, which the daemon leaves out of every git it starts and out of the comparison.

The shim runs its own fetch under the lease, as above, when the socket is missing or not private to this user, the daemon refuses the fetch, the whole answer does not arrive within the lease wait plus 10 minutes, or the working directory’s path names a different directory by the time it does. The daemon refuses a request whose path no longer names the caller’s directory, and one whose path passes through a directory another user owns or can write to without the sticky bit, since that user could put another repository there before git starts. A shim that asked the daemon and got no answer it can use finds its lease again before its own fetch, since the repository it selects may have changed while it waited. A fetch the daemon runs has no terminal, so git cannot prompt there for a password or passphrase, though an askpass program still runs. Interrupting the shim does not stop a fetch the daemon has started, and a daemon killed with SIGKILL releases the lease while its fetch may still be writing refs. See ADR 0014, ADR 0015 and ADR 0016.