Skip to content

Commit 82092c8

Browse files
committed
more reliable submodule origin parsing
1 parent 9242cb6 commit 82092c8

File tree

5 files changed

+21
-68
lines changed

5 files changed

+21
-68
lines changed

__tests__/lib/git/find_git.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test('findGit', function() {
1212

1313
expect(masterPaths).toEqual({
1414
git: path.join(root, '.git'),
15-
root: root
15+
root
1616
});
1717

1818
mock(mockRepo.submodule);
@@ -21,6 +21,6 @@ test('findGit', function() {
2121

2222
expect(submodulePaths).toEqual({
2323
git: path.join(path.dirname(root), '.git', 'modules', 'path'),
24-
root: root
24+
root
2525
});
2626
});

__tests__/utils.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,13 @@ module.exports.mockRepo = {
7979
repository: {
8080
path: {
8181
'.git': 'gitdir: ../.git/modules/path',
82-
'index.js': 'module.exports = 42;',
83-
'package.json': '{"repository": "foo/bar"}'
82+
'index.js': 'module.exports = 42;'
8483
},
8584
'.git': {
85+
config:
86+
'[submodule "path"]\n' +
87+
'url = https://github.com/foo/bar\n' +
88+
'active = true',
8689
modules: {
8790
path: {
8891
HEAD: 'ref: refs/heads/master',

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@
3939
"concat-stream": "^1.6.0",
4040
"diff": "^4.0.1",
4141
"doctrine-temporary-fork": "2.1.0",
42-
"get-pkg-repo": "^4.1.0",
4342
"get-port": "^4.0.0",
4443
"git-url-parse": "^10.0.1",
4544
"github-slugger": "1.2.0",
4645
"glob": "^7.1.2",
4746
"globals-docs": "^2.4.0",
4847
"highlight.js": "^9.15.5",
48+
"ini": "^1.3.5",
4949
"js-yaml": "^3.10.0",
5050
"lodash": "^4.17.10",
5151
"mdast-util-inject": "^1.1.0",
@@ -59,7 +59,6 @@
5959
"remark-html": "^8.0.0",
6060
"remark-reference-links": "^4.0.1",
6161
"remark-toc": "^5.0.0",
62-
"remote-origin-url": "0.4.0",
6362
"resolve": "^1.8.1",
6463
"stream-array": "^1.1.2",
6564
"strip-json-comments": "^2.0.1",

src/git/url_prefix.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
const fs = require('fs');
22
const path = require('path');
33
const gitUrlParse = require('git-url-parse');
4-
const getRemoteOrigin = require('remote-origin-url');
5-
const getPkgRepo = require('get-pkg-repo');
4+
const ini = require('ini');
65

76
/**
87
* Sometimes git will [pack refs](https://git-scm.com/docs/git-pack-refs)
@@ -58,20 +57,21 @@ function getGithubURLPrefix({ git, root }) {
5857
sha = head;
5958
}
6059
if (sha) {
61-
let githubRootUrl;
60+
let origin;
6261
if (git.indexOf(root) === 0) {
63-
const origin = getRemoteOrigin.sync(root);
64-
const parsed = gitUrlParse(origin);
65-
parsed.git_suffix = false; // eslint-disable-line
66-
githubRootUrl = parsed.toString('https');
62+
const config = ini.parse(
63+
fs.readFileSync(path.join(git, 'config'), 'utf8')
64+
);
65+
origin = config['remote "origin"'].url;
6766
} else {
68-
// git submodule; try looking at package.json
69-
const repo = getPkgRepo(
70-
JSON.parse(fs.readFileSync(path.join(root, 'package.json')))
67+
const config = ini.parse(
68+
fs.readFileSync(path.join(git, '..', '..', 'config'), 'utf8')
7169
);
72-
githubRootUrl = repo.browse();
70+
origin = config[`submodule "${path.basename(git)}"`].url;
7371
}
74-
return githubRootUrl + '/blob/' + sha.trim() + '/';
72+
const parsed = gitUrlParse(origin);
73+
parsed.git_suffix = false; // eslint-disable-line
74+
return parsed.toString('https') + '/blob/' + sha.trim() + '/';
7575
}
7676
} catch (e) {
7777
return null;

yarn.lock

+1-50
Original file line numberDiff line numberDiff line change
@@ -825,11 +825,6 @@
825825
lodash "^4.17.10"
826826
to-fast-properties "^2.0.0"
827827

828-
"@hutson/parse-repository-url@^3.0.0":
829-
version "3.0.2"
830-
resolved "https://registry.yarnpkg.com/@hutson/parse-repository-url/-/parse-repository-url-3.0.2.tgz#98c23c950a3d9b6c8f0daed06da6c3af06981340"
831-
integrity sha512-H9XAx3hc0BQHY6l+IFSWHDySypcXsvsuLhgYLUGywmJ5pswRVQJUHpOsobnLYp2ZUaUlKiKDrgWWhosOwAEM8Q==
832-
833828
"@samverschueren/stream-to-observable@^0.3.0":
834829
version "0.3.0"
835830
resolved "https://registry.yarnpkg.com/@samverschueren/stream-to-observable/-/stream-to-observable-0.3.0.tgz#ecdf48d532c58ea477acfcab80348424f8d0662f"
@@ -2682,16 +2677,6 @@ get-pkg-repo@^1.0.0:
26822677
parse-github-repo-url "^1.3.0"
26832678
through2 "^2.0.0"
26842679

2685-
get-pkg-repo@^4.1.0:
2686-
version "4.1.0"
2687-
resolved "https://registry.yarnpkg.com/get-pkg-repo/-/get-pkg-repo-4.1.0.tgz#bd2b109e297af8ec541ba271607aab439f9a8610"
2688-
integrity sha512-BHJovsEz9igoxU9Idfa9XjKr0OuAfg6/wInYegP0/M3efsdVtKo1DipPebwnTZXtL9gzaPLvJv74J/U68yiiMg==
2689-
dependencies:
2690-
"@hutson/parse-repository-url" "^3.0.0"
2691-
hosted-git-info "^2.1.4"
2692-
meow "^5.0.0"
2693-
through2 "^2.0.0"
2694-
26952680
get-port@^4.0.0:
26962681
version "4.0.0"
26972682
resolved "https://registry.yarnpkg.com/get-port/-/get-port-4.0.0.tgz#373c85960138ee20027c070e3cb08019fea29816"
@@ -3091,7 +3076,7 @@ inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.1, inherits@~2.0.3:
30913076
version "2.0.3"
30923077
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
30933078

3094-
ini@^1.3.2, ini@^1.3.3, ini@~1.3.0:
3079+
ini@^1.3.2, ini@^1.3.5, ini@~1.3.0:
30953080
version "1.3.5"
30963081
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927"
30973082

@@ -4364,21 +4349,6 @@ meow@^4.0.0:
43644349
redent "^2.0.0"
43654350
trim-newlines "^2.0.0"
43664351

4367-
meow@^5.0.0:
4368-
version "5.0.0"
4369-
resolved "https://registry.yarnpkg.com/meow/-/meow-5.0.0.tgz#dfc73d63a9afc714a5e371760eb5c88b91078aa4"
4370-
integrity sha512-CbTqYU17ABaLefO8vCU153ZZlprKYWDljcndKKDCFcYQITzWCXZAVk4QMFZPgvzrnUQ3uItnIE/LoUOwrT15Ig==
4371-
dependencies:
4372-
camelcase-keys "^4.0.0"
4373-
decamelize-keys "^1.0.0"
4374-
loud-rejection "^1.0.0"
4375-
minimist-options "^3.0.1"
4376-
normalize-package-data "^2.3.4"
4377-
read-pkg-up "^3.0.0"
4378-
redent "^2.0.0"
4379-
trim-newlines "^2.0.0"
4380-
yargs-parser "^10.0.0"
4381-
43824352
merge-stream@^1.0.1:
43834353
version "1.0.1"
43844354
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-1.0.1.tgz#4041202d508a342ba00174008df0c251b8c135e1"
@@ -4898,12 +4868,6 @@ parse-filepath@^1.0.2:
48984868
map-cache "^0.2.0"
48994869
path-root "^0.1.1"
49004870

4901-
parse-git-config@^0.2.0:
4902-
version "0.2.0"
4903-
resolved "https://registry.yarnpkg.com/parse-git-config/-/parse-git-config-0.2.0.tgz#272833fdd15fea146fb75d336d236b963b6ff706"
4904-
dependencies:
4905-
ini "^1.3.3"
4906-
49074871
parse-github-repo-url@^1.3.0:
49084872
version "1.4.1"
49094873
resolved "https://registry.yarnpkg.com/parse-github-repo-url/-/parse-github-repo-url-1.4.1.tgz#9e7d8bb252a6cb6ba42595060b7bf6df3dbc1f50"
@@ -5450,12 +5414,6 @@ remark@^9.0.0:
54505414
remark-stringify "^5.0.0"
54515415
unified "^6.0.0"
54525416

5453-
5454-
version "0.4.0"
5455-
resolved "https://registry.yarnpkg.com/remote-origin-url/-/remote-origin-url-0.4.0.tgz#4d3e2902f34e2d37d1c263d87710b77eb4086a30"
5456-
dependencies:
5457-
parse-git-config "^0.2.0"
5458-
54595417
remove-bom-buffer@^3.0.0:
54605418
version "3.0.0"
54615419
resolved "https://registry.yarnpkg.com/remove-bom-buffer/-/remove-bom-buffer-3.0.0.tgz#c2bf1e377520d324f623892e33c10cac2c252b53"
@@ -6741,13 +6699,6 @@ yallist@^3.0.0, yallist@^3.0.2:
67416699
version "3.0.3"
67426700
resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.0.3.tgz#b4b049e314be545e3ce802236d6cd22cd91c3de9"
67436701

6744-
yargs-parser@^10.0.0:
6745-
version "10.1.0"
6746-
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-10.1.0.tgz#7202265b89f7e9e9f2e5765e0fe735a905edbaa8"
6747-
integrity sha512-VCIyR1wJoEBZUqk5PA+oOBF6ypbwh5aNB3I50guxAL/quggdfs4TtNHQrSazFA3fYZ+tEqfs0zIGlv0c/rgjbQ==
6748-
dependencies:
6749-
camelcase "^4.1.0"
6750-
67516702
yargs-parser@^11.1.1:
67526703
version "11.1.1"
67536704
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-11.1.1.tgz#879a0865973bca9f6bab5cbdf3b1c67ec7d3bcf4"

0 commit comments

Comments
 (0)