Skip to content

Commit

Permalink
Adds link to install git if init fails
Browse files Browse the repository at this point in the history
  • Loading branch information
peaonunes committed May 2, 2020
1 parent e92f2c5 commit 71d38f4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/cli/src/generators/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ class AppGenerator extends Generator<AppGeneratorOptions> {
if (gitInitResult.status === 0) {
this.commitChanges()
} else {
log.error('Failed to run git init.')
log.warning('Failed to run git init.')
log.warning('Find out more about how to install git here: https://git-scm.com/downloads.')
}
}

Expand Down
20 changes: 20 additions & 0 deletions packages/cli/test/generators/app.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from 'fs-extra'
import spawn from 'cross-spawn'
import {log} from '@blitzjs/server'

import AppGenerator from '../../src/generators/app'

Expand All @@ -20,6 +21,7 @@ jest.mock(
start: jest.fn().mockImplementation(() => ({succeed: jest.fn()})),
}
}),
warning: jest.fn(),
},
}
}),
Expand Down Expand Up @@ -128,4 +130,22 @@ describe('AppGenerator', () => {
stdio: 'ignore',
})
})

describe('when git init fails', () => {
it('logs warn with instructions', async () => {
// @ts-ignore (TS complains about reassign)
spawn.sync = jest.fn().mockImplementation((command, options) => {
if (command === 'git' && options[0] === 'init') {
return {status: 1}
}
return {status: 0}
})
await generator.run()

expect(log.warning).toHaveBeenCalledWith('Failed to run git init.')
expect(log.warning).toHaveBeenCalledWith(
'Find out more about how to install git here: https://git-scm.com/downloads.',
)
})
})
})

0 comments on commit 71d38f4

Please sign in to comment.