Class: UpdateRepo::GitControl

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/update_repo/git_control.rb

Overview

Class : GitControl. This class will update one git repo, and send the output to the logger. It will also return status of the operation in #status.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#trunc_dir

Constructor Details

#initialize(dir, logger, metrics, cmd) ⇒ void

Constructor for the GitControl class.

Examples:

git = GitControl.new(repo_url, @logger, @metrics)

Parameters:

  • dir (string)

    The directory location of this local repo.

  • logger (instance)

    pointer to the Logger class

  • metrics (instance)

    pointer to the Metrics class

  • cmd (instance)

    pointer to the command options class



25
26
27
28
29
30
31
# File 'lib/update_repo/git_control.rb', line 25

def initialize(dir, logger, metrics, cmd)
  @status = { updated: false, failed: false, unchanged: false }
  @dir = dir
  @log = logger
  @metrics = metrics
  @cmd = cmd
end

Instance Attribute Details

#statushash (readonly)

Return the status hash

Returns:

  • (hash)

    Return the status hash



15
16
17
# File 'lib/update_repo/git_control.rb', line 15

def status
  @status
end

Instance Method Details

#updatevoid

This method returns an undefined value.

Update the git repo that was specified in the initializer.

Parameters:

  • (none)


36
37
38
39
40
41
42
43
44
# File 'lib/update_repo/git_control.rb', line 36

def update
  print_log '* Checking ', @dir.green, " (#{repo_url})\n"
  Open3.popen2e("git -C #{@dir} pull") do |_stdin, stdout_err, _thread|
    stdout_err.each { |line| handle_output(line) }
  end
  # reset the updated status in the rare case than both update and failed
  # are set. This does happen!
  @status[:updated] = false if @status[:updated] && @status[:failed]
end