[erlang-questions] erlgit - convenience Erlang wrapper around git executable

Gleb Peregud gleber.p@REDACTED
Fri Aug 24 22:44:47 CEST 2012


Hello again folks!

I am glad to present yet another project open sourced by LivePress
Inc. This time it is a standalone convenience wrapper around git
executable:

https://github.com/gleber/erlgit

Here's an example of usage, which says everything about the project itself:

1> Local = "/tmp/erlgit".
"/tmp/erlgit"
2> git:clone("http://github.com/gleber/erlgit.git", Local).
{ok,"Cloning into '/tmp/erlgit'...\n"}
3> git:branches(Local).
["master"]
4> git:refs(Local).
[{"HEAD",'HEAD',"097428dda56dec6085747387645d6020f86cfae7"},
 {"master",head,"097428dda56dec6085747387645d6020f86cfae7"},
 {"origin/HEAD",remote, "097428dda56dec6085747387645d6020f86cfae7"},
 {"origin/master",remote, "097428dda56dec6085747387645d6020f86cfae7"},
 {"v0.3.0",tag,"be3b0ade881666286801ee8b218ecbf29da97558"},
 {"v0.3.1",tag,"89f2d81be12f6034db52fd6d71d8a4b96f4ee9de"},
 {"v0.3.2",tag,"3dc42981d9e4677654370614888ec3f368421240"},
 {"v0.5.0",tag,"097428dda56dec6085747387645d6020f86cfae7"}]
5> git:branch(Local).
"master"
6> git:tags(Local).
["v0.3.0","v0.3.1","v0.3.2","v0.5.0"]
7> os:cmd("touch "++Local++"/new_file").
[]
8> git:status_is_dirty(Local).
true
9> git:status_changed_files(Local).
[{untracked,"./new_file"}]
10> os:cmd("echo >> "++Local++"/README.md").
[]
11> git:status_changed_files(Local).
[{modified,"./README.md"},{untracked,"./new_file"}]
12> git:add_files(Local, ["new_file"]).
{ok,[]}
13> git:status_changed_files(Local).
[{modified,"./README.md"},{indexed_added,"./new_file"}]
14> git:commit(Local, "update README and add file").
{ok,"[master 3825b3c] update README and add file\n 0 files changed\n
create mode 100644 new_file\n"}
15> git:head(Local).
"3825b3cb5e713c5145b4b74445a4d5e6187e567d"

and it has some support for semantic versioning using erlsemver library:

16> rr("deps/erlsemver/include/*").
[semver]
17> git:version_tags(Local).
[#semver{x = 0,y = 3,z = 0,pre = <<>>,build = undefined},
 #semver{x = 0,y = 3,z = 1,pre = <<>>,build = undefined},
 #semver{x = 0,y = 3,z = 2,pre = <<>>,build = undefined},
 #semver{x = 0,y = 5,z = 0,pre = <<>>,build = undefined}]
18> git:tag(Local, semver:inc_z(#semver{x = 0,y = 5,z = 0,pre =
<<>>,build = undefined})).
#semver{x = 0,y = 5,z = 1,pre = <<>>,build = undefined}
19> lists:last(git:version_tags_commits(Local)).
{#semver{x = 0,y = 5,z = 1,pre = <<>>,build = undefined},
 "3825b3cb5e713c5145b4b74445a4d5e6187e567d"}

I hope it will be useful for someone except for me.

Cheers,
Gleb Peregud



More information about the erlang-questions mailing list