Skip to content

Commit cbf04f9

Browse files
mterrelisaacs
authored andcommitted
fix(gitlab): Do not URL encode slashes in project name for GitLab https URL
PR-URL: #47 Credit: @mterrel Close: #47 Reviewed-by: @isaacs
1 parent d5cf830 commit cbf04f9

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

git-host-info.js

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var gitHosts = module.exports = {
2323
'domain': 'gitlab.com',
2424
'treepath': 'tree',
2525
'bugstemplate': 'https://{domain}/{user}/{project}/issues',
26+
'httpstemplate': 'git+https://{auth@}{domain}/{user}/{projectPath}.git{#committish}',
2627
'tarballtemplate': 'https://{domain}/{user}/{project}/repository/archive.tar.gz?ref={committish}'
2728
},
2829
gist: {

git-host.js

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ GitHost.prototype._fill = function (template, opts) {
3636
var rawcommittish = vars.committish
3737
var rawFragment = vars.fragment
3838
var rawPath = vars.path
39+
var rawProject = vars.project
3940
Object.keys(vars).forEach(function (key) {
4041
vars[key] = encodeURIComponent(vars[key])
4142
})
@@ -44,6 +45,7 @@ GitHost.prototype._fill = function (template, opts) {
4445
vars.fragment = vars.fragment ? vars.fragment : ''
4546
vars['#path'] = rawPath ? '#' + this.hashformat(rawPath) : ''
4647
vars['/path'] = vars.path ? '/' + vars.path : ''
48+
vars.projectPath = rawProject.split('/').map(encodeURIComponent).join('/')
4749
if (opts.noCommittish) {
4850
vars['#committish'] = ''
4951
vars['/tree/committish'] = ''

test/gitlab.js

+6
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,11 @@ test('fromUrl(gitlab url)', function (t) {
2323
require('./lib/standard-tests')(verify, 'gitlab.com', 'gitlab')
2424
require('./lib/standard-tests')(verify, 'www.gitlab.com', 'gitlab')
2525

26+
t.is(
27+
HostedGit.fromUrl('gitlab:group/sub group1/subgroup2/repo').https(),
28+
'git+https://gitlab.com/group/sub%20group1/subgroup2/repo.git',
29+
'subgroups are delimited with slashes and url encoded (shortcut -> https)'
30+
)
31+
2632
t.end()
2733
})

0 commit comments

Comments
 (0)