Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:18
erlgit
erlgit-0.7.5-git.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File erlgit-0.7.5-git.patch of Package erlgit
diff --git a/Emakefile b/Emakefile new file mode 100644 index 0000000..c665d1d --- /dev/null +++ b/Emakefile @@ -0,0 +1,7 @@ +{"src/*", [ + report, + verbose, + {i, "include"}, + {outdir, "ebin"}, + debug_info +]}. diff --git a/package.exs b/package.exs new file mode 100644 index 0000000..90589b3 --- /dev/null +++ b/package.exs @@ -0,0 +1,6 @@ +Expm.Package.new(name: "erlgit", description: "Convenience wrapper around git executable", + version: "0.7.5", keywords: ["git", "wrapper", "vcs"], + maintainers: [[name: "Gleb Peregud", + email: "gleber.p@gmail.com"]], + repositories: [[github: "gleber/erlgit"]]) + \ No newline at end of file diff --git a/src/erlgit.app.src b/src/erlgit.app.src index 0305430..b08bcb9 100644 --- a/src/erlgit.app.src +++ b/src/erlgit.app.src @@ -6,7 +6,8 @@ {applications, [ kernel, stdlib, - erlsemver + erlsemver, + sh ]}, {env, []} ]}. diff --git a/src/git.erl b/src/git.erl index ee29407..262aeaa 100644 --- a/src/git.erl +++ b/src/git.erl @@ -2,9 +2,12 @@ -export([download/2, download/3, + init/1, clone/2, clone/3, fetch/1, checkout/2, checkout/3, + remote/1, + remote/2, remote/3, status_is_detached/1, status_is_dirty/1, @@ -78,6 +81,17 @@ download(Url, Dir, Rev) -> {ok, _} = clone(Url, Dir, [no_checkout]), checkout(Dir, Rev). +%% +%% init empty project +-spec init(dir()) -> ok | {error, any()}. + +init(RepoDir) -> + ok = filelib:ensure_dir(filename:join([RepoDir, ".git"])), + sh(init_cmd(RepoDir), [{cd, RepoDir}]). + +init_cmd(_RepoDir) -> + "git init". + %% @throws {unable_to_clone, Reason :: list()}> -spec clone(url(), dir()) -> {'ok', string()} | {'error', term()}. clone(RepoURL, RepoPath) -> @@ -111,6 +125,35 @@ checkout(RepoDir, CommitID, Opts) -> checkout_cmd(_RepoDir, CommitID, Opts) -> fformat("git checkout ~s ~s", [opts(Opts), CommitID]). +%% @doc List of remote entities: git remote -v +%% +-spec remote(dir()) -> {ok, list()}. + +remote(Repo) -> + lists:usort( + [string_to_remote(X) || + X <- string:tokens(oksh("git remote -v", [{cd, Repo}]), "\n")] + ). + +string_to_remote(X) -> + [Name, Url, _] = string:tokens(X, "\t "), + {Name, Url}. + +%% +%% add git remote to existed repository +-spec remote(dir(), url()) -> ok | {error, any()}. +-spec remote(dir(), list(), url()) -> ok | {error, any()}. + +remote(RepoDir, RepoURL) -> + remote(RepoDir, "origin", RepoURL). + +remote(RepoDir, RemoteName, RepoURL) -> + sh(remote_add_cmd(RemoteName, RepoURL), [{cd, RepoDir}]). + +remote_add_cmd(RemoteName, RepoURL) -> + fformat("git remote add -t \\* -f ~s ~s", [RemoteName, RepoURL]). + + -spec branch(dir()) -> {'ok', branch()} | 'detached'. branch(Repo) -> case status_is_detached(Repo) of @@ -133,16 +176,22 @@ branches_commits(Repo) -> -spec refs(repo()) -> [{ref(), ref_type(), cid()}]. refs(Repo) -> Output = oksh(refs_cmd(Repo), []), - lists:map(fun(L) -> - [Commit, Ref] = string:tokens(L, "\t "), - {Type, Name} = case string:tokens(Ref, "/") of - ["refs", T | N] -> - {T, string:join(N, "/")}; - ["HEAD"] -> - {"HEAD", "HEAD"} - end, - {Name, list_to_atom(string:strip(Type, right, $s)), Commit} - end, string:tokens(Output, [13,10])). + lists:flatmap(fun(L) -> + case string:tokens(L, "\t ") of + ["DEBUG:"++_|_] -> + []; + ["WARNING:"|_] -> + []; + [Commit, Ref] -> + {Type, Name} = case string:tokens(Ref, "/") of + ["refs", T | N] -> + {T, string:join(N, "/")}; + ["HEAD"] -> + {"HEAD", "HEAD"} + end, + [{Name, list_to_atom(string:strip(Type, right, $s)), Commit}] + end + end, string:tokens(Output, [13,10])). refs_cmd(Repo) -> fformat("git ls-remote ~s", [Repo]). @@ -257,14 +306,24 @@ change_type("D ") -> indexed_deleted; change_type(" M") -> modified; +change_type("MM") -> + {several, [indexed_modified, modified]}; change_type(" D") -> deleted; change_type("??") -> untracked. status_changed_files(Repo, Prefix) -> - [ {change_type([A,B]), filename:join(Prefix, F)} - || [A,B,_ | F] <- string:tokens(oksh("git status --porcelain", [{cd, Repo}]), "\n") ]. + Status = string:tokens(oksh("git status --porcelain", [{cd, Repo}]), "\n"), + Changed = [ construct_change(change_type([A,B]), filename:join(Prefix, F)) || + [A,B,_ | F] <- Status ], + lists:flatten(Changed). + +construct_change({several, ChangeTypes}, Filename) -> + [ construct_change(ChangeType, Filename) || ChangeType <- ChangeTypes ]; +construct_change(ChangeType, Filename) -> + {ChangeType, Filename}. + add_files(Repo, Files, Prefix) -> sh("git add ~s", [string:join([filename:join(Prefix, F) || F <- Files], " ")], [{cd, Repo}]).
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor