Class: GitShallowClone

Inherits:
Object
  • Object
show all
Defined in:
lib/gitarro/git_op.rb

Overview

handle shallow clone by default

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(git_dir, pr, options) ⇒ GitShallowClone

Returns a new instance of GitShallowClone.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gitarro/git_op.rb', line 11

def initialize(git_dir, pr, options)
  @git_dir = git_dir
  # pr object for extract all relev. data.
  @pr = pr
  # All gitarro options
  @options = options
  gh = 'https://github.com/'
  gg = '[email protected]:'
  @repo_protocol = @options[:https] ? gh : gg
  @repo_url = @options[:https] ? pr.head.repo.html_url : pr.head.repo.ssh_url
end

Instance Attribute Details

#git_dirObject (readonly)

Returns the value of attribute git_dir.



10
11
12
# File 'lib/gitarro/git_op.rb', line 10

def git_dir
  @git_dir
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/gitarro/git_op.rb', line 10

def options
  @options
end

#prObject (readonly)

Returns the value of attribute pr.



10
11
12
# File 'lib/gitarro/git_op.rb', line 10

def pr
  @pr
end

#repo_protocolObject (readonly)

Returns the value of attribute repo_protocol.



10
11
12
# File 'lib/gitarro/git_op.rb', line 10

def repo_protocol
  @repo_protocol
end

Instance Method Details

#cloneObject

shallow clone



24
25
26
27
28
29
30
# File 'lib/gitarro/git_op.rb', line 24

def clone
  tmp_dir = create_tmp_dir!
  git_local = "#{git_dir}/#{tmp_dir}"
  puts `git clone --depth 1 #{@repo_url} -b #{pr.head.ref} #{git_local}`
  exit 1 if $CHILD_STATUS.exitstatus.nonzero?
  Dir.chdir git_local
end