]> gitweb.factorcode.org Git - factor.git/blob - extra/cli/git/git.factor
bootstrap.image.upload: Upload images per-branch.
[factor.git] / extra / cli / git / git.factor
1 ! Copyright (C) 2017 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays concurrency.combinators concurrency.semaphores fry
4 io io.directories io.encodings.utf8 io.files.info io.launcher
5 io.pathnames kernel math namespaces sequences splitting
6 system-info unicode ;
7 IN: cli.git
8
9 SYMBOL: cli-git-num-parallel
10 cli-git-num-parallel [ cpus 2 * ] initialize
11
12 : git-clone-as ( ssh-url path -- process )
13     [ { "git" "clone" } ] 2dip 2array append run-process ;
14
15 : git-clone ( ssh-url -- process )
16     [ { "git" "clone" } ] dip suffix run-process ;
17
18 : git-pull ( path -- process )
19     [ { "git" "pull" } run-process ] with-directory ;
20
21 : git-repository? ( directory -- ? )
22     ".git" append-path current-directory get prepend-path
23     ?file-info dup [ directory? ] when ;
24
25 : git-current-branch ( directory -- name )
26     [
27         { "git" "rev-parse" "--abbrev-ref" "HEAD" }
28         utf8 <process-reader> stream-contents
29     ] with-directory [ blank? ] trim-tail ;
30
31 : repository-url>name ( string -- string' )
32     file-name ".git" ?tail drop ;
33
34 : update-repository ( url -- process )
35     dup repository-url>name git-repository?
36     [ repository-url>name git-pull ] [ git-clone ] if ;
37
38 : sync-repositories ( directory urls -- )
39     '[
40         _ cli-git-num-parallel get <semaphore> '[
41             _ [ update-repository ] with-semaphore
42         ] parallel-each
43     ] with-ensure-directory ;