-
-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add callback support to
git.firstCommit
(#960)
* Add callback support to `git.firstCommit`
- Loading branch information
Showing
5 changed files
with
24 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'simple-git': patch | ||
--- | ||
|
||
Add trailing callback support to git.firstCommit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
import { Response, SimpleGit } from '../../../typings'; | ||
import { SimpleGitApi } from '../simple-git-api'; | ||
import { trailingFunctionArgument } from '../utils'; | ||
import { straightThroughStringTask } from './task'; | ||
|
||
export default function (): Pick<SimpleGit, 'firstCommit'> { | ||
return { | ||
firstCommit(this: SimpleGitApi): Response<string> { | ||
return this._runTask({ | ||
commands: ['rev-list', '--max-parents=0', 'HEAD'], | ||
format: 'utf-8', | ||
parser(stdOut) { | ||
return String(stdOut).trim(); | ||
}, | ||
}); | ||
return this._runTask( | ||
straightThroughStringTask(['rev-list', '--max-parents=0', 'HEAD'], true), | ||
trailingFunctionArgument(arguments) | ||
); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
import { assertExecutedCommands, closeWithSuccess, newSimpleGit } from './__fixtures__'; | ||
|
||
describe('firstCommit', () => { | ||
it('gets the first commit in a repo', async () => { | ||
it('gets the first commit in a repo async', async () => { | ||
const task = newSimpleGit().firstCommit(); | ||
await closeWithSuccess('a-commit-hash\n'); | ||
|
||
expect(await task).toBe('a-commit-hash'); | ||
assertExecutedCommands('rev-list', '--max-parents=0', 'HEAD'); | ||
}); | ||
|
||
it('gets the first commit in a repo callback', async () => { | ||
const callback = jest.fn(); | ||
const task = newSimpleGit().firstCommit(callback); | ||
await closeWithSuccess('a-commit-hash\n'); | ||
|
||
expect(callback).toHaveBeenCalledWith(null, await task); | ||
assertExecutedCommands('rev-list', '--max-parents=0', 'HEAD'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters