class Coaster::Git::Repository
Attributes
Public Class Methods
Source
# File lib/coaster/git/repository.rb, line 8 def initialize(path) @path = path end
Public Instance Methods
Source
# File lib/coaster/git/repository.rb, line 28 def add(*paths, **options) opts = Options.new('add', **options) run_git_cmd("add", *paths, opts) end
Source
# File lib/coaster/git/repository.rb, line 39 def branch(*args, **options) run_git_cmd("branch", *args, **options) end
Source
# File lib/coaster/git/repository.rb, line 43 def checkout(*args, **options) run_git_cmd("checkout", *args, **options) end
Source
# File lib/coaster/git/repository.rb, line 33 def commit(*args, **options) opts = Options.new('commit', *args, **options) opts['--message'] ||= "no message" run_git_cmd("commit", opts) end
Source
# File lib/coaster/git/repository.rb, line 67 def current_sha run_git_cmd('rev-parse HEAD').strip end
Source
# File lib/coaster/git/repository.rb, line 116 def deep_merge(pointer) puts "[DEEP_MERGE] #{path} #{pointer}" submodules.values.each do |submodule| sm_sha = submodule_sha(submodule.path, pointer: pointer) submodule.merge(sm_sha) if sm_sha.present? end merge_without_submodules do merge(pointer) if pointer.present? end end
Source
# File lib/coaster/git/repository.rb, line 59 def fetch(*args, **options) run_git_cmd("fetch", *args, **options) end
Source
# File lib/coaster/git/repository.rb, line 83 def merge(pointer, *args, **options) opts = Options.new('merge', *args, **options) pointers = pointers(pointer).join(',') puts "[MERGE] #{path} #{pointers} #{options}" opts['--message'] ||= "Merge #{pointers}" run_git_cmd("merge #{pointer} #{opts}") end
Source
# File lib/coaster/git/repository.rb, line 96 def merge_without_submodules run_git_cmd('config merge.ours.name "Keep ours merge driver"') run_git_cmd('config merge.ours.driver true') ga_file = File.join(@path, '.gitattributes') run_cmd("touch #{ga_file}") ga_lines = File.read(ga_file).split("\n") ga_lines_appended = ga_lines + submodules.keys.map{|sb_path| "#{sb_path} merge=ours" } File.open(ga_file, 'w') do |f| f.puts ga_lines_appended.join("\n") end add('.') commit yield File.open(ga_file, 'w') do |f| f.puts ga_lines.join("\n") end add('.') commit end
Source
# File lib/coaster/git/repository.rb, line 127 def pointers(sha) run_git_cmd("branch --contains #{sha}").split("\n").map do |br| br = (br.start_with?('*') ? br[2..-1] : br).strip br.match?(/^\(.*\)$/) ? nil : br end.compact end
Source
# File lib/coaster/git/repository.rb, line 134 def remove run_cmd("rm -rf #{path}", path: path.split('/')[0..-2].join('/')) end
Source
# File lib/coaster/git/repository.rb, line 12 def run_cmd(command, path: nil) super(path || @path, command) end
Calls superclass method
Coaster::Git#run_cmd
Source
# File lib/coaster/git/repository.rb, line 22 def run_git_cmd(command, *args, **options) opts = Options.new(command, *args, **options) cmd = "git #{@git_options} #{Array.wrap(command).join(' ')} #{opts}" run_cmd(cmd) end
Source
# File lib/coaster/git/repository.rb, line 63 def status(*args, **options) run_git_cmd("status", *args, **options) end
Source
# File lib/coaster/git/repository.rb, line 47 def submodule_add!(repo, path, *args, **options) run_git_cmd(["submodule", 'add'], repo, path, *args, **options) end
Source
# File lib/coaster/git/repository.rb, line 51 def submodule_init!(*paths) run_git_cmd(["submodule", "init"], *paths) end
Source
# File lib/coaster/git/repository.rb, line 71 def submodule_paths @submodule_paths ||= run_git_cmd('submodule status --recursive').split("\n").map do |line| line.split(' ')[1] end end
Source
# File lib/coaster/git/repository.rb, line 91 def submodule_sha(path, pointer: nil) pointer ||= current_sha run_git_cmd("ls-tree #{pointer} #{path}").split(' ')[2] end
Source
# File lib/coaster/git/repository.rb, line 55 def submodule_update!(*paths, **options) run_git_cmd(["submodule", "update"], *paths, **options) end
Source
# File lib/coaster/git/repository.rb, line 77 def submodules @submodules ||= submodule_paths.map do |path| [path, Git::Repository.new(File.join(@path, path))] end.to_h end
Source
# File lib/coaster/git/repository.rb, line 16 def with_git_options(*args, **options, &block) @git_options = Options.new('git', *args, **options) yield @git_options = nil end