class Au::Staging
Public Class Methods
abs_path(relative_path)
click to toggle source
# File lib/au/models/staging.rb, line 87 def self.abs_path(relative_path) paths = [Repository.root, relative_path].compact File.join(*paths) end
clear_staged_file_paths()
click to toggle source
# File lib/au/models/staging.rb, line 65 def self.clear_staged_file_paths File.delete stage_db.path end
filter_stageable(last_commit, relative_paths)
click to toggle source
private
# File lib/au/models/staging.rb, line 46 def self.filter_stageable(last_commit, relative_paths) tracked_docs_md5 = last_commit&.tracked_docs_md5 || {} relative_paths.reject do |relative_path| known_md5 = tracked_docs_md5[relative_path] abs_path = File.join(Repository.root, relative_path) if File.exists?(abs_path) known_md5 && Digest::MD5.hexdigest(File.read(abs_path)) == known_md5 else known_md5.nil? end end end
project_file_paths()
click to toggle source
# File lib/au/models/staging.rb, line 92 def self.project_file_paths Dir.glob('**/*', base: Repository.root).reject do |file_path| File.directory? file_path end end
stage(relative_paths, last_commit = Repository.head)
click to toggle source
# File lib/au/models/staging.rb, line 25 def self.stage(relative_paths, last_commit = Repository.head) relative_paths = relative_paths.each_with_object([]) do |staged_path, accum| if File.directory?(File.join(Repository.root, staged_path)) Dir.glob('**/*', base: File.join(Repository.root, staged_path)) do |sub_path| accum << (File.join(staged_path, sub_path)) unless File.directory?(File.join( Repository.root, staged_path, sub_path)) end else accum << staged_path end end stage_db.transaction do filter_stageable(last_commit, relative_paths).each do |relative_path| stage_db[relative_path] = 1 end end relative_paths end
stage_db()
click to toggle source
private
# File lib/au/models/staging.rb, line 99 def self.stage_db @stage_db ||= PStore.new(File.join(*[Repository.path, 'stage.pstore'].compact)) end
staged_file_paths()
click to toggle source
# File lib/au/models/staging.rb, line 59 def self.staged_file_paths stage_db.transaction(true) do stage_db.roots end end
status(last_commit = Repository.head)
click to toggle source
# File lib/au/models/staging.rb, line 7 def self.status(last_commit = Repository.head) return project_file_paths unless last_commit changed_doc_paths = [] tracked_docs_md5 = last_commit.tracked_docs_md5 project_file_paths.each do |relative_path| known_md5 = tracked_docs_md5[relative_path] # file not tracked or tracked but hasn't changed if known_md5.nil? || Digest::MD5.hexdigest(File.read(abs_path(relative_path))) != known_md5 changed_doc_paths << relative_path end tracked_docs_md5.delete(relative_path) if known_md5 end # remaining files in tracked_docs_md5 are no longer in the project changed_doc_paths += tracked_docs_md5.keys unless tracked_docs_md5.empty? changed_doc_paths end
unstage(file_paths)
click to toggle source
# File lib/au/models/staging.rb, line 69 def self.unstage(file_paths) file_paths = file_paths.each_with_object([]) do |staged_path, accum| if File.directory?(staged_path) Dir.glob('**/*', base: staged_path) do |sub_path| accum << (File.join(staged_path, sub_path)) unless File.directory?(sub_path) end else accum << staged_path end end stage_db.transaction do file_paths.each do |file_path| stage_db.delete(file_path) end end end