Workspace. Git
(Workspace v0.4.2)
View Source
Helper git related functions
Summary
Functions
Detects the changed files in the given directory.
Get the changed files of the head git reference since it diverged from base.
Returns the files of the repository
Get the relative path of the given path in its git repository
Get the git repo root of the given path
Returns the submodules of the repository
Returns a list of uncommitted files
Get list of untracked files
Types
Functions
@spec changed(opts :: keyword()) :: {:ok, [{binary(), change_type()}]} | {:error, binary()}
Detects the changed files in the given directory.
By default the following files are included:
- Uncommitted files in the working directory
- Untracked files in the working directory
- If
:baseis provided it also includes the files changed on:headsince it diverged from:base, e.g.git diff base...head.:headdefaults toHEADif not set.
A list of tuples of the form {"path/to/changed/file", change_type} is
returned, where change_type can be one of the following:
:uncommitted- for changed files under version control that are not committed:untracked- for new files that are not under version control:modified- for changed committed files on:headsince it diverged from:base
Options
:cd(binary/0) - The git repo path, defaults to the current working directory.:base(binary/0) - The base reference to use for comparing to theHEAD, can be a branch, a commit or any othergitreference.:head(binary/0) - Theheadto use for comparing to:base, if not set defaults toHEAD. Can be any git reference
@spec changed_files(base :: binary(), head :: binary(), opts :: keyword()) :: {:ok, [binary()]} | {:error, binary()}
Get the changed files of the head git reference since it diverged from base.
The head is compared against the merge base of base and head, e.g.
changes of base after head diverged from it are not included. This is
equivalent to git diff base...head.
Options
:cd(binary/0) - The git repo path, defaults to the current working directory.
Returns the files of the repository
Both tracked files and untracked files which are not ignored are
included. The paths are relative to the :cd path.
Options
Get the relative path of the given path in its git repository
Returns {:ok, prefix} in case of success, where prefix is an empty
string for the repository root, or {:error, reason} in case of failure.
Options
:cd- the path to get the prefix of, if not set defaults to the current working directory.
Get the git repo root of the given path
Returns {:ok, path} in case of success or {:error, reason} in
case of failure.
If the given path is under a symlinked directory, the symlinked form of the root is returned, so that it can be safely compared with paths derived from the given path. If the path is itself a symlink pointing inside a repository there is no symlinked form of the root and the resolved root is returned.
Options
:cd- the path to use for getting the git root, if not set defaults to the current working directory.
Returns the submodules of the repository
The paths of the submodules registered in the index are returned, relative
to the :cd path, whether they are initialized or not. Nested submodules
are not included.
Options
:cd(binary/0) - The git repo path, defaults to the current working directory.
Returns a list of uncommitted files
Uncommitted are considered the files that are staged but not committed yet.
If the repository has no commits yet, all staged files are considered uncommitted.
Options
:cd(binary/0) - The git repo path, defaults to the current working directory.
Get list of untracked files
Options
:cd(binary/0) - The git repo path, defaults to the current working directory.