2013-09-18 20:01:46 +04:00
#!/usr/bin/env gjs
2013-09-19 00:34:57 +04:00
//
// Copyright (C) 2013 Colin Walters <walters@verbum.org>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
2013-09-18 20:01:46 +04:00
const Gio = imports . gi . Gio ;
const OSTree = imports . gi . OSTree ;
function assertEquals ( a , b ) {
if ( a != b )
throw new Error ( "assertion failed " + JSON . stringify ( a ) + " == " + JSON . stringify ( b ) ) ;
}
let testDataDir = Gio . File . new _for _path ( 'test-data' ) ;
testDataDir . make _directory ( null ) ;
testDataDir . get _child ( 'some-file' ) . replace _contents ( "hello world!" , null , false , 0 , null ) ;
let repoPath = Gio . File . new _for _path ( 'repo' ) ;
let repo = OSTree . Repo . new ( repoPath ) ;
repo . create ( OSTree . RepoMode . ARCHIVE _Z2 , null ) ;
repo . open ( null ) ;
assertEquals ( repo . get _mode ( ) , OSTree . RepoMode . ARCHIVE _Z2 ) ;
repo . prepare _transaction ( null ) ;
let mtree = OSTree . MutableTree . new ( ) ;
repo . write _directory _to _mtree ( testDataDir , mtree , null , null ) ;
let [ , dirTree ] = repo . write _mtree ( mtree , null ) ;
let [ , commit ] = repo . write _commit ( null , 'Some subject' , 'Some body' , null , dirTree , null ) ;
print ( "commit => " + commit ) ;
repo . commit _transaction ( null , null ) ;
let [ , root , checksum ] = repo . read _commit ( commit , null ) ;
let child = root . get _child ( 'some-file' ) ;
let info = child . query _info ( "standard::name,standard::type,standard::size" , 0 , null ) ;
assertEquals ( info . get _size ( ) , 12 ) ;
2017-05-04 22:10:57 +03:00
// Write a ref and read it back
repo . prepare _transaction ( null ) ;
repo . transaction _set _refspec ( 'someref' , commit ) ;
repo . commit _transaction ( null , null ) ;
let [ , readCommit ] = repo . resolve _rev ( 'someref' , false ) ;
assertEquals ( readCommit , commit ) ;
// Delete a ref
repo . prepare _transaction ( null ) ;
repo . transaction _set _refspec ( 'someref' , null ) ;
repo . commit _transaction ( null , null ) ;
[ , readCommit ] = repo . resolve _rev ( 'someref' , true ) ;
assertEquals ( readCommit , null ) ;
2013-09-18 20:01:46 +04:00
print ( "test-core complete" ) ;