add-git-sha.js 427 B

123456789101112131415
  1. // add a sha to a git remote url spec
  2. const addGitSha = (spec, sha) => {
  3. if (spec.hosted) {
  4. const h = spec.hosted
  5. const opt = { noCommittish: true }
  6. const base = h.https && h.auth ? h.https(opt) : h.shortcut(opt)
  7. return `${base}#${sha}`
  8. } else {
  9. // don't use new URL for this, because it doesn't handle scp urls
  10. return spec.rawSpec.replace(/#.*$/, '') + `#${sha}`
  11. }
  12. }
  13. module.exports = addGitSha