Skip to content

Commit 27a29be

Browse files
mournertmcw
authored andcommitted
fix: Git submodule support for repo names with a dot (#1271)
1 parent 43cd57d commit 27a29be

File tree

4 files changed

+27
-15
lines changed

4 files changed

+27
-15
lines changed

__tests__/lib/git/find_git.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ test('findGit', function() {
1616
});
1717

1818
mock(mockRepo.submodule);
19-
const submodulePaths = findGit(path.join(root, 'index.js'));
19+
const submoduleRoot = path.join(root, '..', 'my.submodule');
20+
const submodulePaths = findGit(path.join(submoduleRoot, 'index.js'));
2021
mock.restore();
2122

2223
expect(submodulePaths).toEqual({
23-
git: path.join(path.dirname(root), '.git', 'modules', 'path'),
24-
root
24+
git: path.join(
25+
path.dirname(submoduleRoot),
26+
'.git',
27+
'modules',
28+
'my.submodule'
29+
),
30+
root: submoduleRoot
2531
});
2632
});

__tests__/lib/git/url_prefix.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ test('getGithubURLPrefix', function() {
2626

2727
mock(mockRepo.submodule);
2828
const submoduleUrl = getGithubURLPrefix({
29-
git: '/my/repository/.git/modules/path',
30-
root: '/my/repository/path'
29+
git: '/my/repository/.git/modules/my.submodule',
30+
root: '/my/repository/my.submodule'
3131
});
3232
mock.restore();
3333

__tests__/utils.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,17 @@ module.exports.mockRepo = {
7777
submodule: {
7878
'/my': {
7979
repository: {
80-
path: {
81-
'.git': 'gitdir: ../.git/modules/path',
80+
'my.submodule': {
81+
'.git': 'gitdir: ../.git/modules/my.submodule',
8282
'index.js': 'module.exports = 42;'
8383
},
8484
'.git': {
8585
config:
86-
'[submodule "path"]\n' +
86+
'[submodule "my.submodule"]\n' +
8787
'url = https://github.com/foo/bar\n' +
8888
'active = true',
8989
modules: {
90-
path: {
90+
'my.submodule': {
9191
HEAD: 'ref: refs/heads/master',
9292
refs: {
9393
heads: {

src/git/url_prefix.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,10 @@ function getGithubURLPrefix({ git, root }) {
5959
if (sha) {
6060
let origin;
6161
if (git.indexOf(root) === 0) {
62-
const config = ini.parse(
63-
fs.readFileSync(path.join(git, 'config'), 'utf8')
64-
);
62+
const config = parseGitConfig(path.join(git, 'config'));
6563
origin = config['remote "origin"'].url;
6664
} else {
67-
const config = ini.parse(
68-
fs.readFileSync(path.join(git, '..', '..', 'config'), 'utf8')
69-
);
65+
const config = parseGitConfig(path.join(git, '..', '..', 'config'));
7066
origin = config[`submodule "${path.basename(git)}"`].url;
7167
}
7268
const parsed = gitUrlParse(origin);
@@ -78,5 +74,15 @@ function getGithubURLPrefix({ git, root }) {
7874
}
7975
}
8076

77+
function parseGitConfig(configPath) {
78+
const str = fs
79+
.readFileSync(configPath, 'utf8')
80+
.replace(
81+
/\[(\S+) "(.+)"\]/g,
82+
(match, key, value) => `[${key} "${value.split('.').join('\\.')}"]`
83+
);
84+
return ini.parse(str);
85+
}
86+
8187
module.exports = getGithubURLPrefix;
8288
module.exports.parsePackedRefs = parsePackedRefs;

0 commit comments

Comments
 (0)