Skip to content

Commit

Permalink
Added Repository#last_updated_at (closes #18).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Nov 3, 2023
1 parent 1e93ae8 commit 76cacbc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/ronin/repos/repository.rb
Expand Up @@ -152,6 +152,20 @@ def url
end
end

#
# Determines when the repository was last updated.
#
# @return [Time]
# The timestamp of the last commit will be returned.
#
# @since 0.2.0
#
def last_updated_at
Dir.chdir(@path) do
Time.parse(`git log --date=iso8601 --pretty="%cd" -1`)
end
end

#
# Pulls down new git commits.
#
Expand Down
13 changes: 13 additions & 0 deletions spec/repository_spec.rb
Expand Up @@ -149,6 +149,19 @@
end
end

describe "#last_updated_at" do
let(:timestamp) { "2023-09-27 20:11:03 -0700" }
let(:time) { Time.parse(timestamp) }

it "must run 'git log --date=iso8601 --pretty=\"%cd\" -1' and return the parsed timestamp of the last commit" do
expect(subject).to receive(:`).with(
'git log --date=iso8601 --pretty="%cd" -1'
).and_return("#{timestamp}\n")

expect(subject.last_updated_at).to eq(time)
end
end

describe "#pull" do
it "must `git pull` from 'origin'" do
expect(subject).to receive(:system).with(
Expand Down

0 comments on commit 76cacbc

Please sign in to comment.