- Preprocessing (fallible)
- Get the path to the git directory relative to the current directory.
- Get git aliases.
- Read the cache file (regardless of git command).
- Parsing (infallible)
- Pass the CLI arguments through a function to obtain a final list of arguments to actually run.
- This is where numbers and number-ranges are converted to pathspecs, depending on the cache.
- Running (fallible)
- If git's sub-command is
status
, then print and parse the output to build the next cache. - Otherwise, run the args as-is.
- If git's sub-command is
- if Preprocessing fails:
Pass the raw CLI arguments into agit
command and run that and use the same exit code. - if Running fails:
Non-issue. Failing here means there was probably something wrong with the user-supplied command.
Based on git's source code, in the function
execv_dashed_external
, any executable that is in $PATH
that is
named git-foo-bar
can be ran with git foo-bar
.
Additionally, flags placed after git
and before foo-bar
will be
seen by git
but not by git-foo-bar
.
Amazingly, this is not necessary as git
will handle all flags in
this range.
For example, the -C
flag will make git run from a different
directory, and that will be accounted for by git
, and not git-nu
.
Same with configurations set with the -c
flag.
So running this command from /foo
> git -C /bar -c alias.zoom=ls-files nu zoom
Will actually run git ls-files
on the repo located at /bar
.
The caveat is that in code, git-nu
sees zoom
as the only argument
(apart from the binary path), and will effectively return git zoom
.
Setting the directory (from -C
) and aliasing zoom
to ls-files
(from -c
) are managed by git
.
This is the directory where the HEAD
file is stored. On a normal
clone, it is at .git/HEAD
, and in bare repositories it's in
.git/worktrees/<worktree name>/HEAD
. So depending on the state of
the repo, the value of git-dir
may be one of the following:
.git
.git/worktrees/<worktree name>
git-dir
can be found by running the command git rev-parse --git-dir
from anywhere in the git workspace.
Stored in the git directory. It stores the output of the
last run of git status
in that workspace.
The first line is the working directory from which git status
was
ran.
The remaining lines are the ordered pathspecs of that run of git status
.