@@ -4724,10 +4724,11 @@ describe('DataSource', () => {
47244724 mockGitSuccessOnce ( ) ;
47254725
47264726 // Run
4727- const result = await dataSource . createBranch ( '/path/to/repo' , 'develop' , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' , false ) ;
4727+ const result = await dataSource . createBranch ( '/path/to/repo' , 'develop' , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' , false , false ) ;
47284728
47294729 // Assert
4730- expect ( result ) . toBe ( null ) ;
4730+ expect ( result ) . toStrictEqual ( [ null ] ) ;
4731+ expect ( spyOnSpawn ) . toBeCalledTimes ( 1 ) ;
47314732 expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'branch' , 'develop' , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
47324733 } ) ;
47334734
@@ -4736,22 +4737,79 @@ describe('DataSource', () => {
47364737 mockGitSuccessOnce ( ) ;
47374738
47384739 // Run
4739- const result = await dataSource . createBranch ( '/path/to/repo' , 'develop' , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' , true ) ;
4740+ const result = await dataSource . createBranch ( '/path/to/repo' , 'develop' , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' , true , false ) ;
47404741
47414742 // Assert
4742- expect ( result ) . toBe ( null ) ;
4743+ expect ( result ) . toStrictEqual ( [ null ] ) ;
4744+ expect ( spyOnSpawn ) . toBeCalledTimes ( 1 ) ;
47434745 expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'checkout' , '-b' , 'develop' , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
47444746 } ) ;
47454747
4748+ it ( 'Should force create a branch at a commit' , async ( ) => {
4749+ // Setup
4750+ mockGitSuccessOnce ( ) ;
4751+
4752+ // Run
4753+ const result = await dataSource . createBranch ( '/path/to/repo' , 'develop' , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' , false , true ) ;
4754+
4755+ // Assert
4756+ expect ( result ) . toStrictEqual ( [ null ] ) ;
4757+ expect ( spyOnSpawn ) . toBeCalledTimes ( 1 ) ;
4758+ expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'branch' , '-f' , 'develop' , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
4759+ } ) ;
4760+
4761+ it ( 'Should force create a branch at a commit, and check it out' , async ( ) => {
4762+ // Setup
4763+ mockGitSuccessOnce ( ) ;
4764+ mockGitSuccessOnce ( ) ;
4765+
4766+ // Run
4767+ const result = await dataSource . createBranch ( '/path/to/repo' , 'develop' , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' , true , true ) ;
4768+
4769+ // Assert
4770+ expect ( result ) . toStrictEqual ( [ null , null ] ) ;
4771+ expect ( spyOnSpawn ) . toBeCalledTimes ( 2 ) ;
4772+ expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'branch' , '-f' , 'develop' , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
4773+ expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'checkout' , 'develop' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
4774+ } ) ;
4775+
47464776 it ( 'Should return an error message thrown by git' , async ( ) => {
47474777 // Setup
47484778 mockGitThrowingErrorOnce ( ) ;
47494779
47504780 // Run
4751- const result = await dataSource . createBranch ( '/path/to/repo' , 'develop' , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' , false ) ;
4781+ const result = await dataSource . createBranch ( '/path/to/repo' , 'develop' , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' , false , false ) ;
47524782
47534783 // Assert
4754- expect ( result ) . toBe ( 'error message' ) ;
4784+ expect ( result ) . toStrictEqual ( [ 'error message' ] ) ;
4785+ } ) ;
4786+
4787+ it ( 'Should return an error message thrown by git when creating a branch, and not proceed to check out the force-created branch' , async ( ) => {
4788+ // Setup
4789+ mockGitThrowingErrorOnce ( ) ;
4790+
4791+ // Run
4792+ const result = await dataSource . createBranch ( '/path/to/repo' , 'develop' , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' , true , true ) ;
4793+
4794+ // Assert
4795+ expect ( result ) . toStrictEqual ( [ 'error message' ] ) ;
4796+ expect ( spyOnSpawn ) . toBeCalledTimes ( 1 ) ;
4797+ expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'branch' , '-f' , 'develop' , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
4798+ } ) ;
4799+
4800+ it ( 'Should return an error message thrown by git when checking out a force-created branch' , async ( ) => {
4801+ // Setup
4802+ mockGitSuccessOnce ( ) ;
4803+ mockGitThrowingErrorOnce ( ) ;
4804+
4805+ // Run
4806+ const result = await dataSource . createBranch ( '/path/to/repo' , 'develop' , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' , true , true ) ;
4807+
4808+ // Assert
4809+ expect ( result ) . toStrictEqual ( [ null , 'error message' ] ) ;
4810+ expect ( spyOnSpawn ) . toBeCalledTimes ( 2 ) ;
4811+ expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'branch' , '-f' , 'develop' , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
4812+ expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'checkout' , 'develop' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
47554813 } ) ;
47564814 } ) ;
47574815
0 commit comments