Skip to content

Commit 7761b8b

Browse files
committed
docs: help with shallow clone troubleshooting
* closes #7 * closes #12
1 parent 157e14a commit 7761b8b

File tree

2 files changed

+82
-24
lines changed

2 files changed

+82
-24
lines changed

readme.md

+75-23
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ resolves `extends` configurations.
2929

3030
```shell
3131
❯ conventional-changelog-lint --help
32-
conventional-changelog-lint@0.1.0 - Lint commit messages against a conventional-changelog preset and ruleset
32+
conventional-changelog-lint - Lint commit messages against a conventional-changelog preset and ruleset
3333

3434
[input] reads from stdin if --edit, --from, --to are omitted
3535
--color,-c toggle formatted output, defaults to: true
@@ -42,6 +42,41 @@ resolves `extends` configurations.
4242

4343
```
4444
45+
### Recipes
46+
47+
#### git hook
48+
As a `commitmsg` git-hook with ["husky"](https://git.io/JDwyQg)
49+
50+
```json
51+
{
52+
"scripts": {
53+
"commitmsg": "conventional-changelog-lint -e"
54+
}
55+
}
56+
```
57+
58+
59+
#### Last commit
60+
As part of `npm test`
61+
62+
```json
63+
{
64+
"scripts": {
65+
"test": "conventional-changelog-lint --from=HEAD~1"
66+
}
67+
}
68+
```
69+
70+
#### Travis
71+
72+
```yml
73+
# Force full git checkout
74+
before_install: git fetch --unshallow
75+
76+
# Lint all commits not in the target branch
77+
before_script: conventional-changelog-lint --from=$TRAVIS_BRANCH to=$TRAVIS_PULL_REQUEST_BRANCH
78+
```
79+
4580
### API
4681
4782
The programming interface does not read configuration by default,
@@ -77,28 +112,6 @@ const report = lint(
77112
);
78113
```
79114
80-
### Recipes
81-
82-
* As a `commitmsg` git-hook with ["husky"](https://git.io/JDwyQg)
83-
84-
```json
85-
{
86-
"scripts": {
87-
"commitmsg": "conventional-changelog-lint -e"
88-
}
89-
}
90-
```
91-
92-
* As part of `npm test`
93-
94-
```json
95-
{
96-
"scripts": {
97-
"test": "conventional-changelog-lint --from=HEAD~1"
98-
}
99-
}
100-
```
101-
102115
## Configuration
103116
104117
`conventional-changelog-lint` is configured via
@@ -186,6 +199,45 @@ wildcards: {
186199
}
187200
```
188201
202+
## Shallow clones
203+
204+
### TL;DR
205+
206+
Perform `git fetch --shallow` before linting.
207+
208+
Most likely you are reading this because you where presented with an error message:
209+
210+
```
211+
'Could not get git history from shallow clone.
212+
Use git fetch --shallow before linting.
213+
Original issue: https://git.io/vyKMq\n Refer to https://git.io/vyKMv for details.'
214+
```
215+
216+
### Explanation
217+
218+
git supports checking out `shallow` clones of a repository to save bandwith in times.
219+
These limited copies do not contain a full git history. This makes `conventional-changelog-lint`
220+
fail, especially when running on large commit ranges.
221+
To ensure linting works every time you should convert a shallow git repo to a complete one.
222+
Use `git fetch --shallow` to do so.
223+
224+
### Travis
225+
226+
Ensure full git checkouts on TravisCI, add to `.travis.yml`:
227+
228+
```yml
229+
before_install:
230+
- git fetch --unshallow
231+
```
232+
233+
### Appveyor
234+
235+
Ensure full git checkouts on AppVeyor, add to `appveyor.yml`:
236+
237+
```yml
238+
shallow_clone: false
239+
```
240+
189241
## Supported Node.js versions
190242
191243
conventional-changelog-lint supports the active Node.js [LTS](https://github.com/nodejs/LTS#lts-schedule) version and higher: `>= 4`

source/library/get-messages.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import {readFile} from 'mz/fs';
66

77
export default getCommitMessages;
88

9+
const SHALLOW_MESSAGE = [
10+
'Could not get git history from shallow clone.',
11+
'Use git fetch --shallow before linting.',
12+
'Original issue: https://git.io/vyKMq\n Refer to https://git.io/vyKMv for details.'
13+
].join('\n');
14+
915
// Get commit messages
1016
// Object => Promise<Array<String>>
1117
async function getCommitMessages(settings) {
@@ -16,7 +22,7 @@ async function getCommitMessages(settings) {
1622
}
1723

1824
if (await isShallow()) {
19-
throw new Error('Could not get git history from shallow clone. Original issue: https://git.io/vyKMq\n Refer to https://git.io/vyKMv for details.');
25+
throw new Error(SHALLOW_MESSAGE);
2026
}
2127

2228
return await getHistoryCommits({from, to});

0 commit comments

Comments
 (0)