Skip to content

Instantly share code, notes, and snippets.

@dry
Created October 9, 2013 22:32
Show Gist options
  • Save dry/6909681 to your computer and use it in GitHub Desktop.
Save dry/6909681 to your computer and use it in GitHub Desktop.
Update all git repositories in a directory
#!/usr/bin/env escript
%%! -smp enable -sname update
main([Path]) ->
SPath = string:strip(Path, right, $/),
{ok, Dirs} = file:list_dir(SPath),
[files(SPath ++ "/" ++ Dir) || Dir <- Dirs];
main(_) ->
io:format("Usage: update [path/to/directory]~n").
files(Dir) ->
{ok, Files} = file:list_dir(Dir),
update(Files, Dir).
update(Files, Dir) ->
case lists:member(".git", Files) of
true ->
io:format("Updating ~p~n", [Dir]),
ok = file:set_cwd(Dir),
os:cmd("git pull");
false ->
ok
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment