@@ -28,6 +28,12 @@ module Audit
2828 #
2929 class Database
3030
31+ #
32+ # @since 0.10.0
33+ #
34+ class GitNotInstalled < RuntimeError
35+ end
36+
3137 class DownloadFailed < RuntimeError
3238 end
3339
@@ -103,8 +109,9 @@ def self.exists?(path=DEFAULT_PATH)
103109 # @return [Dataase]
104110 # The newly downloaded database.
105111 #
106- # @raise [DownloadFailed]
107- # Indicates that the download failed.
112+ # @raise [DownloadFailed, GitNotInstalled]
113+ # * {DownloadFailed} - the `git clone` command failed.
114+ # * {GitNotInstalled} - the `git` command is not installed.
108115 #
109116 # @note
110117 # Requires network access.
@@ -116,8 +123,11 @@ def self.download(path: DEFAULT_PATH, quiet: false)
116123 command << '--quiet' if quiet
117124 command << URL << path
118125
119- unless system ( *command )
126+ case system ( *command )
127+ when false
120128 raise ( DownloadFailed , "failed to download #{ URL } to #{ path . inspect } " )
129+ when nil
130+ raise ( GitNotInstalled , "the git command is not installed" )
121131 end
122132
123133 return new ( path )
@@ -182,6 +192,10 @@ def git?
182192 # @raise [UpdateFailed]
183193 # Could not update the ruby-advisory-db git repository.
184194 #
195+ # @raise [UpdateFailed, GitNotInstalled]
196+ # * {UpdateFailed} - the `git pull` command failed.
197+ # * {GitNotInstalled} - the `git` command is not installed.
198+ #
185199 # @since 0.8.0
186200 #
187201 def update! ( quiet : false )
@@ -191,8 +205,11 @@ def update!(quiet: false)
191205 command << '--quiet' if quiet
192206 command << 'origin' << 'master'
193207
194- unless system ( *command )
208+ case system ( *command )
209+ when false
195210 raise ( UpdateFailed , "failed to update #{ @path . inspect } " )
211+ when nil
212+ raise ( GitNotInstalled , "the git command is not installed" )
196213 end
197214
198215 return true
@@ -206,12 +223,17 @@ def update!(quiet: false)
206223 # @return [String, nil]
207224 # The commit hash or `nil` if the database is not a git repository.
208225 #
226+ # @raise [GitNotInstalled]
227+ # The `git` command is not installed.
228+ #
209229 # @since 0.9.0
210230 #
211231 def commit_id
212232 if git?
213233 Dir . chdir ( @path ) do
214234 `git rev-parse HEAD` . chomp
235+ rescue Errno ::ENOENT
236+ raise ( GitNotInstalled , "the git command is not installed" )
215237 end
216238 end
217239 end
@@ -221,12 +243,17 @@ def commit_id
221243 #
222244 # @return [Time]
223245 #
246+ # @raise [GitNotInstalled]
247+ # The `git` command is not installed.
248+ #
224249 # @since 0.8.0
225250 #
226251 def last_updated_at
227252 if git?
228253 Dir . chdir ( @path ) do
229254 Time . parse ( `git log --date=iso8601 --pretty="%cd" -1` )
255+ rescue Errno ::ENOENT
256+ raise ( GitNotInstalled , "the git command is not installed" )
230257 end
231258 else
232259 File . mtime ( @path )
0 commit comments