Module: Nucleus::Adapters::GitRepoAnalyzer

Defined in:
lib/nucleus/core/file_handling/git_repo_analyzer.rb

Class Method Summary collapse

Class Method Details

.any_branch?(repo_host, repo_name, username) ⇒ TrueClass, FalseClass

Is the repository having any branch?

Parameters:

  • repo_host (String)

    repository host where the repository can be retrieved

  • repo_name (String)

    name of the directory for the repository that shall be created in the tmp dir

  • username (String)

    user to authenticate with

Returns:

  • (TrueClass, FalseClass)

    true if the repository has any non-empty branch, e.g. ‘master’



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/nucleus/core/file_handling/git_repo_analyzer.rb', line 9

def self.any_branch?(repo_host, repo_name, username)
  detected_branch = false
  options = { forward_agent: true, auth_methods: ['publickey'],
              keys: [nucleus_config.ssh.handler.key_file], keys_only: true }
  Net::SSH.start(repo_host, username, options) do |ssh|
    ssh.exec! "git-upload-pack '/#{repo_name}.git'" do |ch, stream, data|
      detected_branch = (detected_branch || data != '0000') unless stream == :stderr
      ch.close
    end
  end
  detected_branch
end