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.directories.hierarchy
5 io.encodings.utf8 io.files io.launcher io.sockets
6 io.streams.string kernel mason.common mason.email sequences
11 { "git" "show" } utf8 [ lines ] with-process-reader
12 first " " split second ;
16 : git-clone-cmd ( -- cmd )
20 "git://factorcode.org/git/factor.git"
24 #! Must be run from builds-dir
25 "Cloning initial repository" print-timestamp
26 git-clone-cmd try-output-process ;
28 : git-pull-cmd ( -- cmd )
32 "git://factorcode.org/git/factor.git"
36 : repo-corrupted-body ( error -- string )
38 "Corrupted repository on " write host-name write " will be re-cloned." print
39 "Error while pulling was:" print
42 ] with-string-writer ;
44 : git-repo-corrupted ( error -- )
45 repo-corrupted-body "corrupted repo" email-fatal
49 : git-pull-failed ( error -- )
50 dup output-process-error? [
51 dup output>> "not uptodate. Cannot merge." swap subseq?
52 [ git-repo-corrupted ]
57 : with-process-reader* ( desc encoding quot -- )
58 [ (process-reader) ] dip swap [ with-input-stream ] dip
59 dup wait-for-process dup { 0 1 } member?
60 [ 2drop ] [ process-failed ] if ; inline
62 : git-status-cmd ( -- cmd )
65 : git-status-failed ( error -- )
66 #! Exit code 1 means there's nothing to commit.
67 dup { [ process-failed? ] [ code>> 1 = ] } 1&&
68 [ drop ] [ rethrow ] if ;
70 : git-status ( -- seq )
72 git-status-cmd utf8 [ lines ] with-process-reader*
73 [ "#\t" head? ] filter
74 ] [ git-status-failed { } ] recover ;
76 : check-repository ( -- seq )
77 "factor" [ git-status ] with-directory ;
79 : repo-dirty-body ( error -- string )
81 "Dirty repository on " write host-name write " will be re-cloned." print
82 "Modified and untracked files:" print nl
84 ] with-string-writer ;
86 : git-repo-dirty ( files -- )
87 repo-dirty-body "dirty repo" email-fatal
94 #! Must be run from builds-dir.
98 [ git-pull-cmd short-running-process ]
102 ] [ git-repo-dirty ] if-empty
104 "factor" [ git-id ] with-directory ;