Module: Rookout::ComWs::Git

Included in:
Information
Defined in:
lib/rookout/com_ws/git.rb

Constant Summary collapse

GIT_FOLDER =
".git".freeze
GIT_HEAD =
"HEAD".freeze
GIT_CONFIG =
"config".freeze
REMOTE_ORIGINS =
/\[remote "origin"\]\s*url\s*=\s*(\S*)/.freeze

Instance Method Summary collapse

Instance Method Details

#find_root(path) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rookout/com_ws/git.rb', line 10

def find_root path
  # Return if found
  return path if git? path

  # Get next, fail if there's no next
  next_path = File.dirname path
  return nil if next_path == path

  # Recursive call
  find_root next_path
end


40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rookout/com_ws/git.rb', line 40

def follow_sym_links root, link
  link_path = File.join root, link
  link_contents = File.read link_path

  if link_contents.start_with? "ref:"
    next_link = link_contents.split[1].strip
    follow_sym_links root, next_link
  else
    link_contents.strip
  end
end

#git?(path) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/rookout/com_ws/git.rb', line 35

def git? path
  potential_git_folder = File.join path, GIT_FOLDER
  File.directory? potential_git_folder
end

#remote_origin(path) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/rookout/com_ws/git.rb', line 26

def remote_origin path
  git_config_path = File.join path, GIT_FOLDER, GIT_CONFIG
  git_config_contents = File.read git_config_path
  match = git_config_contents.match REMOTE_ORIGINS
  return "" if match.captures.empty?

  match.captures[0]
end

#revision(path) ⇒ Object



22
23
24
# File 'lib/rookout/com_ws/git.rb', line 22

def revision path
  follow_sym_links File.join(path, GIT_FOLDER), GIT_HEAD
end