Skip to content

Commit

Permalink
add svn support
Browse files Browse the repository at this point in the history
  • Loading branch information
joergen7 committed Apr 9, 2021
1 parent d5775f1 commit efb1189
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 20 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,21 @@ This results in an output that looks like this:

The repository information is drawn from a file `repo_info.json` which is expected in the current working directory.

The `repo_info.json` file contains a JSON object associating a base URL string with a list of repository name strings. E.g., the following JSON object is a valid repo info object:
The `repo_info.json` file contains a list of JSON objects that each contain three keys: `protocol`, `url`, and `repo_list`. The protocol can be either `git` or `svn`. The base URL and repository list identify the repositories to be managed. Herein, the base URL and repo entry are joined with a `/` separator. The following is a valid `repo_info.json` file:

[
{ "protocol" : "git",
"url" : "[email protected]:joergen7",
"repo_list" : ["bismark", "bsmooth-align", "gpull"] }
"repo_list" : ["bismark",
"bsmooth-align",
"gpull"] },
{ "protocol" : "git",
"url" : "https://github.com",
"repo_list" : ["sile/jsone",
"jcomellas/getopt"] },
{ "protocol" : "svn",
"url" : "https://svn.win.tue.nl/repos",
"repo_list" : ["cpntools/GUI/trunk"] }
]

The base URL string is prepended to each repository name to build the repository URL.
Expand Down
11 changes: 10 additions & 1 deletion priv/repo_info.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
[
{ "protocol" : "git",
"url" : "[email protected]:joergen7",
"repo_list" : ["bismark", "bsmooth-align", "gpull"] }
"repo_list" : ["bismark",
"bsmooth-align",
"gpull"] },
{ "protocol" : "git",
"url" : "https://github.com",
"repo_list" : ["sile/jsone",
"jcomellas/getopt"] },
{ "protocol" : "svn",
"url" : "https://svn.win.tue.nl/repos",
"repo_list" : ["cpntools/GUI/trunk"] }
]
66 changes: 49 additions & 17 deletions src/gpull.erl
Original file line number Diff line number Diff line change
Expand Up @@ -181,26 +181,23 @@ when is_binary( Prefix ),
is_binary( Suffix ) ->

RepoName = get_repo_name( Prefix, Suffix ),
RepoUrl = get_repo_url( Prefix, Suffix ),
RepoUrl = get_repo_url( Prefix, Suffix, <<".git">> ),

{Action, Cmd} =
case filelib:is_dir( RepoName ) of

true ->
{"git pull", "(cd "++RepoName++"; git pull)"};
{"git pull", "(cd "++RepoName++" && git pull)"};

false ->
{"git clone", "git clone "++RepoUrl++"; (cd "++RepoName++"; git config pull.rebase false)"}
{"git clone", "git clone "++RepoUrl++" && (cd "++RepoName++" && git config pull.rebase false)"}
end,

InfoMap = #{ "URL" => RepoUrl },

Reply = os:cmd( Cmd ),

ok =
print_reply( RepoName, Action, InfoMap, Reply ),

ok.
print_reply( RepoName, Action, InfoMap, Reply ).

-spec git_status( Prefix, Suffix ) -> ok
when Prefix :: binary(),
Expand All @@ -212,7 +209,7 @@ when is_binary( Prefix ),

RepoName = get_repo_name( Prefix, Suffix ),

Cmd = "(cd "++RepoName++"; git status)",
Cmd = "(cd "++RepoName++" && git status)",
Reply = os:cmd( Cmd ),
Action = "git status",

Expand All @@ -231,14 +228,43 @@ when Prefix :: binary(),
Suffix :: binary().

svn_up( Prefix, Suffix ) ->
error( nyi ).

RepoName = get_repo_name( Prefix, Suffix ),
RepoUrl = get_repo_url( Prefix, Suffix, <<>> ),

{Action, Cmd} =
case filelib:is_dir( RepoName ) of

true ->
{"svn up", "(cd "++RepoName++" && svn up)"};

false ->
{"svn co", "svn co -q "++RepoUrl++" "++RepoName}
end,

InfoMap = #{ "URL" => RepoUrl },

Reply = os:cmd( Cmd ),

print_reply( RepoName, Action, InfoMap, Reply ).


-spec svn_status( Prefix, Suffix ) -> ok
when Prefix :: binary(),
Suffix :: binary().

svn_status( Prefix, Suffix ) ->
error( nyi ).

RepoName = get_repo_name( Prefix, Suffix ),

Cmd = "(cd "++RepoName++" && svn status)",
Reply = os:cmd( Cmd ),
Action = "svn status",

case string:is_empty( Reply ) of
true -> ok;
false -> print_reply( RepoName, Action, #{}, Reply )
end.

%% Helper functions --------------------------------------------------

Expand All @@ -251,20 +277,26 @@ when is_binary( Prefix ),
is_binary( Suffix ) ->
RepoUrl = string:join( [binary_to_list( Prefix ),
binary_to_list( Suffix )], "/" ),
[$/|RepoName] = string:find( RepoUrl, "/", trailing ),
RepoName.
NoTrunk = re:replace( RepoUrl, "/trunk", "", [global] ),
TrimmedEnd = string:trim( NoTrunk, trailing, "/" ),
Found = string:find( TrimmedEnd, "/", trailing ),
TrimmedFront = string:trim( Found, leading, "/" ),
binary_to_list( TrimmedFront ).



-spec get_repo_url( Prefix, Suffix ) -> string()
-spec get_repo_url( Prefix, Suffix, Add ) -> string()
when Prefix :: binary(),
Suffix :: binary().
Suffix :: binary(),
Add :: binary().

get_repo_url( Prefix, Suffix )
get_repo_url( Prefix, Suffix, Add )
when is_binary( Prefix ),
is_binary( Suffix ) ->
is_binary( Suffix ),
is_binary( Add ) ->
RepoUrl0 = string:join( [binary_to_list( Prefix ),
binary_to_list( Suffix )], "/" ),
RepoUrl0++".git".
RepoUrl0++binary_to_list( Add ).


%% Printing ----------------------------------------------------------
Expand Down

0 comments on commit efb1189

Please sign in to comment.