Skip to content

Commit 89155e8

Browse files
darcyclarkelukekarrys
authored andcommitted
feat!: set default git ref to HEAD
1 parent 61ca7fb commit 89155e8

File tree

6 files changed

+26
-26
lines changed

6 files changed

+26
-26
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ provided to a method override those provided to the constructor.
6868

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

7373
For example `hostedGitInfo.fromUrl("git@github.com:npm/hosted-git-info.git#v1.0.0").file("package.json")`
7474
would return `https://raw.githubusercontent.com/npm/hosted-git-info/v1.0.0/package.json`

lib/git-host-info.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ const maybeEncode = (arg) => arg ? encodeURIComponent(arg) : ''
66
const defaults = {
77
sshtemplate: ({ domain, user, project, committish }) => `git@${domain}:${user}/${project}.git${maybeJoin('#', committish)}`,
88
sshurltemplate: ({ domain, user, project, committish }) => `git+ssh://git@${domain}/${user}/${project}.git${maybeJoin('#', committish)}`,
9-
edittemplate: ({ domain, user, project, committish, editpath, path }) => `https://${domain}/${user}/${project}${maybeJoin('/', editpath, '/', maybeEncode(committish || 'master'), '/', path)}`,
9+
edittemplate: ({ domain, user, project, committish, editpath, path }) => `https://${domain}/${user}/${project}${maybeJoin('/', editpath, '/', maybeEncode(committish || 'HEAD'), '/', path)}`,
1010
browsetemplate: ({ domain, user, project, committish, treepath }) => `https://${domain}/${user}/${project}${maybeJoin('/', treepath, '/', maybeEncode(committish))}`,
11-
browsefiletemplate: ({ domain, user, project, committish, treepath, path, fragment, hashformat }) => `https://${domain}/${user}/${project}/${treepath}/${maybeEncode(committish || 'master')}/${path}${maybeJoin('#', hashformat(fragment || ''))}`,
11+
browsefiletemplate: ({ domain, user, project, committish, treepath, path, fragment, hashformat }) => `https://${domain}/${user}/${project}/${treepath}/${maybeEncode(committish || 'HEAD')}/${path}${maybeJoin('#', hashformat(fragment || ''))}`,
1212
docstemplate: ({ domain, user, project, treepath, committish }) => `https://${domain}/${user}/${project}${maybeJoin('/', treepath, '/', maybeEncode(committish))}#readme`,
1313
httpstemplate: ({ auth, domain, user, project, committish }) => `git+https://${maybeJoin(auth, '@')}${domain}/${user}/${project}.git${maybeJoin('#', committish)}`,
14-
filetemplate: ({ domain, user, project, committish, path }) => `https://${domain}/${user}/${project}/raw/${maybeEncode(committish) || 'master'}/${path}`,
14+
filetemplate: ({ domain, user, project, committish, path }) => `https://${domain}/${user}/${project}/raw/${maybeEncode(committish) || 'HEAD'}/${path}`,
1515
shortcuttemplate: ({ type, user, project, committish }) => `${type}:${user}/${project}${maybeJoin('#', committish)}`,
1616
pathtemplate: ({ user, project, committish }) => `${user}/${project}${maybeJoin('#', committish)}`,
1717
bugstemplate: ({ domain, user, project }) => `https://${domain}/${user}/${project}/issues`,
@@ -26,9 +26,9 @@ gitHosts.github = Object.assign({}, defaults, {
2626
domain: 'github.com',
2727
treepath: 'tree',
2828
editpath: 'edit',
29-
filetemplate: ({ auth, user, project, committish, path }) => `https://${maybeJoin(auth, '@')}raw.githubusercontent.com/${user}/${project}/${maybeEncode(committish) || 'master'}/${path}`,
29+
filetemplate: ({ auth, user, project, committish, path }) => `https://${maybeJoin(auth, '@')}raw.githubusercontent.com/${user}/${project}/${maybeEncode(committish) || 'HEAD'}/${path}`,
3030
gittemplate: ({ auth, domain, user, project, committish }) => `git://${maybeJoin(auth, '@')}${domain}/${user}/${project}.git${maybeJoin('#', committish)}`,
31-
tarballtemplate: ({ domain, user, project, committish }) => `https://codeload.${domain}/${user}/${project}/tar.gz/${maybeEncode(committish) || 'master'}`,
31+
tarballtemplate: ({ domain, user, project, committish }) => `https://codeload.${domain}/${user}/${project}/tar.gz/${maybeEncode(committish) || 'HEAD'}`,
3232
extract: (url) => {
3333
let [, user, project, type, committish] = url.pathname.split('/', 5)
3434
if (type && type !== 'tree') {
@@ -56,8 +56,8 @@ gitHosts.bitbucket = Object.assign({}, defaults, {
5656
domain: 'bitbucket.org',
5757
treepath: 'src',
5858
editpath: '?mode=edit',
59-
edittemplate: ({ domain, user, project, committish, treepath, path, editpath }) => `https://${domain}/${user}/${project}${maybeJoin('/', treepath, '/', maybeEncode(committish || 'master'), '/', path, editpath)}`,
60-
tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}/get/${maybeEncode(committish) || 'master'}.tar.gz`,
59+
edittemplate: ({ domain, user, project, committish, treepath, path, editpath }) => `https://${domain}/${user}/${project}${maybeJoin('/', treepath, '/', maybeEncode(committish || 'HEAD'), '/', path, editpath)}`,
60+
tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}/get/${maybeEncode(committish) || 'HEAD'}.tar.gz`,
6161
extract: (url) => {
6262
let [, user, project, aux] = url.pathname.split('/', 4)
6363
if (['get'].includes(aux)) {
@@ -82,7 +82,7 @@ gitHosts.gitlab = Object.assign({}, defaults, {
8282
treepath: 'tree',
8383
editpath: '-/edit',
8484
httpstemplate: ({ auth, domain, user, project, committish }) => `git+https://${maybeJoin(auth, '@')}${domain}/${user}/${project}.git${maybeJoin('#', committish)}`,
85-
tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}/repository/archive.tar.gz?ref=${maybeEncode(committish) || 'master'}`,
85+
tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}/repository/archive.tar.gz?ref=${maybeEncode(committish) || 'HEAD'}`,
8686
extract: (url) => {
8787
const path = url.pathname.slice(1)
8888
if (path.includes('/-/') || path.includes('/archive.tar.gz')) {
@@ -120,7 +120,7 @@ gitHosts.gist = Object.assign({}, defaults, {
120120
pathtemplate: ({ project, committish }) => `${project}${maybeJoin('#', committish)}`,
121121
bugstemplate: ({ domain, project }) => `https://${domain}/${project}`,
122122
gittemplate: ({ domain, project, committish }) => `git://${domain}/${project}.git${maybeJoin('#', committish)}`,
123-
tarballtemplate: ({ project, committish }) => `https://codeload.github.com/gist/${project}/tar.gz/${maybeEncode(committish) || 'master'}`,
123+
tarballtemplate: ({ project, committish }) => `https://codeload.github.com/gist/${project}/tar.gz/${maybeEncode(committish) || 'HEAD'}`,
124124
extract: (url) => {
125125
let [, user, project, aux] = url.pathname.split('/', 4)
126126
if (aux === 'raw') {

test/bitbucket.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,15 @@ t.test('string methods populate correctly', t => {
184184
t.equal(parsed.edit(), 'https://bitbucket.org/foo/bar')
185185
t.equal(parsed.edit('/lib/index.js'), 'https://bitbucket.org/foo/bar/src/master/lib/index.js?mode=edit')
186186
t.equal(parsed.browse(), 'https://bitbucket.org/foo/bar')
187-
t.equal(parsed.browse('/lib/index.js'), 'https://bitbucket.org/foo/bar/src/master/lib/index.js')
188-
t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://bitbucket.org/foo/bar/src/master/lib/index.js#l100')
187+
t.equal(parsed.browse('/lib/index.js'), 'https://bitbucket.org/foo/bar/src/HEAD/lib/index.js')
188+
t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://bitbucket.org/foo/bar/src/HEAD/lib/index.js#l100')
189189
t.equal(parsed.docs(), 'https://bitbucket.org/foo/bar#readme')
190190
t.equal(parsed.https(), 'git+https://bitbucket.org/foo/bar.git')
191191
t.equal(parsed.shortcut(), 'bitbucket:foo/bar')
192192
t.equal(parsed.path(), 'foo/bar')
193-
t.equal(parsed.tarball(), 'https://bitbucket.org/foo/bar/get/master.tar.gz')
194-
t.equal(parsed.file(), 'https://bitbucket.org/foo/bar/raw/master/')
195-
t.equal(parsed.file('/lib/index.js'), 'https://bitbucket.org/foo/bar/raw/master/lib/index.js')
193+
t.equal(parsed.tarball(), 'https://bitbucket.org/foo/bar/get/HEAD.tar.gz')
194+
t.equal(parsed.file(), 'https://bitbucket.org/foo/bar/raw/HEAD/')
195+
t.equal(parsed.file('/lib/index.js'), 'https://bitbucket.org/foo/bar/raw/HEAD/lib/index.js')
196196
t.equal(parsed.bugs(), 'https://bitbucket.org/foo/bar/issues')
197197

198198
t.equal(parsed.docs({ committish: 'fix/bug' }), 'https://bitbucket.org/foo/bar/src/fix%2Fbug#readme', 'allows overriding options')

test/gist.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ t.test('string methods populate correctly', t => {
354354
t.equal(parsed.https(), 'git+https://gist.github.com/feedbeef.git')
355355
t.equal(parsed.shortcut(), 'gist:feedbeef')
356356
t.equal(parsed.path(), 'feedbeef')
357-
t.equal(parsed.tarball(), 'https://codeload.github.com/gist/feedbeef/tar.gz/master')
357+
t.equal(parsed.tarball(), 'https://codeload.github.com/gist/feedbeef/tar.gz/HEAD')
358358
t.equal(parsed.file(), 'https://gist.githubusercontent.com/foo/feedbeef/raw/')
359359
t.equal(parsed.file('/lib/index.js'), 'https://gist.githubusercontent.com/foo/feedbeef/raw/lib/index.js')
360360
t.equal(parsed.git(), 'git://gist.github.com/feedbeef.git')

test/github.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,15 @@ t.test('string methods populate correctly', t => {
238238
t.equal(parsed.edit('/lib/index.js'), 'https://github.com/foo/bar/edit/master/lib/index.js')
239239
t.equal(parsed.edit('/lib/index.js', { committish: 'docs' }), 'https://github.com/foo/bar/edit/docs/lib/index.js')
240240
t.equal(parsed.browse(), 'https://github.com/foo/bar')
241-
t.equal(parsed.browse('/lib/index.js'), 'https://github.com/foo/bar/tree/master/lib/index.js')
242-
t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://github.com/foo/bar/tree/master/lib/index.js#l100')
241+
t.equal(parsed.browse('/lib/index.js'), 'https://github.com/foo/bar/tree/HEAD/lib/index.js')
242+
t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://github.com/foo/bar/tree/HEAD/lib/index.js#l100')
243243
t.equal(parsed.docs(), 'https://github.com/foo/bar#readme')
244244
t.equal(parsed.https(), 'git+https://github.com/foo/bar.git')
245245
t.equal(parsed.shortcut(), 'github:foo/bar')
246246
t.equal(parsed.path(), 'foo/bar')
247-
t.equal(parsed.tarball(), 'https://codeload.github.com/foo/bar/tar.gz/master')
248-
t.equal(parsed.file(), 'https://raw.githubusercontent.com/foo/bar/master/')
249-
t.equal(parsed.file('/lib/index.js'), 'https://raw.githubusercontent.com/foo/bar/master/lib/index.js')
247+
t.equal(parsed.tarball(), 'https://codeload.github.com/foo/bar/tar.gz/HEAD')
248+
t.equal(parsed.file(), 'https://raw.githubusercontent.com/foo/bar/HEAD/')
249+
t.equal(parsed.file('/lib/index.js'), 'https://raw.githubusercontent.com/foo/bar/HEAD/lib/index.js')
250250
t.equal(parsed.git(), 'git://github.com/foo/bar.git')
251251
t.equal(parsed.bugs(), 'https://github.com/foo/bar/issues')
252252

test/gitlab.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,15 +290,15 @@ t.test('string methods populate correctly', t => {
290290
t.equal(parsed.edit(), 'https://gitlab.com/foo/bar')
291291
t.equal(parsed.edit('/lib/index.js'), 'https://gitlab.com/foo/bar/-/edit/master/lib/index.js')
292292
t.equal(parsed.browse(), 'https://gitlab.com/foo/bar')
293-
t.equal(parsed.browse('/lib/index.js'), 'https://gitlab.com/foo/bar/tree/master/lib/index.js')
294-
t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://gitlab.com/foo/bar/tree/master/lib/index.js#l100')
293+
t.equal(parsed.browse('/lib/index.js'), 'https://gitlab.com/foo/bar/tree/HEAD/lib/index.js')
294+
t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://gitlab.com/foo/bar/tree/HEAD/lib/index.js#l100')
295295
t.equal(parsed.docs(), 'https://gitlab.com/foo/bar#readme')
296296
t.equal(parsed.https(), 'git+https://gitlab.com/foo/bar.git')
297297
t.equal(parsed.shortcut(), 'gitlab:foo/bar')
298298
t.equal(parsed.path(), 'foo/bar')
299-
t.equal(parsed.tarball(), 'https://gitlab.com/foo/bar/repository/archive.tar.gz?ref=master')
300-
t.equal(parsed.file(), 'https://gitlab.com/foo/bar/raw/master/')
301-
t.equal(parsed.file('/lib/index.js'), 'https://gitlab.com/foo/bar/raw/master/lib/index.js')
299+
t.equal(parsed.tarball(), 'https://gitlab.com/foo/bar/repository/archive.tar.gz?ref=HEAD')
300+
t.equal(parsed.file(), 'https://gitlab.com/foo/bar/raw/HEAD/')
301+
t.equal(parsed.file('/lib/index.js'), 'https://gitlab.com/foo/bar/raw/HEAD/lib/index.js')
302302
t.equal(parsed.bugs(), 'https://gitlab.com/foo/bar/issues')
303303

304304
t.same(parsed.git(), null, 'git() returns null')

0 commit comments

Comments
 (0)