Skip to content

Commit

Permalink
feat!: set default git ref to HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
darcyclarke committed May 7, 2022
1 parent e50cadb commit 69e586d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ provided to a method override those provided to the constructor.

Given the path of a file relative to the repository, returns a URL for
directly fetching it from the githost. If no committish was set then
`master` will be used as the default.
`HEAD` will be used as the default.

For example `hostedGitInfo.fromUrl("git@github.com:npm/hosted-git-info.git#v1.0.0").file("package.json")`
would return `https://raw.githubusercontent.com/npm/hosted-git-info/v1.0.0/package.json`
Expand Down
14 changes: 7 additions & 7 deletions lib/git-host-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const defaults = {
sshtemplate: ({ domain, user, project, committish }) => `git@${domain}:${user}/${project}.git${maybeJoin('#', committish)}`,
sshurltemplate: ({ domain, user, project, committish }) => `git+ssh://git@${domain}/${user}/${project}.git${maybeJoin('#', committish)}`,
browsetemplate: ({ domain, user, project, committish, treepath }) => `https://${domain}/${user}/${project}${maybeJoin('/', treepath, '/', maybeEncode(committish))}`,
browsefiletemplate: ({ domain, user, project, committish, treepath, path, fragment, hashformat }) => `https://${domain}/${user}/${project}/${treepath}/${maybeEncode(committish || 'master')}/${path}${maybeJoin('#', hashformat(fragment || ''))}`,
browsefiletemplate: ({ domain, user, project, committish, treepath, path, fragment, hashformat }) => `https://${domain}/${user}/${project}/${treepath}/${maybeEncode(committish || 'HEAD')}/${path}${maybeJoin('#', hashformat(fragment || ''))}`,
docstemplate: ({ domain, user, project, treepath, committish }) => `https://${domain}/${user}/${project}${maybeJoin('/', treepath, '/', maybeEncode(committish))}#readme`,
httpstemplate: ({ auth, domain, user, project, committish }) => `git+https://${maybeJoin(auth, '@')}${domain}/${user}/${project}.git${maybeJoin('#', committish)}`,
filetemplate: ({ domain, user, project, committish, path }) => `https://${domain}/${user}/${project}/raw/${maybeEncode(committish) || 'master'}/${path}`,
filetemplate: ({ domain, user, project, committish, path }) => `https://${domain}/${user}/${project}/raw/${maybeEncode(committish) || 'HEAD'}/${path}`,
shortcuttemplate: ({ type, user, project, committish }) => `${type}:${user}/${project}${maybeJoin('#', committish)}`,
pathtemplate: ({ user, project, committish }) => `${user}/${project}${maybeJoin('#', committish)}`,
bugstemplate: ({ domain, user, project }) => `https://${domain}/${user}/${project}/issues`,
Expand All @@ -24,9 +24,9 @@ gitHosts.github = Object.assign({}, defaults, {
protocols: ['git:', 'http:', 'git+ssh:', 'git+https:', 'ssh:', 'https:'],
domain: 'github.com',
treepath: 'tree',
filetemplate: ({ auth, user, project, committish, path }) => `https://${maybeJoin(auth, '@')}raw.githubusercontent.com/${user}/${project}/${maybeEncode(committish) || 'master'}/${path}`,
filetemplate: ({ auth, user, project, committish, path }) => `https://${maybeJoin(auth, '@')}raw.githubusercontent.com/${user}/${project}/${maybeEncode(committish) || 'HEAD'}/${path}`,
gittemplate: ({ auth, domain, user, project, committish }) => `git://${maybeJoin(auth, '@')}${domain}/${user}/${project}.git${maybeJoin('#', committish)}`,
tarballtemplate: ({ domain, user, project, committish }) => `https://codeload.${domain}/${user}/${project}/tar.gz/${maybeEncode(committish) || 'master'}`,
tarballtemplate: ({ domain, user, project, committish }) => `https://codeload.${domain}/${user}/${project}/tar.gz/${maybeEncode(committish) || 'HEAD'}`,
extract: (url) => {
let [, user, project, type, committish] = url.pathname.split('/', 5)
if (type && type !== 'tree') {
Expand All @@ -53,7 +53,7 @@ gitHosts.bitbucket = Object.assign({}, defaults, {
protocols: ['git+ssh:', 'git+https:', 'ssh:', 'https:'],
domain: 'bitbucket.org',
treepath: 'src',
tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}/get/${maybeEncode(committish) || 'master'}.tar.gz`,
tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}/get/${maybeEncode(committish) || 'HEAD'}.tar.gz`,
extract: (url) => {
let [, user, project, aux] = url.pathname.split('/', 4)
if (['get'].includes(aux)) {
Expand All @@ -77,7 +77,7 @@ gitHosts.gitlab = Object.assign({}, defaults, {
domain: 'gitlab.com',
treepath: 'tree',
httpstemplate: ({ auth, domain, user, project, committish }) => `git+https://${maybeJoin(auth, '@')}${domain}/${user}/${project}.git${maybeJoin('#', committish)}`,
tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}/repository/archive.tar.gz?ref=${maybeEncode(committish) || 'master'}`,
tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}/repository/archive.tar.gz?ref=${maybeEncode(committish) || 'HEAD'}`,
extract: (url) => {
const path = url.pathname.slice(1)
if (path.includes('/-/') || path.includes('/archive.tar.gz')) {
Expand Down Expand Up @@ -113,7 +113,7 @@ gitHosts.gist = Object.assign({}, defaults, {
pathtemplate: ({ project, committish }) => `${project}${maybeJoin('#', committish)}`,
bugstemplate: ({ domain, project }) => `https://${domain}/${project}`,
gittemplate: ({ domain, project, committish }) => `git://${domain}/${project}.git${maybeJoin('#', committish)}`,
tarballtemplate: ({ project, committish }) => `https://codeload.github.com/gist/${project}/tar.gz/${maybeEncode(committish) || 'master'}`,
tarballtemplate: ({ project, committish }) => `https://codeload.github.com/gist/${project}/tar.gz/${maybeEncode(committish) || 'HEAD'}`,
extract: (url) => {
let [, user, project, aux] = url.pathname.split('/', 4)
if (aux === 'raw') {
Expand Down
10 changes: 5 additions & 5 deletions test/bitbucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ t.test('string methods populate correctly', t => {
t.equal(parsed.ssh(), 'git@bitbucket.org:foo/bar.git')
t.equal(parsed.sshurl(), 'git+ssh://git@bitbucket.org/foo/bar.git')
t.equal(parsed.browse(), 'https://bitbucket.org/foo/bar')
t.equal(parsed.browse('/lib/index.js'), 'https://bitbucket.org/foo/bar/src/master/lib/index.js')
t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://bitbucket.org/foo/bar/src/master/lib/index.js#l100')
t.equal(parsed.browse('/lib/index.js'), 'https://bitbucket.org/foo/bar/src/HEAD/lib/index.js')
t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://bitbucket.org/foo/bar/src/HEAD/lib/index.js#l100')
t.equal(parsed.docs(), 'https://bitbucket.org/foo/bar#readme')
t.equal(parsed.https(), 'git+https://bitbucket.org/foo/bar.git')
t.equal(parsed.shortcut(), 'bitbucket:foo/bar')
t.equal(parsed.path(), 'foo/bar')
t.equal(parsed.tarball(), 'https://bitbucket.org/foo/bar/get/master.tar.gz')
t.equal(parsed.file(), 'https://bitbucket.org/foo/bar/raw/master/')
t.equal(parsed.file('/lib/index.js'), 'https://bitbucket.org/foo/bar/raw/master/lib/index.js')
t.equal(parsed.tarball(), 'https://bitbucket.org/foo/bar/get/HEAD.tar.gz')
t.equal(parsed.file(), 'https://bitbucket.org/foo/bar/raw/HEAD/')
t.equal(parsed.file('/lib/index.js'), 'https://bitbucket.org/foo/bar/raw/HEAD/lib/index.js')
t.equal(parsed.bugs(), 'https://bitbucket.org/foo/bar/issues')

t.equal(parsed.docs({ committish: 'fix/bug' }), 'https://bitbucket.org/foo/bar/src/fix%2Fbug#readme', 'allows overriding options')
Expand Down
2 changes: 1 addition & 1 deletion test/gist.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ t.test('string methods populate correctly', t => {
t.equal(parsed.https(), 'git+https://gist.github.com/feedbeef.git')
t.equal(parsed.shortcut(), 'gist:feedbeef')
t.equal(parsed.path(), 'feedbeef')
t.equal(parsed.tarball(), 'https://codeload.github.com/gist/feedbeef/tar.gz/master')
t.equal(parsed.tarball(), 'https://codeload.github.com/gist/feedbeef/tar.gz/HEAD')
t.equal(parsed.file(), 'https://gist.githubusercontent.com/foo/feedbeef/raw/')
t.equal(parsed.file('/lib/index.js'), 'https://gist.githubusercontent.com/foo/feedbeef/raw/lib/index.js')
t.equal(parsed.git(), 'git://gist.github.com/feedbeef.git')
Expand Down
10 changes: 5 additions & 5 deletions test/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,15 @@ t.test('string methods populate correctly', t => {
t.equal(parsed.ssh(), 'git@github.com:foo/bar.git')
t.equal(parsed.sshurl(), 'git+ssh://git@github.com/foo/bar.git')
t.equal(parsed.browse(), 'https://github.com/foo/bar')
t.equal(parsed.browse('/lib/index.js'), 'https://github.com/foo/bar/tree/master/lib/index.js')
t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://github.com/foo/bar/tree/master/lib/index.js#l100')
t.equal(parsed.browse('/lib/index.js'), 'https://github.com/foo/bar/tree/HEAD/lib/index.js')
t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://github.com/foo/bar/tree/HEAD/lib/index.js#l100')
t.equal(parsed.docs(), 'https://github.com/foo/bar#readme')
t.equal(parsed.https(), 'git+https://github.com/foo/bar.git')
t.equal(parsed.shortcut(), 'github:foo/bar')
t.equal(parsed.path(), 'foo/bar')
t.equal(parsed.tarball(), 'https://codeload.github.com/foo/bar/tar.gz/master')
t.equal(parsed.file(), 'https://raw.githubusercontent.com/foo/bar/master/')
t.equal(parsed.file('/lib/index.js'), 'https://raw.githubusercontent.com/foo/bar/master/lib/index.js')
t.equal(parsed.tarball(), 'https://codeload.github.com/foo/bar/tar.gz/HEAD')
t.equal(parsed.file(), 'https://raw.githubusercontent.com/foo/bar/HEAD/')
t.equal(parsed.file('/lib/index.js'), 'https://raw.githubusercontent.com/foo/bar/HEAD/lib/index.js')
t.equal(parsed.git(), 'git://github.com/foo/bar.git')
t.equal(parsed.bugs(), 'https://github.com/foo/bar/issues')

Expand Down
10 changes: 5 additions & 5 deletions test/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,15 @@ t.test('string methods populate correctly', t => {
t.equal(parsed.ssh(), 'git@gitlab.com:foo/bar.git')
t.equal(parsed.sshurl(), 'git+ssh://git@gitlab.com/foo/bar.git')
t.equal(parsed.browse(), 'https://gitlab.com/foo/bar')
t.equal(parsed.browse('/lib/index.js'), 'https://gitlab.com/foo/bar/tree/master/lib/index.js')
t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://gitlab.com/foo/bar/tree/master/lib/index.js#l100')
t.equal(parsed.browse('/lib/index.js'), 'https://gitlab.com/foo/bar/tree/HEAD/lib/index.js')
t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://gitlab.com/foo/bar/tree/HEAD/lib/index.js#l100')
t.equal(parsed.docs(), 'https://gitlab.com/foo/bar#readme')
t.equal(parsed.https(), 'git+https://gitlab.com/foo/bar.git')
t.equal(parsed.shortcut(), 'gitlab:foo/bar')
t.equal(parsed.path(), 'foo/bar')
t.equal(parsed.tarball(), 'https://gitlab.com/foo/bar/repository/archive.tar.gz?ref=master')
t.equal(parsed.file(), 'https://gitlab.com/foo/bar/raw/master/')
t.equal(parsed.file('/lib/index.js'), 'https://gitlab.com/foo/bar/raw/master/lib/index.js')
t.equal(parsed.tarball(), 'https://gitlab.com/foo/bar/repository/archive.tar.gz?ref=HEAD')
t.equal(parsed.file(), 'https://gitlab.com/foo/bar/raw/HEAD/')
t.equal(parsed.file('/lib/index.js'), 'https://gitlab.com/foo/bar/raw/HEAD/lib/index.js')
t.equal(parsed.bugs(), 'https://gitlab.com/foo/bar/issues')

t.same(parsed.git(), null, 'git() returns null')
Expand Down

0 comments on commit 69e586d

Please sign in to comment.