View Source git (egit v0.1.3)

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

Functions

Same as add(Repo, FileSpecs, Opts).
Add files matching PathSpecs to index.
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 => {<<"Serge Aleynikov">>,<<"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,<<"Serge Aleynikov">>}
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">>)
List branches

See also: list_branches/2.

Open a local git repository
Pull from origin
Pull from given remote (e.g. <<"origin">>)

Return the list of OIDs for the given specs.

Same as rev_parse(Repo, Spec, []).

Link to this section Types

-type add_opt() :: verbose | dry_run | update | force.
-type add_opts() :: [add_opt()].
-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 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()].

Link to this section Functions

-spec add(repository(), binary() | string() | [binary() | string()]) -> [binary()] | {error, term()}.
Same as add(Repo, FileSpecs, Opts).
Link to this function

add(Repo, PathSpecs, Opts)

View Source
-spec add(repository(), [binary() | string()], add_opts()) -> [binary()] | {error, term()}.
Add files matching PathSpecs to index.
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 => {<<"Serge Aleynikov">>,<<"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,<<"Serge Aleynikov">>}
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">>)
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
-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">>)
Link to this function

rev_list(Repo, Specs, Opts)

View Source
-spec rev_list(repository(), ['not' | 'Elixir.Not' | 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">>}