View Source git (egit v0.1.8)
Link to this section Summary
Types
- overwrite
- Force to overwrite the existing branch
- {target, Commit}
- Use the target commit (default
<<"HEAD">>
)
- 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
- 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
- {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]
.
- {untracked,
Untracked
} none
- don't include untracked filesnormal
- include untracked filesrecursive
- 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
)
Untracked
can be one of:- {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
PathSpecs
to indexSee also: add/3.
PathSpecs
to index with optionsSee also: git:branch_create/3.
1> R = git:clone(<<"https://github.com/saleyn/egit.git">>, "/tmp/egit").
#Ref<0.170091758.2335834136.12133>
2> git:branch_create(R, "tmp").
ok
See also: branch_rename/4.
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">>}
checkout(Repo, Revision, [])
.Opts
contains verbose
(and optionally perf
), then the return is a map with checkout stats. 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">>}
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
<<"origin">>
)See also: init/2.
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.See also: list_branches/2.
See also: list_index/2.
<<"origin">>
)"origin"
)Opts
contains push
, then the repository is pushed ot the remote URL
.Return the list of OIDs for the given specs.
rev_parse(Repo, Spec, [])
.Reverse parse a reference. See https://git-scm.com/docs/git-rev-parse.html#_specifying_revisions for the formats of a Spec
.
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()}].
- 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.
- 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()}.
- 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]}.
- {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.
- {untracked,
Untracked
} none
- don't include untracked filesnormal
- include untracked filesrecursive
- 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
)
Untracked
can be one of:-type status_opts() :: [status_opt()].
-type tag_opt() :: [{message, binary()} | {pattern, binary()} | {target, binary()} | {lines, integer()}].
- {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().
PathSpecs
to indexSee also: add/3.
-spec add(repository(), [binary() | string()], add_opts()) -> add_result().
PathSpecs
to index with options
-spec add_all(repository()) -> add_result().
See also: git:branch_create/3.
-spec branch_create(repository(), binary() | string(), branch_create_opts()) -> ok | {error, binary()}.
1> R = git:clone(<<"https://github.com/saleyn/egit.git">>, "/tmp/egit").
#Ref<0.170091758.2335834136.12133>
2> git:branch_create(R, "tmp").
ok
-spec branch_delete(repository(), binary() | string()) -> ok | {error, binary()}.
See also: branch_rename/4.
-spec branch_rename(repository(), binary() | string(), binary() | string(), [overwrite]) -> ok | {error, binary()}.
-spec cat_file(repository(), binary() | string()) -> {ok, term()} | {error, term()}.
-spec cat_file(repository(), binary() | string(), cat_file_opts()) -> {ok, term()} | {error, term()}.
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()}.
checkout(Repo, Revision, [])
.
-spec checkout(repository(), binary(), checkout_opts()) -> ok | checkout_stats() | {error, term()}.
Opts
contains verbose
(and optionally perf
), then the return is a map with checkout stats.
-spec clone(binary() | string(), binary() | string()) -> repository().
-spec commit(repository(), binary() | string()) -> {ok, OID :: binary()} | {error, binary() | atom()}.
-spec commit_lookup(repository(), binary() | string(), [commit_opt()]) -> #{commit_opt() => term()}.
-spec config_get(cfg_source(), binary() | string()) -> {ok, binary()} | {error, binary() | atom()}.
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">>}
-spec config_set(cfg_source(), binary() | string(), binary() | string()) -> ok | {error, binary() | atom()}.
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()}.
-spec fetch(repository(), binary() | string()) -> ok | {error, binary()}.
<<"origin">>
)
-spec init(binary() | string()) -> repository().
See also: init/2.
-spec init(binary() | string(), [bare]) -> repository().
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.
See also: list_branches/2.
-spec list_branches(repository(), list_branch_opts()) -> [{local | remote, binary()}].
See also: list_index/2.
-spec list_index(repository(), list_index_opts()) -> [list_index_entry()].
-spec list_remotes(repository()) -> [{binary(), binary()}].
-spec list_tags(repository()) -> [binary() | {binary(), binary()}] | {error, binary() | atom()}.
-spec list_tags(repository(), string() | binary()) -> [binary() | {binary(), binary()}] | {error, binary() | atom()}.
-spec open(binary() | string()) -> repository().
-spec pull(repository()) -> ok | {error, binary()}.
-spec pull(repository(), binary() | string()) -> ok | {error, binary()}.
<<"origin">>
)
-spec push(repository()) -> ok | {error, binary()}.
"origin"
)
-spec push(repository(), binary() | string()) -> ok | {error, binary()}.
-spec push(repository(), binary() | string(), [binary() | string()]) -> ok | {error, binary()}.
-spec remote_add(repository(), binary() | string(), binary() | string()) -> ok | {error, binary()}.
-spec remote_delete(repository(), binary() | string()) -> ok | {error, binary()}.
-spec remote_rename(repository(), binary() | string(), binary() | string()) -> ok | {error, binary()}.
-spec remote_set_url(repository(), binary() | string(), binary() | string()) -> ok | {error, binary()}.
Opts
contains push
, then the repository is pushed ot the remote URL
.
-spec reset(repository(), soft | mixed | hard) -> ok | {error, term()}.
-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)
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()}.
rev_parse(Repo, Spec, [])
.
-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
.
- {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.
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()}.
-spec status(repository(), status_opts()) -> map() | {error, term()}.
-spec tag_create(repository(), string() | binary()) -> ok | {error, binary() | atom()}.
-spec tag_create(repository(), string() | binary(), nil | string() | binary()) -> ok | {error, binary() | atom()}.
-spec tag_create(repository(), string() | binary(), nil | string() | binary(), tag_opts()) -> ok | {error, binary() | atom()}.
-spec tag_delete(repository(), string() | binary()) -> ok | {error, binary() | atom()}.