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

Lines changed: 9 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 12 additions & 6 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy