@@ -5,13 +5,13 @@ import { Repository } from "./repository.js";
55import {
66 addOneStep ,
77 addOneStep as addOneNested ,
8- ComplexObject ,
8+ type ComplexObject ,
99 getBaseline ,
1010 sumChanges ,
1111 testAuthor ,
1212 updateHeaderData ,
1313} from "./test.utils.js" ;
14- import { Reference } from "./interfaces.js" ;
14+ import type { Reference } from "./interfaces.js" ;
1515import { compare } from "fast-json-patch" ;
1616import { objectToTree , treeToObject } from "./serialize.js" ;
1717
@@ -60,6 +60,13 @@ test("restore", async (t) => {
6060 "main is pointing at wrong commit" ,
6161 ) ;
6262 t . equal ( history . commits . length , 2 , "incorrect # of commits" ) ;
63+ const logs = repo . logs ( )
64+ t . equal ( logs . length , 3 , "incorrect # of logs" )
65+ const logs1 = repo . logs ( 1 )
66+ t . equal ( logs1 . length , 1 , "incorrect # of logs retrieved" )
67+
68+ const logs2 = repo . logs ( 100 )
69+ t . equal ( logs2 . length , 3 , "incorrect # of logs retrieved" )
6370
6471 // start reconstruction
6572 const p = { } ;
@@ -280,7 +287,7 @@ test("history", async (t) => {
280287} ) ;
281288
282289test ( "reset" , async ( t ) => {
283- t . test ( "reset hard " , async ( t ) => {
290+ t . test ( "discard uncommitted changes " , async ( t ) => {
284291 const [ repo , co ] = await getBaseline ( ) ;
285292 co . uuid = "asdf" ;
286293 const hash = await repo . commit ( "baseline" , testAuthor ) ;
@@ -292,10 +299,60 @@ test("reset", async (t) => {
292299 t . equal ( diff . length , changes , "wrong # of changes in diff" ) ;
293300
294301 // reset
295- repo . reset ( "hard" ) ;
302+ await repo . reset ( "hard" ) ;
296303 const diff2 = await repo . diff ( hash ) ;
297304 t . equal ( diff2 . length , 0 , "failed to reset" ) ;
298305 } ) ;
306+
307+ t . test ( "reset to earlier commit" , async t => {
308+ const [ repo , co ] = await getBaseline ( ) ;
309+ co . uuid = "asdf" ;
310+ const hash = await repo . commit ( "baseline" , testAuthor ) ;
311+ const h1 = repo . getHistory ( ) ;
312+ t . equal ( h1 . commits . length , 1 ) ;
313+
314+ // do changes
315+ const changes = updateHeaderData ( co ) ;
316+ const hash2 = await repo . commit ( "header data" , testAuthor ) ;
317+ const h2 = repo . getHistory ( ) ;
318+ t . equal ( h2 . commits . length , 2 ) ;
319+ const diff = await repo . diff ( hash ) ;
320+ t . equal ( diff . length , changes , "wrong # of changes in diff" ) ;
321+ t . equal ( hash !== hash2 , true , "hash should not be the same" ) ;
322+
323+ // reset
324+ await repo . reset ( "hard" , hash ) ;
325+ const diff2 = await repo . diff ( hash ) ;
326+ t . equal ( diff2 . length , 0 , "failed to reset" ) ;
327+ const h3 = repo . getHistory ( )
328+ t . equal ( h3 . refs . get ( "refs/heads/main" ) ! . value , hash , "main should point to first hash" ) ;
329+ } )
330+
331+ t . test ( "reset to earlier version tag" , async t => {
332+ const [ repo , co ] = await getBaseline ( ) ;
333+ co . uuid = "asdf" ;
334+ const hash = await repo . commit ( "baseline" , testAuthor ) ;
335+ repo . tag ( "v0.1.0" )
336+ const h1 = repo . getHistory ( ) ;
337+ t . equal ( h1 . commits . length , 1 ) ;
338+
339+ // do changes
340+ const changes = updateHeaderData ( co ) ;
341+ const hash2 = await repo . commit ( "header data" , testAuthor ) ;
342+ repo . tag ( "v0.2.0" )
343+ const h2 = repo . getHistory ( ) ;
344+ t . equal ( h2 . commits . length , 2 ) ;
345+ const diff = await repo . diff ( hash ) ;
346+ t . equal ( diff . length , changes , "wrong # of changes in diff" ) ;
347+ t . equal ( hash !== hash2 , true , "hash should not be the same" ) ;
348+
349+ // reset
350+ await repo . reset ( "hard" , "v0.1.0" ) ;
351+ const diff2 = await repo . diff ( hash ) ;
352+ t . equal ( diff2 . length , 0 , "failed to reset" ) ;
353+ const h3 = repo . getHistory ( )
354+ t . equal ( h3 . refs . get ( "refs/heads/main" ) ! . value , hash , "main should point to first hash" ) ;
355+ } )
299356} ) ;
300357
301358test ( "status" , async ( t ) => {
0 commit comments