Skip to content

Commit

Permalink
rethrow git pathspec errors when cloning from a hosted service
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Jul 2, 2021
1 parent 6ad9ede commit c76c279
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/git.js
Expand Up @@ -85,6 +85,9 @@ class GitFetcher extends Fetcher {
[_resolvedFromHosted] (hosted) {
return this[_resolvedFromRepo](hosted.https && hosted.https())
.catch(er => {
// Throw early since we know pathspec errors will fail again if retried
if (er instanceof git.errors.GitPathspecError)
throw er
const ssh = hosted.sshurl && hosted.sshurl()
// no fallthrough if we can't fall through or have https auth
if (!ssh || hosted.auth)
Expand Down Expand Up @@ -260,9 +263,11 @@ class GitFetcher extends Fetcher {
// is present, otherwise ssh if the hosted type provides it
[_cloneHosted] (ref, tmp) {
const hosted = this.spec.hosted
const https = hosted.https()
return this[_cloneRepo](hosted.https({ noCommittish: true }), ref, tmp)
.catch(er => {
// Throw early since we know pathspec errors will fail again if retried
if (er instanceof git.errors.GitPathspecError)
throw er
const ssh = hosted.sshurl && hosted.sshurl({ noCommittish: true })
// no fallthrough if we can't fall through or have https auth
if (!ssh || hosted.auth)
Expand Down
14 changes: 14 additions & 0 deletions test/git.js
Expand Up @@ -35,6 +35,7 @@ ghi.localhostssh = {
protocols: ['git+ssh:'],
tarballtemplate: () => `${hostedUrl}/repo-HEAD.tgz`,
sshurltemplate: (h) => `git://127.0.0.1:${gitPort}/${h.user}${h.committish ? `#${h.committish}` : ''}`,
httpstemplate: (h) => `git://127.0.0.1:${gitPort}/${h.user}${h.committish ? `#${h.committish}` : ''}`,
shortcuttemplate: (h) => `localhostssh:${h.user}/${h.project}${h.committish ? `#${h.committish}` : ''}`,
extract: (url) => {
const [, user, project] = url.pathname.split('/')
Expand Down Expand Up @@ -618,3 +619,16 @@ require('fs').writeFileSync('log', JSON.stringify(data,0,2))
}, 'does not continue installing once loop is detected')
}
})

t.test('missing branch name throws pathspec error', async (t) => {
const domains = ['localhostssh', 'localhosthttps', 'localhost']

for (const domain of domains) {
await t.rejects(new GitFetcher(`${domain}:repo/x#this-branch-does-not-exist`, {cache}).resolve(), {
constructor: /GitPathspecError/
}, domain)
await t.rejects(new GitFetcher(`${domain}:repo/x#this-branch-does-not-exist`, {cache}).manifest(), {
constructor: /GitPathspecError/
}, domain)
}
})

0 comments on commit c76c279

Please sign in to comment.