lib/adapters/git_adapter.rb in idonethis-cli-0.19.1 vs lib/adapters/git_adapter.rb in idonethis-cli-0.20.0
- old
+ new
@@ -1,24 +1,32 @@
module Idonethis::Adapters
module Git
class << self
- def commits(dir, since, how_many = 1000)
+ def commits(opts={})
require 'git'
+
+ fail "opts is supposed to be a hash" unless opts.is_a?(Hash)
- since_when = case since
- when 'yesterday'
- '1am yesterday'
- when 'today'
- '1am'
- else
- since
- end
+ dir, since, how_many, log = defaults.merge(opts).values_at(:dir, :since, :how_many, :log)
+
+ since_when = since.strftime("%d-%b-%Y")
+
+ since_when = '1am' if since == Date.today
+ since_when = '1am yesterday' if since == (Date.today - 1)
+
+ log.call("Using <#{since_when}> as the since date for git")
- ::Git.open(dir).log(how_many).since(since_when)
+ ::Git.open(dir).log(how_many).since("1am #{since_when}")
end
def repo?(dir)
File.exists?(File.join(dir, ".git"))
+ end
+
+ private
+
+ def defaults
+ { log: ->(msg) {}, how_many: 1000 }
end
end
end
end