-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost-push.escript
executable file
·30 lines (26 loc) · 1.27 KB
/
post-push.escript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env escript
%%==============================================================================
%% MAIN
%%==============================================================================
main(_) ->
%% This is required to invoke git module
add_lib_code_paths(),
LoadedData = git:load_data([exit]),
io:format("Load data from node successfully: ~p~n", [LoadedData]).
%%==============================================================================
%% Internal functions
%%==============================================================================
%%------------------------------------------------------------------------------
%% This script may be symlinked, then escript:script_name() returns path to the
%% symlink. Get regular file path and dir of the script, then add dir of git lib
%% module to code paths.
%%------------------------------------------------------------------------------
add_lib_code_paths() ->
ExePath = escript:script_name(),
GetPathCmd = "readlink -f " ++ ExePath,
ScriptPath = string:trim(os:cmd(GetPathCmd)),
ScriptDir = filename:dirname(ScriptPath),
GitLibPath = "libs/erlang/git/_build/default/lib/git/ebin",
GitLibFullPath = filename:join(ScriptDir, GitLibPath),
true = code:add_patha(GitLibFullPath),
git:load().