1 ! Copyright (C) 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors combinators.short-circuit continuations
4 debugger io io.directories io.encodings.utf8 io.files
5 io.launcher io.sockets io.streams.string kernel mason.common
6 mason.email sequences splitting ;
10 { "git" "show" } utf8 [ lines ] with-process-reader
11 first " " split second ;
15 : git-clone-cmd ( -- cmd )
19 "git://factorcode.org/git/factor.git"
23 #! Must be run from builds-dir
24 git-clone-cmd try-output-process ;
26 : git-pull-cmd ( -- cmd )
30 "git://factorcode.org/git/factor.git"
34 : repo-corrupted-body ( error -- string )
36 "Corrupted repository on " write host-name write " will be re-cloned." print
37 "Error while pulling was:" print
40 ] with-string-writer ;
42 : git-repo-corrupted ( error -- )
43 repo-corrupted-body "corrupted repo" email-fatal
44 "factor" really-delete-tree
47 : git-pull-failed ( error -- )
48 dup output-process-error? [
49 dup output>> "not uptodate. Cannot merge." swap start
50 [ git-repo-corrupted ]
55 : with-process-reader* ( desc encoding quot -- )
56 [ <process-reader*> ] dip swap [ with-input-stream ] dip
57 dup wait-for-process dup { 0 1 } member?
58 [ 2drop ] [ process-failed ] if ; inline
60 : git-status-cmd ( -- cmd )
63 : git-status-failed ( error -- )
64 #! Exit code 1 means there's nothing to commit.
65 dup { [ process-failed? ] [ code>> 1 = ] } 1&&
66 [ drop ] [ rethrow ] if ;
68 : git-status ( -- seq )
70 git-status-cmd utf8 [ lines ] with-process-reader*
71 [ "#\t" head? ] filter
72 ] [ git-status-failed { } ] recover ;
74 : check-repository ( -- seq )
75 "factor" [ git-status ] with-directory ;
77 : repo-dirty-body ( error -- string )
79 "Dirty repository on " write host-name write " will be re-cloned." print
80 "Modified and untracked files:" print nl
82 ] with-string-writer ;
84 : git-repo-dirty ( files -- )
85 repo-dirty-body "dirty repo" email-fatal
86 "factor" really-delete-tree
92 #! Must be run from builds-dir.
96 [ git-pull-cmd short-running-process ]
100 ] [ git-repo-dirty ] if-empty
102 "factor" [ git-id ] with-directory ;