Skip to content

Commit

Permalink
Merge pull request #53 from golopot/pass-gitinfo-config-defaultBranch…
Browse files Browse the repository at this point in the history
…Name

feat: pass config `defaultBranchName` to gitinfo if provided
  • Loading branch information
gajus authored Jun 22, 2019
2 parents f6c6ba6 + 56d8b34 commit 79f4eef
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ Prints a string formatted according to the given [moment format](http://momentjs
Generates:

```markdown
1560895526
1561166577
2019
```

Expand Down
3 changes: 2 additions & 1 deletion src/helpers/gitinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const createGitinfo = require('gitinfo');
helper.compile = (config, context) => {
const parserConfig = context.gitdown.getConfig().gitinfo;
const gitinfo = createGitinfo({
gitPath: parserConfig.gitPath
gitPath: parserConfig.gitPath,
...parserConfig.defaultBranchName && {defaultBranchName: parserConfig.defaultBranchName}
});

const methodMap = {
Expand Down
1 change: 1 addition & 0 deletions tests/dummy_git_untracked_head/HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref: refs/heads/some-untracked-branch
13 changes: 13 additions & 0 deletions tests/dummy_git_untracked_head/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = [email protected]:foo/bar.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
2 changes: 2 additions & 0 deletions tests/dummy_git_untracked_head/objects/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
2 changes: 2 additions & 0 deletions tests/dummy_git_untracked_head/refs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
14 changes: 14 additions & 0 deletions tests/gitdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ describe('Gitdown.read()', () => {

expect(response).to.equal('abc');
});
it('does not fail when HEAD is untracked', async () => {
const gitdown = Gitdown.read('{"gitdown": "gitinfo", "name": "name"}');

gitdown.setConfig({
gitinfo: {
defaultBranchName: 'master',
gitPath: path.resolve(__dirname, './dummy_git_untracked_head/')
}
});

const response = await gitdown.get();

expect(response).to.equal('bar');
});
});
describe('.writeFile()', () => {
it('writes the output of .get() to a file', async () => {
Expand Down

0 comments on commit 79f4eef

Please sign in to comment.