View Source git (egit v0.1.8)

Link to this section Summary

Types

Branch creation options
overwrite
Force to overwrite the existing branch
{target, Commit}
Use the target commit (default <<"HEAD">>)
Configuration source. If the value is an atom, then:
default
Find default configuration file for this app
system
System-wide configuration file - /etc/gitconfig on Linux systems
xdg
XDG compatible configuration file, typically ~/.config/git/config
global
User-specific global configuration file, typically ~/.gitconfig
local
Repository specific configuration file; $WORK_DIR/.git/config on non-bare repos
app
Application specific configuration file; freely defined by applications
highest
The most specific config file available for the app
List branch option.
local
Return only local branches
remote
Return only remote branches
all
Return all branches (default)
fullname
Return full branch names
{limit, Limit}
Return up to this number of branches
List index option.
{abbrev, NumChars}
NumChars truncates the commit hash (must be less then 40).
{fields, ListOfFields}
Field list to return. If not specified, the option will default to [path].
Status function options
{untracked, Untracked}
Untracked can be one of:
  • none - don't include untracked files
  • normal - include untracked files
  • recursive - include untracked files and recurse into untracked directories
  • {paths, Paths}
    Path is an array of path patterns to match
    branch
    Include branch name
    ignored
    Include ignored files
    ignore_submodules
    Indicates that submodules should be skipped
    submodules
    Include submodules (overrides ignore_submodules)
    Tag creation options
    {message, Msg}
    Message associated with the tag's commit
    {pattern, Pat}
    Pattern to search matching tags
    {target, SHA}
    Target commit SHA to be associated with the tag
    {lines, Num}
    Number of lines in the commit to store

    Functions

    Add files matching PathSpecs to index

    See also: add/3.

    Add files matching PathSpecs to index with options
    Add all pending changes
    Create a branch Example:
      1> R = git:clone(<<"https://github.com/saleyn/egit.git">>, "/tmp/egit").
      #Ref<0.170091758.2335834136.12133>
      2> git:branch_create(R, "tmp").
      ok
    Delete a branch
    Provide content or type and size information for repository objects.
    Provide content or type and size information for repository objects. Example:
      1> R = git:open(".").
      2> git:cat_file(R, "main", [{abbrev, 5}]).
      #{type => commit,
        author => {<<"John Doh">>,<<"test@gmail.com">>,1686195121, -14400},
        oid => <<"b85d0">>,
        parents => [<<"1fd4b">>]}
      7> git:cat_file(R, "b85d0", [{abbrev, 5}]).
      #{type => tree,
        commits =>
            [{<<".github">>,<<"tree">>,<<"1e41f">>,16384},
             {<<".gitignore">>,<<"blob">>,<<"b893a">>,33188},
             {<<".gitmodules">>,<<"blob">>,<<"2550a">>,33188},
             {<<".vscode">>,<<"tree">>,<<"c7b1b">>,16384},
             {<<"LICENSE">>,<<"blob">>,<<"d6456">>,33188},
             {<<"Makefile">>,<<"blob">>,<<"2d635">>,33188},
             {<<"README.md">>,<<"blob">>,<<"7b3d0">>,33188},
             {<<"c_src">>,<<"tree">>,<<"147f3">>,16384},
             {<<"rebar.config">>,<<"blob">>,<<"1f68a">>,33188},
             {<<"rebar.lock">>,<<"blob">>,<<"57afc">>,33188},
             {<<"src">>,<<"tree">>,<<"1bccb">>,16384}]}
      8> git:cat_file(R, "b893a", [{abbrev, 5}]).
      #{type => blob,
        blob => <<"*.swp\n*.dump\n/c_src/*.o\n/c_src/fmt\n/priv/*.so\n/_build\n/doc\n">>}
    Same as checkout(Repo, Revision, []).
    Provide content or type and size information for repository objects. If Opts contains verbose (and optionally perf), then the return is a map with checkout stats.
    Clone a remote repository to the local path
    Commit changes to a repository
    Lookup commit details identified by OID
    Get git configuration value Example:
      1> R = git:clone(<<"https://github.com/saleyn/egit.git">>, "/tmp/egit").
      #Ref<0.170091758.2335834136.12133>
      2> git:config_get(R, "user.name").
      {ok,<<"John Doh">>}
    Set git configuration value Example:
      1> R = git:clone(<<"https://github.com/saleyn/egit.git">>, "/tmp/egit").
      #Ref<0.170091758.2335834136.12133>
      2> git:config_set(R, "user.name", "Test User").
      ok
    Fetch from origin
    Fetch from given remote (e.g. <<"origin">>)
    Init a repository.

    See also: init/2.

    Init a repository. If Opts list contains bare, a Git repository without a working directory is created at the pointed path. Otherwise, the provided path will be considered as the working directory into which the .git directory will be created.
    List branches

    See also: list_branches/2.

    List index

    See also: list_index/2.

    List remotes
    List all tags
    List all tags
    Open a local git repository
    Pull from origin
    Pull from given remote (e.g. <<"origin">>)
    Push changes to remote ("origin")
    Push to given remote
    Push refs to given remote
    Delete a remote
    Add a remote. If Opts contains push, then the repository is pushed ot the remote URL.

    Return the list of OIDs for the given specs.

    Same as rev_parse(Repo, Spec, []).
    Get repository status
    Get repository status
    Create a tag
    Delete a tag

    Link to this section Types

    -type add_opt() :: verbose | dry_run | update | force.
    -type add_opts() :: [add_opt()].
    -type add_result() :: nil | #{mode => dry_run | added, files => [binary()]} | {error, term()}.
    -type branch_create_opts() :: [overwrite | {target, binary()}].
    Branch creation options
    overwrite
    Force to overwrite the existing branch
    {target, Commit}
    Use the target commit (default <<"HEAD">>)
    -type cat_file_opt() :: type | size | {abbrev, pos_integer()}.
    -type cat_file_opts() :: [cat_file_opt()].
    -type cfg_source() :: repository() | default | system | xdg | global | local | app | highest.
    Configuration source. If the value is an atom, then:
    default
    Find default configuration file for this app
    system
    System-wide configuration file - /etc/gitconfig on Linux systems
    xdg
    XDG compatible configuration file, typically ~/.config/git/config
    global
    User-specific global configuration file, typically ~/.gitconfig
    local
    Repository specific configuration file; $WORK_DIR/.git/config on non-bare repos
    app
    Application specific configuration file; freely defined by applications
    highest
    The most specific config file available for the app
    -type checkout_opt() :: force | verbose | perf.
    -type checkout_opts() :: [checkout_opt()].
    -type checkout_stats() ::
        #{chmod_calls => integer(),
          mkdir_calls => integer(),
          stat_calls => integer(),
          total_steps => integer()}.
    -type commit_opt() ::
        encoding | message | summary | time | time_offset | committer | author | header | tree_id.
    -type commit_opts() :: [commit_opt()].
    -type list_branch_opt() :: local | remote | all | fullname | {limit, pos_integer()}.
    List branch option.
    local
    Return only local branches
    remote
    Return only remote branches
    all
    Return all branches (default)
    fullname
    Return full branch names
    {limit, Limit}
    Return up to this number of branches
    -type list_branch_opts() :: [list_branch_opt()].
    -type list_index_entry() ::
        #{path => binary(),
          stage => [normal | ancestor | ours | theirs],
          conflict => boolean(),
          oid => binary(),
          mode => pos_integer(),
          size => non_neg_integer(),
          ctime => pos_integer(),
          mtime => pos_integer()}.
    -type list_index_opt() ::
        {abbrev, pos_integer()} |
        {fields, all | [path | stage | conflict | oid | mode | size | ctime | mtime]}.
    List index option.
    {abbrev, NumChars}
    NumChars truncates the commit hash (must be less then 40).
    {fields, ListOfFields}
    Field list to return. If not specified, the option will default to [path].
    -type list_index_opts() :: [list_index_opt()].
    -type repository() :: reference().
    -type rev_list_opt() ::
        [topo_order | date_order | reverse | {limit, pos_integer()} | {abbrev, pos_integer()}].
    -type rev_list_opts() :: [rev_list_opt()].
    -type rev_parse_opt() :: {abbrev, pos_integer()}.
    -type rev_parse_opts() :: [rev_parse_opt()].
    -type status_opt() ::
        {untracked, none | normal | recursive} |
        {paths, [binary()]} |
        branch | ignored | submodules | ignore_submodules.
    Status function options
    {untracked, Untracked}
    Untracked can be one of:
  • none - don't include untracked files
  • normal - include untracked files
  • recursive - include untracked files and recurse into untracked directories
  • {paths, Paths}
    Path is an array of path patterns to match
    branch
    Include branch name
    ignored
    Include ignored files
    ignore_submodules
    Indicates that submodules should be skipped
    submodules
    Include submodules (overrides ignore_submodules)
    -type status_opts() :: [status_opt()].
    -type tag_opt() :: [{message, binary()} | {pattern, binary()} | {target, binary()} | {lines, integer()}].
    Tag creation options
    {message, Msg}
    Message associated with the tag's commit
    {pattern, Pat}
    Pattern to search matching tags
    {target, SHA}
    Target commit SHA to be associated with the tag
    {lines, Num}
    Number of lines in the commit to store
    -type tag_opts() :: [tag_opt()].

    Link to this section Functions

    -spec add(repository(), binary() | string() | [binary() | string()]) -> add_result().
    Add files matching PathSpecs to index

    See also: add/3.

    Link to this function

    add(Repo, PathSpecs, Opts)

    View Source
    -spec add(repository(), [binary() | string()], add_opts()) -> add_result().
    Add files matching PathSpecs to index with options
    -spec add_all(repository()) -> add_result().
    Add all pending changes
    Link to this function

    branch_create(Repo, Name)

    View Source
    Create a branch

    See also: git:branch_create/3.

    Link to this function

    branch_create(Repo, Name, Opts)

    View Source
    -spec branch_create(repository(), binary() | string(), branch_create_opts()) -> ok | {error, binary()}.
    Create a branch Example:
      1> R = git:clone(<<"https://github.com/saleyn/egit.git">>, "/tmp/egit").
      #Ref<0.170091758.2335834136.12133>
      2> git:branch_create(R, "tmp").
      ok
    Link to this function

    branch_delete(Repo, Name)

    View Source
    -spec branch_delete(repository(), binary() | string()) -> ok | {error, binary()}.
    Delete a branch
    Link to this function

    branch_rename(Repo, OldName, NewName)

    View Source
    Rename a branch

    See also: branch_rename/4.

    Link to this function

    branch_rename(Repo, OldName, NewName, Opts)

    View Source
    -spec branch_rename(repository(), binary() | string(), binary() | string(), [overwrite]) ->
                     ok | {error, binary()}.
    Rename a branch
    -spec cat_file(repository(), binary() | string()) -> {ok, term()} | {error, term()}.
    Provide content or type and size information for repository objects.
    Link to this function

    cat_file(Repo, Rev, Opts)

    View Source
    -spec cat_file(repository(), binary() | string(), cat_file_opts()) -> {ok, term()} | {error, term()}.
    Provide content or type and size information for repository objects. Example:
      1> R = git:open(".").
      2> git:cat_file(R, "main", [{abbrev, 5}]).
      #{type => commit,
        author => {<<"John Doh">>,<<"test@gmail.com">>,1686195121, -14400},
        oid => <<"b85d0">>,
        parents => [<<"1fd4b">>]}
      7> git:cat_file(R, "b85d0", [{abbrev, 5}]).
      #{type => tree,
        commits =>
            [{<<".github">>,<<"tree">>,<<"1e41f">>,16384},
             {<<".gitignore">>,<<"blob">>,<<"b893a">>,33188},
             {<<".gitmodules">>,<<"blob">>,<<"2550a">>,33188},
             {<<".vscode">>,<<"tree">>,<<"c7b1b">>,16384},
             {<<"LICENSE">>,<<"blob">>,<<"d6456">>,33188},
             {<<"Makefile">>,<<"blob">>,<<"2d635">>,33188},
             {<<"README.md">>,<<"blob">>,<<"7b3d0">>,33188},
             {<<"c_src">>,<<"tree">>,<<"147f3">>,16384},
             {<<"rebar.config">>,<<"blob">>,<<"1f68a">>,33188},
             {<<"rebar.lock">>,<<"blob">>,<<"57afc">>,33188},
             {<<"src">>,<<"tree">>,<<"1bccb">>,16384}]}
      8> git:cat_file(R, "b893a", [{abbrev, 5}]).
      #{type => blob,
        blob => <<"*.swp\n*.dump\n/c_src/*.o\n/c_src/fmt\n/priv/*.so\n/_build\n/doc\n">>}
    -spec checkout(repository(), binary() | string()) -> ok | {error, term()}.
    Same as checkout(Repo, Revision, []).
    Link to this function

    checkout(Repo, Revision, Opts)

    View Source
    -spec checkout(repository(), binary(), checkout_opts()) -> ok | checkout_stats() | {error, term()}.
    Provide content or type and size information for repository objects. If Opts contains verbose (and optionally perf), then the return is a map with checkout stats.
    -spec clone(binary() | string(), binary() | string()) -> repository().
    Clone a remote repository to the local path
    -spec commit(repository(), binary() | string()) -> {ok, OID :: binary()} | {error, binary() | atom()}.
    Commit changes to a repository
    Link to this function

    commit_lookup(Repo, OID, Opts)

    View Source
    -spec commit_lookup(repository(), binary() | string(), [commit_opt()]) -> #{commit_opt() => term()}.
    Lookup commit details identified by OID
    -spec config_get(cfg_source(), binary() | string()) -> {ok, binary()} | {error, binary() | atom()}.
    Get git configuration value Example:
      1> R = git:clone(<<"https://github.com/saleyn/egit.git">>, "/tmp/egit").
      #Ref<0.170091758.2335834136.12133>
      2> git:config_get(R, "user.name").
      {ok,<<"John Doh">>}
    Link to this function

    config_set(Src, Key, Val)

    View Source
    -spec config_set(cfg_source(), binary() | string(), binary() | string()) ->
                  ok | {error, binary() | atom()}.
    Set git configuration value Example:
      1> R = git:clone(<<"https://github.com/saleyn/egit.git">>, "/tmp/egit").
      #Ref<0.170091758.2335834136.12133>
      2> git:config_set(R, "user.name", "Test User").
      ok
    -spec fetch(repository()) -> ok | {error, binary()}.
    Fetch from origin
    -spec fetch(repository(), binary() | string()) -> ok | {error, binary()}.
    Fetch from given remote (e.g. <<"origin">>)
    -spec init(binary() | string()) -> repository().
    Init a repository.

    See also: init/2.

    -spec init(binary() | string(), [bare]) -> repository().
    Init a repository. If Opts list contains bare, a Git repository without a working directory is created at the pointed path. Otherwise, the provided path will be considered as the working directory into which the .git directory will be created.
    List branches

    See also: list_branches/2.

    Link to this function

    list_branches(Repo, Opts)

    View Source
    -spec list_branches(repository(), list_branch_opts()) -> [{local | remote, binary()}].
    List branches
    List index

    See also: list_index/2.

    -spec list_index(repository(), list_index_opts()) -> [list_index_entry()].
    List index.
    -spec list_remotes(repository()) -> [{binary(), binary()}].
    List remotes
    -spec list_tags(repository()) -> [binary() | {binary(), binary()}] | {error, binary() | atom()}.
    List all tags
    Link to this function

    list_tags(Repo, Pattern)

    View Source
    -spec list_tags(repository(), string() | binary()) ->
                 [binary() | {binary(), binary()}] | {error, binary() | atom()}.
    List all tags
    -spec open(binary() | string()) -> repository().
    Open a local git repository
    -spec pull(repository()) -> ok | {error, binary()}.
    Pull from origin
    -spec pull(repository(), binary() | string()) -> ok | {error, binary()}.
    Pull from given remote (e.g. <<"origin">>)
    -spec push(repository()) -> ok | {error, binary()}.
    Push changes to remote ("origin")
    -spec push(repository(), binary() | string()) -> ok | {error, binary()}.
    Push to given remote
    Link to this function

    push(Repo, Remote, Refs)

    View Source
    -spec push(repository(), binary() | string(), [binary() | string()]) -> ok | {error, binary()}.
    Push refs to given remote
    Link to this function

    remote_add(Repo, Name, URL)

    View Source
    -spec remote_add(repository(), binary() | string(), binary() | string()) -> ok | {error, binary()}.
    Add a remote
    Link to this function

    remote_delete(Repo, Name)

    View Source
    -spec remote_delete(repository(), binary() | string()) -> ok | {error, binary()}.
    Delete a remote
    Link to this function

    remote_rename(Repo, OldName, NewName)

    View Source
    -spec remote_rename(repository(), binary() | string(), binary() | string()) -> ok | {error, binary()}.
    Rename a remote
    Link to this function

    remote_set_url(Repo, Name, URL)

    View Source
    -spec remote_set_url(repository(), binary() | string(), binary() | string()) -> ok | {error, binary()}.
    Delete a remote
    Link to this function

    remote_set_url(Repo, Name, URL, Opts)

    View Source
    Add a remote. If Opts contains push, then the repository is pushed ot the remote URL.
    -spec reset(repository(), soft | mixed | hard) -> ok | {error, term()}.
    Link to this function

    rev_list(Repo, Specs, Opts)

    View Source
    -spec rev_list(repository(), ['not' | 'Elixir.Not' | string() | binary()] | binary(), rev_list_opts()) ->
                #{commit_opt() => term()}.

    Return the list of OIDs for the given specs.

    Opts is a list of:
    topo_order | date_order | reverse
    Control sorting order
    {limit, Limit}
    Limit is an integer that limits the number of refs returned
    {abbrev, NumChars}
    NumChars truncates the commit hash (must be less then 40)
    Example:
      9> git:rev_list(R, ["HEAD"], [{limit, 4}, {abbrev, 7}]).
      [<<"f791f01">>,<<"1b74c46">>,<<"c40374d">>,<<"12968bd">>]
    -spec rev_parse(repository(), binary() | string()) ->
                 {ok, binary()} | map() | {error, binary() | atom()}.
    Same as rev_parse(Repo, Spec, []).
    Link to this function

    rev_parse(Repo, Spec, Opts)

    View Source
    -spec rev_parse(repository(), binary() | string(), rev_parse_opts()) ->
                 {ok, binary()} | map() | {error, binary() | atom()}.

    Reverse parse a reference. See https://git-scm.com/docs/git-rev-parse.html#_specifying_revisions for the formats of a Spec.

    Opts is a list of:
    {abbrev, NumChars}
    NumChars truncates the commit hash (must be less then 40)

    When a reference refers to a single object, an ok tuple with a binary string of the commit hash is returned. When it refers to a range (e.g. HEAD..HEAD~2`), a map is returned with `from and to keys. When using a Symmetric Difference Notation ... (i.e. HEAD...HEAD~4), a map with three keys from, to, and merge_base is returned.

    Examples:
      2> git:rev_parse(R,<<"HEAD~4">>, [{abbrev, 7}]).
      {ok,<<"6d6f662">>}
      3> git:rev_parse(R,<<"HEAD..HEAD~4">>, [{abbrev, 7}]).
      git:rev_parse(R,<<"HEAD..HEAD~4">>, [{abbrev, 7}]).
      #{from => <<"f791f01">>,to => <<"6d6f662">>}
      4> git:rev_parse(R,<<"HEAD...HEAD~4">>).
      git:rev_parse(R,<<"HEAD...HEAD~4">>, [{abbrev, 7}]).
      #{from => <<"f791f01">>,merge_base => <<"6d6f662">>, to => <<"6d6f662">>}
    -spec status(repository()) -> map() | {error, term()}.
    Get repository status
    -spec status(repository(), status_opts()) -> map() | {error, term()}.
    Get repository status
    -spec tag_create(repository(), string() | binary()) -> ok | {error, binary() | atom()}.
    Create a tag
    Link to this function

    tag_create(Repo, Tag, Msg)

    View Source
    -spec tag_create(repository(), string() | binary(), nil | string() | binary()) ->
                  ok | {error, binary() | atom()}.
    Create a tag
    Link to this function

    tag_create(Repo, Tag, Msg, Opts)

    View Source
    -spec tag_create(repository(), string() | binary(), nil | string() | binary(), tag_opts()) ->
                  ok | {error, binary() | atom()}.
    Create a tag
    -spec tag_delete(repository(), string() | binary()) -> ok | {error, binary() | atom()}.
    Delete a tag