Skip to content

Commit 9c211d6

Browse files
committed
Improved the removeCommit function
The date field is not mandatory anymore.
1 parent e8b643a commit 9c211d6

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

lib/index.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var Ul = require("ul")
1414
, Typpy = require("typpy")
1515
, Exec = ChildProcess.exec
1616
, Spawn = ChildProcess.spawn
17+
, IterateObject = require("iterate-object")
1718
;
1819

1920
// Constants
@@ -209,7 +210,7 @@ GitStats.prototype.record = function (data, callback) {
209210
* @function
210211
* @param {Object} data The commit data containing:
211212
*
212-
* - `date` (String|Date): The date object or a string in a format that can be parsed.
213+
* - `date` (String|Date): The date object or a string in a format that can be parsed. If not provided, the hash object will be searched in all dates.
213214
* - `hash` (String): The commit hash.
214215
* - `_data` (Object): If this field is provided, it should be the content of the git-stats data file as object. It will be modified in-memory and then returned.
215216
* - `save` (Boolean): If `false`, the result will *not* be saved in the file.
@@ -230,8 +231,7 @@ GitStats.prototype.removeCommit = function (data, callback) {
230231
}
231232

232233
if (!/^moment|date$/.test(Typpy(data.date))) {
233-
callback(new Error("The date field should be a string or a date object."));
234-
return GitStats;
234+
data.date = null;
235235
} else if (Typpy(data.date, Date)) {
236236
data.date = Moment(data.date);
237237
}
@@ -244,13 +244,19 @@ GitStats.prototype.removeCommit = function (data, callback) {
244244
function modify (err, stats) {
245245

246246
if (err) { return callback(err); }
247+
if (!data.date) {
248+
debugger
249+
IterateObject(stats.commits, function (todayObj) {
250+
delete todayObj[data.hash];
251+
});
252+
} else {
253+
var commits = stats.commits
254+
, day = data.date.format(DATE_FORMAT)
255+
, today = commits[day] = Object(commits[day])
256+
;
247257

248-
var commits = stats.commits
249-
, day = data.date.format(DATE_FORMAT)
250-
, today = commits[day] = Object(commits[day])
251-
;
252-
253-
delete today[data.hash];
258+
delete today[data.hash];
259+
}
254260

255261
if (data.save === false) {
256262
callback(null, stats);

0 commit comments

Comments
 (0)