Skip to content

Commit e7abb5d

Browse files
authoredSep 23, 2023
Fix getting Git remote name (#173)
1 parent 0c1d847 commit e7abb5d

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed
 

‎rules/github.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,26 @@ module.exports = rule('remark-lint:awesome-github', async (ast, file) => {
1313
'--show-current'
1414
]);
1515

16-
const remoteName = await execa.stdout('git', [
17-
'config',
18-
'--get',
19-
`branch.${gitBranch}.remote`
20-
]);
16+
let remoteName;
17+
if (gitBranch) {
18+
remoteName = await execa.stdout('git', [
19+
'config',
20+
'--get',
21+
`branch.${gitBranch}.remote`
22+
]);
23+
} else {
24+
// If HEAD does not point to a branch, it is in a detached state.
25+
// This can occur with '@actions/checkout'. In such cases, we read
26+
// it from the config key 'clone.defaultRemoteName'. If that is not
27+
// set, then it is defaulted to 'origin'. See #172 for details.
28+
remoteName = await execa.stdout('git', [
29+
'config',
30+
'--default',
31+
'origin',
32+
'--get',
33+
'clone.defaultRemoteName'
34+
]);
35+
}
2136

2237
const remoteUrl = await execa.stdout('git', [
2338
'remote',

0 commit comments

Comments
 (0)