pacote 21.3.0 → 21.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/git.js +12 -0
- package/package.json +1 -1
package/lib/git.js
CHANGED
|
@@ -25,6 +25,14 @@ const repoUrl = (h, opts) =>
|
|
|
25
25
|
// add git+ to the url, but only one time.
|
|
26
26
|
const addGitPlus = url => url && `git+${url}`.replace(/^(git\+)+/, 'git+')
|
|
27
27
|
|
|
28
|
+
const checkoutError = (expected, found) => {
|
|
29
|
+
const err = new Error(`Commit mismatch: expected SHA ${expected} and cloned HEAD ${found}`)
|
|
30
|
+
err.code = 'EGITCHECKOUT'
|
|
31
|
+
err.sha = expected
|
|
32
|
+
err.head = found
|
|
33
|
+
return err
|
|
34
|
+
}
|
|
35
|
+
|
|
28
36
|
class GitFetcher extends Fetcher {
|
|
29
37
|
constructor (spec, opts) {
|
|
30
38
|
super(spec, opts)
|
|
@@ -259,6 +267,10 @@ class GitFetcher extends Fetcher {
|
|
|
259
267
|
h ? this.#cloneHosted(ref, tmp)
|
|
260
268
|
: this.#cloneRepo(this.spec.fetchSpec, ref, tmp)
|
|
261
269
|
)
|
|
270
|
+
// if we already have a resolved sha ensure it doesn't change
|
|
271
|
+
if (this.resolvedSha && this.resolvedSha !== sha) {
|
|
272
|
+
throw checkoutError(this.resolvedSha, sha)
|
|
273
|
+
}
|
|
262
274
|
this.resolvedSha = sha
|
|
263
275
|
if (!this.resolved) {
|
|
264
276
|
await this.#addGitSha(sha)
|