Skip to content

Commit e7e6f0d

Browse files
authoredJul 2, 2021
Merge pull request #84 from npm/lk/handle-pathspec-error
fix: rethrow git pathspec errors from git operations on hosted services
2 parents ac56329 + c76c279 commit e7e6f0d

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
 

‎lib/git.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class GitFetcher extends Fetcher {
8585
[_resolvedFromHosted] (hosted) {
8686
return this[_resolvedFromRepo](hosted.https && hosted.https())
8787
.catch(er => {
88+
// Throw early since we know pathspec errors will fail again if retried
89+
if (er instanceof git.errors.GitPathspecError)
90+
throw er
8891
const ssh = hosted.sshurl && hosted.sshurl()
8992
// no fallthrough if we can't fall through or have https auth
9093
if (!ssh || hosted.auth)
@@ -260,9 +263,11 @@ class GitFetcher extends Fetcher {
260263
// is present, otherwise ssh if the hosted type provides it
261264
[_cloneHosted] (ref, tmp) {
262265
const hosted = this.spec.hosted
263-
const https = hosted.https()
264266
return this[_cloneRepo](hosted.https({ noCommittish: true }), ref, tmp)
265267
.catch(er => {
268+
// Throw early since we know pathspec errors will fail again if retried
269+
if (er instanceof git.errors.GitPathspecError)
270+
throw er
266271
const ssh = hosted.sshurl && hosted.sshurl({ noCommittish: true })
267272
// no fallthrough if we can't fall through or have https auth
268273
if (!ssh || hosted.auth)

‎test/git.js

+14
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ ghi.localhostssh = {
3535
protocols: ['git+ssh:'],
3636
tarballtemplate: () => `${hostedUrl}/repo-HEAD.tgz`,
3737
sshurltemplate: (h) => `git://127.0.0.1:${gitPort}/${h.user}${h.committish ? `#${h.committish}` : ''}`,
38+
httpstemplate: (h) => `git://127.0.0.1:${gitPort}/${h.user}${h.committish ? `#${h.committish}` : ''}`,
3839
shortcuttemplate: (h) => `localhostssh:${h.user}/${h.project}${h.committish ? `#${h.committish}` : ''}`,
3940
extract: (url) => {
4041
const [, user, project] = url.pathname.split('/')
@@ -618,3 +619,16 @@ require('fs').writeFileSync('log', JSON.stringify(data,0,2))
618619
}, 'does not continue installing once loop is detected')
619620
}
620621
})
622+
623+
t.test('missing branch name throws pathspec error', async (t) => {
624+
const domains = ['localhostssh', 'localhosthttps', 'localhost']
625+
626+
for (const domain of domains) {
627+
await t.rejects(new GitFetcher(`${domain}:repo/x#this-branch-does-not-exist`, {cache}).resolve(), {
628+
constructor: /GitPathspecError/
629+
}, domain)
630+
await t.rejects(new GitFetcher(`${domain}:repo/x#this-branch-does-not-exist`, {cache}).manifest(), {
631+
constructor: /GitPathspecError/
632+
}, domain)
633+
}
634+
})

0 commit comments

Comments
 (0)
Please sign in to comment.