Class: ConfCtl::GitRepoMirror

Inherits:
Object
  • Object
show all
Defined in:
lib/confctl/git_repo_mirror.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, quiet: false) ⇒ GitRepoMirror

Returns a new instance of GitRepoMirror.

Parameters:

  • url (String)
  • quiet (Boolean) (defaults to: false)


10
11
12
13
14
15
# File 'lib/confctl/git_repo_mirror.rb', line 10

def initialize(url, quiet: false)
  @url = url
  @quiet = quiet
  @name = Digest::SHA256.hexdigest(url)
  @cmd = SystemCommand.new
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/confctl/git_repo_mirror.rb', line 6

def name
  @name
end

#urlObject (readonly)

Returns the value of attribute url.



6
7
8
# File 'lib/confctl/git_repo_mirror.rb', line 6

def url
  @url
end

Instance Method Details

#diff(from_ref, to_ref, opts: []) ⇒ Object

Parameters:

  • from_ref (String)
  • to_ref (String)


44
45
46
47
48
49
50
51
52
# File 'lib/confctl/git_repo_mirror.rb', line 44

def diff(from_ref, to_ref, opts: [])
  ret = "git diff for #{from_ref}..#{to_ref}\n"
  ret << git_repo(
    'diff',
    opts:,
    args: ["#{from_ref}..#{to_ref}"]
  )
  ret
end

#log(from_ref, to_ref, opts: []) ⇒ Object

Parameters:

  • from_ref (String)
  • to_ref (String)


32
33
34
35
36
37
38
39
40
# File 'lib/confctl/git_repo_mirror.rb', line 32

def log(from_ref, to_ref, opts: [])
  ret = "git log for #{from_ref}..#{to_ref}\n"
  ret << git_repo(
    'log',
    opts: ['--no-decorate', '--left-right', '--cherry-mark'] + opts,
    args: ["#{from_ref}..#{to_ref}"]
  )
  ret
end

#revision_parse(str) ⇒ Object



26
27
28
# File 'lib/confctl/git_repo_mirror.rb', line 26

def revision_parse(str)
  git_repo('rev-parse', args: [str])
end

#setupObject



17
18
19
20
21
22
23
24
# File 'lib/confctl/git_repo_mirror.rb', line 17

def setup
  File.stat(mirror_path)
rescue Errno::ENOENT
  FileUtils.mkdir_p(mirror_path)
  git('clone', args: ['--mirror', url, mirror_path])
else
  git_repo('fetch')
end