@@ -4,6 +4,7 @@ import { expectNotToFailAsync, expectToFailWithTypeAsync } from './helpers/asser
44import * as path from './helpers/path'
55
66import branchFsFixtureData from './fixtures/fs/branch.json'
7+ import branchStartPointFsFixtureData from './fixtures/fs/branch-start-point.json'
78
89describe ( 'branch' , ( ) => {
910 it ( 'branch' , async ( ) => {
@@ -19,7 +20,28 @@ describe('branch', () => {
1920 expect ( await currentBranch ( { fs, dir } ) ) . toBe ( 'main' )
2021 } )
2122
22- it ( 'branch force=false' , async ( ) => {
23+ it ( 'branch with start point' , async ( ) => {
24+ // arrange
25+ const { fs, dir } = await makeFsFixture ( branchStartPointFsFixtureData as FsFixtureData )
26+ let files = await fs . readdir ( path . resolve ( dir , '.git' , 'refs' , 'heads' ) )
27+
28+ // assert
29+ expect ( files ) . toEqual ( [ 'main' , 'start-point' ] )
30+
31+ // act
32+ await branch ( { fs, dir, ref : 'test-branch' , startPoint : 'start-point' } )
33+
34+ // assert
35+ files = await fs . readdir ( path . resolve ( dir , '.git' , 'refs' , 'heads' ) )
36+ expect ( files ) . toEqual ( [ 'main' , 'start-point' , 'test-branch' ] )
37+ expect ( await currentBranch ( { fs, dir } ) ) . toEqual ( 'main' )
38+ expect ( await fs . readFile ( path . resolve ( dir , '.git' , 'refs' , 'heads' , 'test-branch' ) , { encoding : 'utf8' } )
39+ ) . toEqual ( await fs . readFile ( path . resolve ( dir , '.git' , 'refs' , 'heads' , 'start-point' ) , { encoding : 'utf8' } ) )
40+ expect ( await listFiles ( { fs, dir, ref : 'HEAD' } ) ) . toEqual ( [ 'new-file.txt' ] )
41+ expect ( await listFiles ( { fs, dir, ref : 'test-branch' } ) ) . toEqual ( [ ] )
42+ } )
43+
44+ it ( 'branch force=undefined' , async ( ) => {
2345 // arrange
2446 const { fs, dir } = await makeFsFixture ( branchFsFixtureData as FsFixtureData )
2547
@@ -79,28 +101,28 @@ describe('branch', () => {
79101 await expectNotToFailAsync ( action )
80102 } )
81103
82- // it('branch with start point force', async () => {
83- // // arrange
84- // const { fs, dir } = await makeFsFixture('test-branch-start-point' )
104+ it ( 'branch with start point force' , async ( ) => {
105+ // arrange
106+ const { fs, dir } = await makeFsFixture ( branchStartPointFsFixtureData as FsFixtureData )
85107
86- // // act
87- // await branch({ fs, dir, ref: 'test-branch', startPoint: 'start-point' })
108+ // act
109+ await branch ( { fs, dir, ref : 'test-branch' , startPoint : 'start-point' } )
88110
89- // // assert
90- // expect(await currentBranch({ fs, dir })).toEqual('main')
91- // expect(await fs.exists(path.resolve(dir, '.git', 'refs/heads/test-branch'))).toBeTruthy()
111+ // assert
112+ expect ( await currentBranch ( { fs, dir } ) ) . toEqual ( 'main' )
113+ expect ( await fs . exists ( path . resolve ( dir , '.git' , 'refs/heads/test-branch' ) ) ) . toBeTruthy ( )
92114
93- // // act
94- // const action = async () => {
95- // await branch({ fs, dir, ref: 'test-branch', force: true })
96- // }
115+ // act
116+ const action = async ( ) => {
117+ await branch ( { fs, dir, ref : 'test-branch' , force : true } )
118+ }
97119
98- // // assert
99- // await expectNotToFailAsync(action)
100- // expect(await listFiles({ fs, dir, ref: 'test-branch' })).toEqual([
101- // 'new-file.txt',
102- // ])
103- // })
120+ // assert
121+ await expectNotToFailAsync ( action )
122+ expect ( await listFiles ( { fs, dir, ref : 'test-branch' } ) ) . toEqual ( [
123+ 'new-file.txt' ,
124+ ] )
125+ } )
104126
105127 it ( 'branch --checkout' , async ( ) => {
106128 // arrange
0 commit comments