Skip to content

Commit

Permalink
test(integration): Respect global init.defaultBranch git config
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Jan 6, 2022
1 parent 4d98715 commit 74b39f5
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions test/integration.test.js
Expand Up @@ -98,6 +98,9 @@ describe('lint-staged', () => {

const globalConsoleTemp = console

// Tests should be resilient to `git config init.defaultBranch` that is _not_ "master"
let defaultBranchName = 'UNSET'

describe('lint-staged', () => {
beforeAll(() => {
console = makeConsoleMock()
Expand All @@ -114,6 +117,10 @@ describe('lint-staged', () => {
await appendFile('README.md', '# Test\n')
await execGit(['add', 'README.md'])
await execGit(['commit', '-m initial commit'])

if (defaultBranchName === 'UNSET') {
defaultBranchName = await execGit(['rev-parse', '--abbrev-ref', 'HEAD'])
}
})

afterEach(async () => {
Expand Down Expand Up @@ -461,7 +468,7 @@ describe('lint-staged', () => {
await gitCommit(fixJsConfig, ['-m commit a'])
expect(await readFile('test.js')).toEqual(fileInBranchA)

await execGit(['checkout', 'master'])
await execGit(['checkout', defaultBranchName])

// Create another branch
await execGit(['checkout', '-b', 'branch-b'])
Expand All @@ -471,7 +478,7 @@ describe('lint-staged', () => {
expect(await readFile('test.js')).toEqual(fileInBranchBFixed)

// Merge first branch
await execGit(['checkout', 'master'])
await execGit(['checkout', defaultBranchName])
await execGit(['merge', 'branch-a'])
expect(await readFile('test.js')).toEqual(fileInBranchA)
expect(await execGit(['log', '-1', '--pretty=%B'])).toMatch('commit a')
Expand Down Expand Up @@ -522,7 +529,7 @@ describe('lint-staged', () => {
await gitCommit(fixJsConfig, ['-m commit a'])
expect(await readFile('test.js')).toEqual(fileInBranchA)

await execGit(['checkout', 'master'])
await execGit(['checkout', defaultBranchName])

// Create another branch
await execGit(['checkout', '-b', 'branch-b'])
Expand All @@ -532,7 +539,7 @@ describe('lint-staged', () => {
expect(await readFile('test.js')).toEqual(fileInBranchBFixed)

// Merge first branch
await execGit(['checkout', 'master'])
await execGit(['checkout', defaultBranchName])
await execGit(['merge', 'branch-a'])
expect(await readFile('test.js')).toEqual(fileInBranchA)
expect(await execGit(['log', '-1', '--pretty=%B'])).toMatch('commit a')
Expand Down Expand Up @@ -1083,7 +1090,7 @@ describe('lintStaged', () => {
await execGit(['add', 'test.js'], { cwd })

await expect(execGit(['log', '-1'], { cwd })).rejects.toThrowErrorMatchingInlineSnapshot(
`"fatal: your current branch 'master' does not have any commits yet"`
`"fatal: your current branch '${defaultBranchName}' does not have any commits yet"`
)

await gitCommit({
Expand Down

0 comments on commit 74b39f5

Please sign in to comment.