Skip to main content

Module aliases

Module aliases 

Source
Expand description

url.<base>.insteadOf <alias> rewrite handling.

Git lets users define URL prefix aliases in config: git config url."https://github.com/".insteadOf gh: makes any URL starting with gh: rewrite to https://github.com/.... The git tooling applies this rewrite universally; LFS has to do the same so settings like lfs.url = gh:org/repo resolve the same way the user’s git fetch already does.

The rewrite logic itself is dead simple — pick the longest alias that’s a prefix of the input URL and swap it for the configured base. The only subtlety is duplicate detection: when two url.<base>.insteadOf entries share the same alias value but disagree on the base, we emit warning: Multiple 'url.*.insteadof' keys with the same alias: ... once per process, mirroring upstream.

Functions§

apply
Pure function: given a built alias map and a URL, do the longest- prefix-match rewrite. Split out so unit tests don’t need a temp repo, and exposed so callers that already hold an Aliases map (e.g. the transfer queue, which captures the map once at startup instead of re-locking the per-call cache) can apply it directly.
load_aliases
Load the alias map for cwd, warning once-per-process about conflicts. Cached so repeated calls within one process don’t fire git config again.
rewrite
Apply url.*.insteadOf rewriting to url, returning the longest- prefix-match rewrite or the original string if nothing matches.

Type Aliases§

Aliases
Maps <alias><base> for every url.<base>.insteadOf <alias> entry in the effective git config.