1- import { Errors , branch , init , currentBranch } from '../src'
1+ import { Errors , branch , init , currentBranch , listFiles } from '../src'
22import { makeFsFixture , FsFixtureData } from './helpers/makeFsFixture'
3- import { expectToFailWithTypeAsync } from './helpers/assertionHelper'
3+ import { expectNotToFailAsync , expectToFailWithTypeAsync } from './helpers/assertionHelper'
44import * as path from './helpers/path'
55
66import branchFsFixtureData from './fixtures/fs/branch.json'
@@ -19,6 +19,89 @@ describe('branch', () => {
1919 expect ( await currentBranch ( { fs, dir } ) ) . toBe ( 'main' )
2020 } )
2121
22+ it ( 'branch force=false' , async ( ) => {
23+ // arrange
24+ const { fs, dir } = await makeFsFixture ( branchFsFixtureData as FsFixtureData )
25+
26+ // act
27+ await branch ( { fs, dir, ref : 'test-branch' } )
28+
29+ // assert
30+ expect ( await currentBranch ( { fs, dir } ) ) . toEqual ( 'main' )
31+ expect ( await fs . exists ( path . resolve ( dir , '.git' , 'refs/heads/test-branch' ) ) ) . toBeTruthy ( )
32+
33+ // act
34+ const action = async ( ) => {
35+ await branch ( { fs, dir, ref : 'test-branch' } )
36+ }
37+
38+ // assert
39+ await expectToFailWithTypeAsync ( action , Errors . AlreadyExistsError )
40+ } )
41+
42+ it ( 'branch force=false' , async ( ) => {
43+ // arrange
44+ const { fs, dir } = await makeFsFixture ( branchFsFixtureData as FsFixtureData )
45+
46+ // act
47+ await branch ( { fs, dir, ref : 'test-branch' } )
48+
49+ // assert
50+ expect ( await currentBranch ( { fs, dir } ) ) . toEqual ( 'main' )
51+ expect ( await fs . exists ( path . resolve ( dir , '.git' , 'refs/heads/test-branch' ) ) ) . toBeTruthy ( )
52+
53+ // act
54+ const action = async ( ) => {
55+ await branch ( { fs, dir, ref : 'test-branch' , force : false } )
56+ }
57+
58+ // assert
59+ await expectToFailWithTypeAsync ( action , Errors . AlreadyExistsError )
60+ } )
61+
62+ it ( 'branch force=true' , async ( ) => {
63+ // arrange
64+ const { fs, dir } = await makeFsFixture ( branchFsFixtureData as FsFixtureData )
65+
66+ // act
67+ await branch ( { fs, dir, ref : 'test-branch' } )
68+
69+ // assert
70+ expect ( await currentBranch ( { fs, dir } ) ) . toEqual ( 'main' )
71+ expect ( await fs . exists ( path . resolve ( dir , '.git' , 'refs/heads/test-branch' ) ) ) . toBeTruthy ( )
72+
73+ // act
74+ const action = async ( ) => {
75+ await branch ( { fs, dir, ref : 'test-branch' , force : true } )
76+ }
77+
78+ // assert
79+ await expectNotToFailAsync ( action )
80+ } )
81+
82+ // it('branch with start point force', async () => {
83+ // // arrange
84+ // const { fs, dir } = await makeFsFixture('test-branch-start-point')
85+
86+ // // act
87+ // await branch({ fs, dir, ref: 'test-branch', startPoint: 'start-point' })
88+
89+ // // assert
90+ // expect(await currentBranch({ fs, dir })).toEqual('main')
91+ // expect(await fs.exists(path.resolve(dir, '.git', 'refs/heads/test-branch'))).toBeTruthy()
92+
93+ // // act
94+ // const action = async () => {
95+ // await branch({ fs, dir, ref: 'test-branch', force: true })
96+ // }
97+
98+ // // assert
99+ // await expectNotToFailAsync(action)
100+ // expect(await listFiles({ fs, dir, ref: 'test-branch' })).toEqual([
101+ // 'new-file.txt',
102+ // ])
103+ // })
104+
22105 it ( 'branch --checkout' , async ( ) => {
23106 // arrange
24107 const { fs, dir } = await makeFsFixture ( branchFsFixtureData as FsFixtureData )
0 commit comments