diff --git a/lib/ronin/repos/repository.rb b/lib/ronin/repos/repository.rb index 0e94a76..45b61fb 100644 --- a/lib/ronin/repos/repository.rb +++ b/lib/ronin/repos/repository.rb @@ -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. # diff --git a/spec/repository_spec.rb b/spec/repository_spec.rb index 4bf51fc..1f662d2 100644 --- a/spec/repository_spec.rb +++ b/spec/repository_spec.rb @@ -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(