Class: MRuby::Command::Git

Inherits:
MRuby::Command show all
Defined in:
ext/enterprise_script_service/mruby/lib/mruby/build/command.rb

Instance Attribute Summary collapse

Attributes inherited from MRuby::Command

#build, #command

Instance Method Summary collapse

Methods inherited from MRuby::Command

#clone, #shellquote

Constructor Details

#initialize(build) ⇒ Git

Returns a new instance of Git.



277
278
279
280
281
282
283
284
285
286
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 277

def initialize(build)
  super
  @command = 'git'
  @flags = %w[]
  @clone_options = "clone %{flags} %{url} %{dir}"
  @pull_options = "--git-dir %{repo_dir}/.git --work-tree %{repo_dir} pull"
  @checkout_options = "--git-dir %{repo_dir}/.git --work-tree %{repo_dir} checkout %{checksum_hash}"
  @checkout_detach_options = "--git-dir %{repo_dir}/.git --work-tree %{repo_dir} checkout --detach %{checksum_hash}"
  @reset_options = "--git-dir %{repo_dir}/.git --work-tree %{repo_dir} reset %{checksum_hash}"
end

Instance Attribute Details

#checkout_detach_optionsObject

Returns the value of attribute checkout_detach_options.



275
276
277
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 275

def checkout_detach_options
  @checkout_detach_options
end

#checkout_optionsObject

Returns the value of attribute checkout_options.



275
276
277
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 275

def checkout_options
  @checkout_options
end

#clone_optionsObject

Returns the value of attribute clone_options.



275
276
277
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 275

def clone_options
  @clone_options
end

#flagsObject

Returns the value of attribute flags.



274
275
276
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 274

def flags
  @flags
end

#pull_optionsObject

Returns the value of attribute pull_options.



275
276
277
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 275

def pull_options
  @pull_options
end

#reset_optionsObject

Returns the value of attribute reset_options.



275
276
277
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 275

def reset_options
  @reset_options
end

Instance Method Details

#commit_hash(dir) ⇒ Object



313
314
315
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 313

def commit_hash(dir)
  `#{@command} --git-dir #{shellquote(dir +'/.git')} --work-tree #{shellquote(dir)} rev-parse --verify HEAD`.strip
end

#current_branch(dir) ⇒ Object



317
318
319
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 317

def current_branch(dir)
  `#{@command} --git-dir #{shellquote(dir + '/.git')} --work-tree #{shellquote(dir)} rev-parse --abbrev-ref HEAD`.strip
end

#run_checkout(dir, checksum_hash) ⇒ Object



298
299
300
301
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 298

def run_checkout(dir, checksum_hash)
  _pp "GIT CHECKOUT", dir, checksum_hash
  _run checkout_options, { :checksum_hash => checksum_hash, :repo_dir => shellquote(dir) }
end

#run_checkout_detach(dir, checksum_hash) ⇒ Object



303
304
305
306
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 303

def run_checkout_detach(dir, checksum_hash)
  _pp "GIT CHECKOUT DETACH", dir, checksum_hash
  _run checkout_detach_options, { :checksum_hash => checksum_hash, :repo_dir => shellquote(dir) }
end

#run_clone(dir, url, _flags = []) ⇒ Object



288
289
290
291
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 288

def run_clone(dir, url, _flags = [])
  _pp "GIT", url, dir.relative_path
  _run clone_options, { :flags => [flags, _flags].flatten.join(' '), :url => shellquote(url), :dir => shellquote(filename(dir)) }
end

#run_pull(dir, url) ⇒ Object



293
294
295
296
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 293

def run_pull(dir, url)
  _pp "GIT PULL", url, dir.relative_path
  _run pull_options, { :repo_dir => shellquote(dir) }
end

#run_reset_hard(dir, checksum_hash) ⇒ Object



308
309
310
311
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 308

def run_reset_hard(dir, checksum_hash)
  _pp "GIT RESET", dir, checksum_hash
  _run reset_options, { :checksum_hash => checksum_hash, :repo_dir => shellquote(dir) }
end