pacote 21.2.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.
Files changed (2) hide show
  1. package/lib/git.js +13 -1
  2. package/package.json +1 -1
package/lib/git.js CHANGED
@@ -12,7 +12,7 @@ const _ = require('./util/protected.js')
12
12
  const addGitSha = require('./util/add-git-sha.js')
13
13
  const npm = require('./util/npm.js')
14
14
 
15
- const hashre = /^[a-f0-9]{40}$/
15
+ const hashre = /^[a-f0-9]{40,64}$/
16
16
 
17
17
  // get the repository url.
18
18
  // prefer https if there's auth, since ssh will drop that.
@@ -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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacote",
3
- "version": "21.2.0",
3
+ "version": "21.3.1",
4
4
  "description": "JavaScript package downloader",
5
5
  "author": "GitHub Inc.",
6
6
  "bin": {