parse empty commits

This commit is contained in:
Peter Evans 2024-08-23 09:14:25 +00:00
parent a3546365cd
commit 42beb85339
5 changed files with 91 additions and 46 deletions

View file

@ -22,6 +22,7 @@ git config --global user.name "Your Name"
echo "#test-base" > README.md
git add .
git commit -m "initial commit"
git commit --allow-empty -m "empty commit for tests"
echo "#test-base :sparkles:" > README.md
git add .
git commit -m "add sparkles" -m "Change description:

View file

@ -11,17 +11,26 @@ describe('git-command-manager integration tests', () => {
})
it('tests getCommit', async () => {
const parent = await git.getCommit('HEAD^')
const commit = await git.getCommit('HEAD')
expect(parent.subject).toEqual('initial commit')
expect(parent.signed).toBeFalsy()
expect(parent.changes).toEqual([
const initialCommit = await git.getCommit('HEAD^^')
const emptyCommit = await git.getCommit('HEAD^')
const headCommit = await git.getCommit('HEAD')
expect(initialCommit.subject).toEqual('initial commit')
expect(initialCommit.signed).toBeFalsy()
expect(initialCommit.changes).toEqual([
{mode: '100644', status: 'A', path: 'README.md'}
])
expect(commit.subject).toEqual('add sparkles')
expect(commit.parents[0]).toEqual(parent.sha)
expect(commit.signed).toBeFalsy()
expect(commit.changes).toEqual([
expect(emptyCommit.subject).toEqual('empty commit for tests')
expect(emptyCommit.tree).toEqual(initialCommit.tree) // empty commits have no tree and reference the parent's
expect(emptyCommit.parents[0]).toEqual(initialCommit.sha)
expect(emptyCommit.signed).toBeFalsy()
expect(emptyCommit.changes).toEqual([])
expect(headCommit.subject).toEqual('add sparkles')
expect(headCommit.parents[0]).toEqual(emptyCommit.sha)
expect(headCommit.signed).toBeFalsy()
expect(headCommit.changes).toEqual([
{mode: '100644', status: 'M', path: 'README.md'}
])
})