lib/gitdocs/runner.rb in gitdocs-0.4.7 vs lib/gitdocs/runner.rb in gitdocs-0.4.8
- old
+ new
@@ -4,26 +4,26 @@
attr_reader :root, :listener
def initialize(share)
@share = share
- @root = share.path
+ @root = share.path.sub(%r{/+$},'') if share.path
@polling_interval = share.polling_interval
@icon = File.expand_path("../../img/icon.png", __FILE__)
end
SearchResult = Struct.new(:file, :context)
def search(term)
results = []
- if result_test = sh_string("git grep #{ShellTools.escape(term)}")
+ if result_test = sh_string("git grep -i #{ShellTools.escape(term)}")
result_test.scan(/(.*?):([^\n]*)/) { |(file, context)| results << SearchResult.new(file, context) }
end
results
end
def run
- return false unless self.valid?
+ return false unless self.valid? && !self.root.empty?
@show_notifications = @share.notification
@current_remote = @share.remote_name
@current_branch = @share.branch_name
@current_revision = sh_string("git rev-parse HEAD")
Guard::Notifier.turn_on if @show_notifications
@@ -138,29 +138,24 @@
end
end
IGNORED_FILES = ['.gitignore']
# dir_files("some/dir") => [<Docfile>, <Docfile>]
- def dir_files(dir)
- dir_path = File.expand_path(dir, @root)
- files = {}
- ls_files = sh_string("git ls-files").split("\n").map { |f| Docfile.new(f) }
- ls_files.select { |f| f.within?(dir, @root) }.each do |f|
- path = File.expand_path(f.parent, root)
- files[path] ||= Docdir.new(path)
- files[path].files << f unless IGNORED_FILES.include?(f.name)
- end
- files.keys.each { |f| files[f].parent = files[File.dirname(f)] }
- files[dir_path]
+ def dir_files(dir_path)
+ Dir[File.join(dir_path, "*")].to_a.map { |path| Docfile.new(path) }
end
def file_meta(file)
+ result = {}
file = file.gsub(%r{^/}, '')
full_path = File.expand_path(file, @root)
- author, modified = sh_string("git log --format='%aN|%ai' -n1 #{ShellTools.escape(file)}").split("|")
+ log_result = sh_string("git log --format='%aN|%ai' -n1 #{ShellTools.escape(file)}")
+ result = {} unless File.exist?(full_path) && log_result
+ author, modified = log_result.split("|")
modified = Time.parse(modified.sub(' ', 'T')).utc.iso8601
size = (File.symlink?(full_path) || File.directory?(full_path)) ? -1 : File.size(full_path)
- { :author => author, :size => size, :modified => modified }
+ result = { :author => author, :size => size, :modified => modified }
+ result
end
def valid?
out, status = sh_with_code "git status"
status.success?