Skip to content

Commit 3759582

Browse files
committed
feat: pass config defaultBranchName to gitinfo if provided
1 parent f6c6ba6 commit 3759582

File tree

7 files changed

+35
-2
lines changed

7 files changed

+35
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ Prints a string formatted according to the given [moment format](http://momentjs
564564
Generates:
565565

566566
```markdown
567-
1560895526
567+
1561166482
568568
2019
569569
```
570570

src/helpers/gitinfo.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const createGitinfo = require('gitinfo');
55
helper.compile = (config, context) => {
66
const parserConfig = context.gitdown.getConfig().gitinfo;
77
const gitinfo = createGitinfo({
8-
gitPath: parserConfig.gitPath
8+
gitPath: parserConfig.gitPath,
9+
...parserConfig.defaultBranchName && {defaultBranchName: parserConfig.defaultBranchName}
910
});
1011

1112
const methodMap = {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/some-untracked-branch
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = true
4+
bare = false
5+
logallrefupdates = true
6+
ignorecase = true
7+
precomposeunicode = true
8+
[remote "origin"]
9+
url = git@github.com:foo/bar.git
10+
fetch = +refs/heads/*:refs/remotes/origin/*
11+
[branch "master"]
12+
remote = origin
13+
merge = refs/heads/master
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

tests/gitdown.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ describe('Gitdown.read()', () => {
108108

109109
expect(response).to.equal('abc');
110110
});
111+
it('does not fail when HEAD is untracked', async () => {
112+
const gitdown = Gitdown.read('{"gitdown": "gitinfo", "name": "name"}');
113+
114+
gitdown.setConfig({
115+
gitinfo: {
116+
defaultBranchName: 'master',
117+
gitPath: path.resolve(__dirname, './dummy_git_untracked_head/')
118+
}
119+
});
120+
121+
const response = await gitdown.get();
122+
123+
expect(response).to.equal('bar');
124+
});
111125
});
112126
describe('.writeFile()', () => {
113127
it('writes the output of .get() to a file', async () => {

0 commit comments

Comments
 (0)