diff --git a/lib/errors.ts b/lib/errors.ts index 65dbcd96..2ef0cea1 100644 --- a/lib/errors.ts +++ b/lib/errors.ts @@ -57,7 +57,8 @@ export enum GitError { TagAlreadyExists, MergeWithLocalChanges, RebaseWithLocalChanges, - MergeCommitNoMainlineOption + MergeCommitNoMainlineOption, + UnsafeDirectory } /** A mapping from regexes to the git error they identify. */ @@ -68,7 +69,7 @@ export const GitErrorRegexes: { [regexp: string]: GitError } = { 'fatal: Authentication failed': GitError.SSHAuthenticationFailed, 'fatal: Could not read from remote repository.': GitError.SSHPermissionDenied, 'The requested URL returned error: 403': GitError.HTTPSAuthenticationFailed, - 'fatal: The remote end hung up unexpectedly': GitError.RemoteDisconnection, + 'fatal: [Tt]he remote end hung up unexpectedly': GitError.RemoteDisconnection, "fatal: unable to access '(.+)': Failed to connect to (.+): Host is down": GitError.HostDown, "Cloning into '(.+)'...\nfatal: unable to access '(.+)': Could not resolve host: (.+)": GitError.HostDown, @@ -91,7 +92,7 @@ export const GitErrorRegexes: { [regexp: string]: GitError } = { "Your configuration specifies to merge with the ref '(.+)'\nfrom the remote, but no such ref was fetched.": GitError.NoExistingRemoteBranch, 'nothing to commit': GitError.NothingToCommit, - "No submodule mapping found in .gitmodules for path '(.+)'": GitError.NoSubmoduleMapping, + "[Nn]o submodule mapping found in .gitmodules for path '(.+)'": GitError.NoSubmoduleMapping, "fatal: repository '(.+)' does not exist\nfatal: clone of '.+' into submodule path '(.+)' failed": GitError.SubmoduleRepositoryDoesNotExist, "Fetched in submodule path '(.+)', but it did not contain (.+). Direct fetching of that commit failed.": @@ -104,7 +105,7 @@ export const GitErrorRegexes: { [regexp: string]: GitError } = { GitError.NonFastForwardMergeIntoEmptyHead, 'error: (.+): (patch does not apply|already exists in working directory)': GitError.PatchDoesNotApply, - "fatal: A branch named '(.+)' already exists.": GitError.BranchAlreadyExists, + "fatal: [Aa] branch named '(.+)' already exists.?": GitError.BranchAlreadyExists, "fatal: bad revision '(.*)'": GitError.BadRevision, 'fatal: [Nn]ot a git repository \\(or any of the parent directories\\): (.*)': GitError.NotAGitRepository, @@ -145,7 +146,8 @@ export const GitErrorRegexes: { [regexp: string]: GitError } = { GitError.MergeWithLocalChanges, 'error: cannot (pull with rebase|rebase): You have unstaged changes\\.\n\\s*error: [Pp]lease commit or stash them\\.': GitError.RebaseWithLocalChanges, - 'error: commit (.+) is a merge but no -m option was given': GitError.MergeCommitNoMainlineOption + 'error: commit (.+) is a merge but no -m option was given': GitError.MergeCommitNoMainlineOption, + "fatal: unsafe repository \\('(.+)' is owned by someone else\\)": GitError.UnsafeDirectory } /** diff --git a/package-lock.json b/package-lock.json index e1efa365..288e456b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "dugite", - "version": "1.106.0", + "version": "1.107.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index df05eac8..215ae130 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dugite", - "version": "1.106.0", + "version": "1.107.0", "description": "Elegant bindings for Git", "main": "./build/lib/index.js", "typings": "./build/lib/index.d.ts", diff --git a/test/fast/errors-test.ts b/test/fast/errors-test.ts index d7f0845e..a1bb920c 100644 --- a/test/fast/errors-test.ts +++ b/test/fast/errors-test.ts @@ -31,4 +31,12 @@ describe('detects errors', () => { expect(result).toHaveGitError(GitError.TagAlreadyExists) }) + it('BranchAlreadyExists', async () => { + const path = await initialize('branch-already-exists', 'foo') + await GitProcess.exec(['commit', '-m', 'initial', '--allow-empty'], path) + + const result = await GitProcess.exec(['branch', 'foo'], path) + + expect(result).toHaveGitError(GitError.BranchAlreadyExists) + }) })