From 8eb177bc7d6bae889dc7bd8b42c78810bcb35553 Mon Sep 17 00:00:00 2001 From: Markus Olsson Date: Wed, 13 Apr 2022 11:02:37 +0200 Subject: [PATCH 1/5] Fix BranchAlreadyExists error See https://github.com/git/git/commit/7435e7e2e7645124679eedbfb1443b8408f29219 --- lib/errors.ts | 2 +- test/fast/errors-test.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/errors.ts b/lib/errors.ts index 65dbcd96..751efd9c 100644 --- a/lib/errors.ts +++ b/lib/errors.ts @@ -104,7 +104,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, 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) + }) }) From 1a67710e3450e10d054453b61fa93eaf558dd55b Mon Sep 17 00:00:00 2001 From: Markus Olsson Date: Wed, 13 Apr 2022 11:58:37 +0200 Subject: [PATCH 2/5] Fix two more changed messages See https://github.com/git/git/commit/1a07e59c3e269418f3f5d186d166bf5ab5db6667 and https://github.com/git/git/commit/0ea306ef1701d6f42e74d3c33addfcd630248904 These are both ancient changes but we barely have any tests for errors :disappointed: --- lib/errors.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/errors.ts b/lib/errors.ts index 751efd9c..7efbb500 100644 --- a/lib/errors.ts +++ b/lib/errors.ts @@ -68,7 +68,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 +91,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.": From 6ed730faed969a1c33961b7933f93011222b62e5 Mon Sep 17 00:00:00 2001 From: Markus Olsson Date: Wed, 13 Apr 2022 12:04:34 +0200 Subject: [PATCH 3/5] Add unsafe directory error detection --- lib/errors.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/errors.ts b/lib/errors.ts index 7efbb500..38295c28 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. */ @@ -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 } /** From 10002ad7bf51ea0df69390f4c3e4e71c7d1d6461 Mon Sep 17 00:00:00 2001 From: Markus Olsson Date: Wed, 13 Apr 2022 12:27:30 +0200 Subject: [PATCH 4/5] Escape regex properly --- lib/errors.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/errors.ts b/lib/errors.ts index 38295c28..2ef0cea1 100644 --- a/lib/errors.ts +++ b/lib/errors.ts @@ -147,7 +147,7 @@ export const GitErrorRegexes: { [regexp: string]: GitError } = { '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, - "fatal: unsafe repository ('(.+)' is owned by someone else)": GitError.UnsafeDirectory + "fatal: unsafe repository \\('(.+)' is owned by someone else\\)": GitError.UnsafeDirectory } /** From 4d1251e34fb4fb5c42f57d156e8a62a533b4c9ad Mon Sep 17 00:00:00 2001 From: Markus Olsson Date: Wed, 13 Apr 2022 12:40:45 +0200 Subject: [PATCH 5/5] 1.107.0 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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",