Skip to content

Commit 51910bc

Browse files
committed
Merge pull request #33 from cball/handle-empty-git-info
Gracefully handle partial git info.
2 parents 5d232cd + 8c43f50 commit 51910bc

File tree

11 files changed

+76
-3
lines changed

11 files changed

+76
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ The unique identifier of this build based on the version in the `package.json`,
156156

157157
For example, if your package.json version is `v2.0.3`, and the current commit is `0993043d49f9e0[...]`, this generator will return a revision of `v2.0.3+0993043d`.
158158

159+
`Note:` Some environments (like CircleCI) may return partial git information. If the current commit hash cannot be determined, the generator will return only the package.json version (`v2.0.3`) as the `revisionKey`.
160+
159161
##### timestamp
160162

161163
The timestamp of the current deploy

lib/data-generators/version-commit.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,26 @@ module.exports = CoreObject.extend({
2121
}
2222

2323
var info = gitRepoInfo(path);
24-
var sha = info.sha.slice(0, 8);
24+
var sha = (info.sha || '').slice(0, 8);
25+
var log = this._plugin.log;
2526

2627
return readFile(versionFile)
2728
.then(function(contents) {
2829
var json = JSON.parse(contents);
2930

30-
if (!json.version || !sha) {
31+
if (!json.version) {
3132
return Promise.reject('Could not build revision with version `' + json.version + '` and commit hash `' + sha + '`');
3233
}
3334

35+
var versionString = json.version;
36+
if (sha) {
37+
versionString = versionString + '+' + sha;
38+
} else {
39+
log('Missing git commit sha, using package version as revisionKey', { color: 'yellow', verbose: true });
40+
}
41+
3442
return {
35-
revisionKey: json.version + '+' + sha,
43+
revisionKey: versionString,
3644
timestamp: new Date().toISOString()
3745
};
3846
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/master
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = true
4+
bare = false
5+
logallrefupdates = true
6+
ignorecase = true
7+
precomposeunicode = true
225 Bytes
Binary file not shown.

tests/fixtures/repo/dotgit-branch-only/objects/41/d41f081b45ad50935c08b1203220737d9739b4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x��A
2+
1 @Q�=E��4�L����"Ӧ�Z��������������7H��g�0N�GN�샥A�'&&t9~�Gmp^��X��E�Mp�_;��ֶ��~\���ak�Z��.2��Ԯ����OB�

tests/fixtures/repo/dotgit-branch-only/refs/heads/master

Whitespace-only changes.

0 commit comments

Comments
 (0)