! Copyright (C) 2015 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: fry git io io.directories io.encodings.utf8 io.files.temp
-io.files.unique io.launcher kernel sequences tools.test ;
+USING: accessors fry git io io.directories io.encodings.utf8
+io.launcher io.streams.string kernel sequences tools.test ;
IN: git.tests
: run-process-stdout ( process -- string )
@
] with-empty-test-git-repo ; inline
+{ "hello" } [
+ commit new "author" "hello\r\n"
+ [ parse-commit-field ] with-string-reader
+ author>>
+] unit-test
+
{ "refs/heads/master" } [
[ git-head-ref ] with-empty-test-git-repo
] unit-test
ERROR: unknown-commit-line line name ;
-ERROR: string-expected got expected ;
-
-: expect-string ( string expected -- )
- 2dup = [ 2drop ] [ string-expected ] if ;
-
ERROR: eof-too-early ;
ERROR: unknown-field field ;
} case ;
: parse-commit ( bytes -- commit )
- " " split1 [ "commit" expect-string ] [ string>number read ] bi*
+ " " split1 [ "commit" assert= ] [ string>number read ] bi*
utf8 [
commit new parse-commit-lines
] with-byte-reader ;
-
-
: parse-tree-field ( obj parameter -- obj )
[ "\r\n" read-until* ] dip {
{ "tree" [ >>tree ] }
H{ } clone parents [
git-head-object [
parents>> dup string? [ random ] unless [
- ! [ parents get 2dup key? [ repeated-parent-hash ] when dupd set-at ] keep
- ! dup "parent: " prepend print flush yield
dup git-unpacked-object-exists?
[ git-read-object ] [ git-object-from-pack ] if
] [ f ] if*