lib/sdoc/github.rb in sdoc-0.2.17 vs lib/sdoc/github.rb in sdoc-0.2.18

- old
+ new

@@ -16,22 +16,29 @@ end @github_url_cache[path] end protected - + + def have_git? + @have_git = system('git --version > /dev/null 2>&1') if @have_git.nil? + @have_git + end + def commit_sha1(path) + return false unless have_git? name = File.basename(path) - s = in_dir(File.join(basedir, File.dirname(path))) do + s = Dir.chdir(File.join(basedir, File.dirname(path))) do `git log -1 --pretty=format:"commit %H" #{name}` end m = s.match(/commit\s+(\S+)/) m ? m[1] : false end def repository_url(path) - s = in_dir(File.join(basedir, File.dirname(path))) do + return false unless have_git? + s = Dir.chdir(File.join(basedir, File.dirname(path))) do `git config --get remote.origin.url` end m = s.match(%r{github.com[/:](.*)\.git$}) m ? "http://github.com/#{m[1]}/blob/" : false end @@ -48,17 +55,7 @@ return path end path = File.dirname(path) end '' - end - - def in_dir(dir) - pwd = Dir.pwd - Dir.chdir dir - return yield - rescue Exception => e - return '' - ensure - Dir.chdir pwd end end