Class: Braid::Commands::Add

Inherits:
Braid::Command show all
Defined in:
lib/braid/commands/add.rb

Instance Method Summary collapse

Methods inherited from Braid::Command

#config, #force?, handle_error, msg, #msg, #run, #verbose?

Methods included from T::Sig

#sig

Methods included from Operations::VersionControl

#git, #git_cache

Constructor Details

#initialize(url, options) ⇒ Add

Returns a new instance of Add.



35
36
37
38
# File 'lib/braid/commands/add.rb', line 35

def initialize(url, options)
  @url = url
  @options = options
end

Instance Method Details

#get_default_branch_name(url) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/braid/commands/add.rb', line 17

def get_default_branch_name(url)
  head_targets = []
  # The `HEAD` parameter here doesn't appear to do an exact match (it
  # appears to match any ref with `HEAD` as the last path component, such
  # as `refs/remotes/origin/HEAD` in the unusual case where the repository
  # contains its own remote-tracking branches), but it reduces the data we
  # have to scan a bit.
  git.ls_remote(['--symref', url, 'HEAD']).split("\n").each do |line|
    m = /^ref: (.*)\tHEAD$/.match(line)
    head_targets.push(m[1]) if m
  end
  return nil unless head_targets.size == 1
  m = /^refs\/heads\/(.*)$/.match(head_targets[0])
  return nil unless m
  m[1]
end