<commit_before>import { GitError } from 'dugite'

import { Repository } from '../../../src/models/repository'
import { git } from '../../../src/lib/git'
import { setupFixtureRepository } from '../../helpers/repositories'

describe('git/core', () => {
  let repository: Repository

  beforeEach(async () => {
    const testRepoPath = await setupFixtureRepository('test-repo')
    repository = new Repository(testRepoPath, -1, null, false)
  })

  describe('error handling', () => {
    it('does not throw for errors that were expected', async () => {
      const args = ['rev-list', '--left-right', '--count', 'some-ref', '--']

      let threw = false
      try {
        const result = await git(args, repository.path, 'test', {
          expectedErrors: new Set([GitError.BadRevision]),
        })
        expect(result.gitError).toBe(GitError.BadRevision)
      } catch (e) {
        threw = true
      }

      expect(threw).toBe(false)
    })

    it('throws for errors that were not expected', async () => {
      const args = ['rev-list', '--left-right', '--count', 'some-ref', '--']

      let threw = false
      try {
        await git(args, repository.path, 'test', {
          expectedErrors: new Set([GitError.SSHKeyAuditUnverified]),
        })
      } catch (e) {
        threw = true
      }

      expect(threw).toBe(true)
    })
  })

  describe('exit code handling', () => {
    it('does not throw for exit codes that were expected', async () => {
      const args = ['rev-list', '--left-right', '--count', 'some-ref', '--']

      let threw = false
      try {
        const result = await git(args, repository.path, 'test', {
          successExitCodes: new Set([128]),
        })
        expect(result.exitCode).toBe(128)
      } catch (e) {
        threw = true
      }

      expect(threw).toBe(false)
    })

    it('throws for exit codes that were not expected', async () => {
      const args = ['rev-list', '--left-right', '--count', 'some-ref', '--']

      let threw = false
      try {
        await git(args, repository.path, 'test', {
          successExitCodes: new Set([2]),
        })
      } catch (e) {
        threw = true
      }

      expect(threw).toBe(true)
    })
  })
})<commit_msg>Add some tests<commit_after>import { GitError } from 'dugite'

import { Repository } from '../../../src/models/repository'
import { git, parseConfigLockFilePathFromError } from '../../../src/lib/git'
import { setupFixtureRepository } from '../../helpers/repositories'

describe('git/core', () => {
  let repository: Repository

  beforeEach(async () => {
    const testRepoPath = await setupFixtureRepository('test-repo')
    repository = new Repository(testRepoPath, -1, null, false)
  })

  describe('error handling', () => {
    it('does not throw for errors that were expected', async () => {
      const args = ['rev-list', '--left-right', '--count', 'some-ref', '--']

      let threw = false
      try {
        const result = await git(args, repository.path, 'test', {
          expectedErrors: new Set([GitError.BadRevision]),
        })
        expect(result.gitError).toBe(GitError.BadRevision)
      } catch (e) {
        threw = true
      }

      expect(threw).toBe(false)
    })

    it('throws for errors that were not expected', async () => {
      const args = ['rev-list', '--left-right', '--count', 'some-ref', '--']

      let threw = false
      try {
        await git(args, repository.path, 'test', {
          expectedErrors: new Set([GitError.SSHKeyAuditUnverified]),
        })
      } catch (e) {
        threw = true
      }

      expect(threw).toBe(true)
    })
  })

  describe('exit code handling', () => {
    it('does not throw for exit codes that were expected', async () => {
      const args = ['rev-list', '--left-right', '--count', 'some-ref', '--']

      let threw = false
      try {
        const result = await git(args, repository.path, 'test', {
          successExitCodes: new Set([128]),
        })
        expect(result.exitCode).toBe(128)
      } catch (e) {
        threw = true
      }

      expect(threw).toBe(false)
    })

    it('throws for exit codes that were not expected', async () => {
      const args = ['rev-list', '--left-right', '--count', 'some-ref', '--']

      let threw = false
      try {
        await git(args, repository.path, 'test', {
          successExitCodes: new Set([2]),
        })
      } catch (e) {
        threw = true
      }

      expect(threw).toBe(true)
    })

    it('', () => {
      if (__WIN32__) {
        expect(
          parseConfigLockFilePathFromError(
            'error: could not lock config file C:/Users/markus/.gitconfig: File exists'
          )
        ).toBe('c:\\Users\\markus\\.gitconfig.lock')

        expect(
          parseConfigLockFilePathFromError(
            'error: could not lock config file C:\\Users\\markus\\.gitconfig: File exists'
          )
        ).toBe('c:\\Users\\markus\\.gitconfig.lock')
      } else {
        expect(
          parseConfigLockFilePathFromError(
            'error: could not lock config file /Users/markus/.gitconfig: File exists'
          )
        ).toBe('/Users/markus/.gitconfig.lock')
      }
    })
  })
})
{'fraction_non_alphanumeric': 0.16673076923076924, 'fraction_numerical': 0.0034615384615384616, 'mean_word_length': 2.133132530120482, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5370611', 'n_tokens_mistral': 1586, 'n_tokens_neox': 1560, 'n_words': 375}