Skip to content

Commit

Permalink
Fallback to default year if -r flag used in directory without git repo.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ridha Hassoun committed Mar 14, 2017
1 parent 3fa74c7 commit ff93dd7
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ program
var yearArg = this.year || new Date().getFullYear();

if (this.range) {
var firstCommitYear = firstCommitDate.sync(cwd + '/.git').getFullYear();
var currentYear = new Date().getFullYear();
if (currentYear === firstCommitYear) {
yearArg = currentYear;
} else {
yearArg = firstCommitYear + "-" + currentYear;
try {
var firstCommitYear = firstCommitDate.sync(cwd + '/.git').getFullYear();
var currentYear = new Date().getFullYear();
if (currentYear === firstCommitYear) {
yearArg = currentYear;
} else {
yearArg = firstCommitYear + "-" + currentYear;
}
} catch (error) {
console.log('git repository not found in this directory. Using', yearArg, 'as year.');
}
}

Expand Down

0 comments on commit ff93dd7

Please sign in to comment.