Class: DEIS::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/rdeis/git.rb

Class Method Summary collapse

Class Method Details

.branchObject



34
35
36
# File 'lib/rdeis/git.rb', line 34

def self.branch
  `#{DEIS::Git.branch_cmd}`.strip
end

.branch_cmdObject



38
39
40
# File 'lib/rdeis/git.rb', line 38

def self.branch_cmd
  "git rev-parse --abbrev-ref HEAD"
end

.checkout_to_ref_cmd(ref, branch) ⇒ Object



46
47
48
# File 'lib/rdeis/git.rb', line 46

def self.checkout_to_ref_cmd(ref, branch)
  "git fetch origin && git checkout -f origin/#{branch} && git branch -d #{branch} ; git checkout -f #{branch} && git checkout -f #{ref} 2>&1 | grep 'error:' | wc -l"
end

.github_tokenObject

find env based token



51
52
53
54
# File 'lib/rdeis/git.rb', line 51

def self.github_token
  v = self.github_token_varname
  ENV[v]
end

.github_token_cmdObject

more advanced version that reads config files



57
58
59
# File 'lib/rdeis/git.rb', line 57

def self.github_token_cmd
  "cat #{DEIS::Storage::BASE_PATH}.profile  | grep #{DEIS::Git.github_token_varname}=.* -o | sed -E 's##{DEIS::Git.github_token_varname}=##' | sed -E 's#\"##g'"
end

.github_token_varnameObject



61
62
63
# File 'lib/rdeis/git.rb', line 61

def self.github_token_varname
  "GITHUB_TOKEN"
end

.init_with_remote_cmd(remote) ⇒ Object



42
43
44
# File 'lib/rdeis/git.rb', line 42

def self.init_with_remote_cmd(remote)
  "git init && git remote add origin #{remote} 2>&1 | grep 'fatal:' -o | wc -l"
end

.is_git?Boolean

Returns:

  • (Boolean)


4
5
6
7
# File 'lib/rdeis/git.rb', line 4

def self.is_git?
  res = `#{DEIS::Git.is_git_cmd}`.to_i
  if res == 0 then true else false end
end

.is_git_cmdObject



9
10
11
# File 'lib/rdeis/git.rb', line 9

def self.is_git_cmd
  "git status 2>&1 | grep 'fatal: Not a git' | wc -l"
end

.nameObject



13
14
15
16
17
18
19
20
# File 'lib/rdeis/git.rb', line 13

def self.name
  remote = DEIS::Git.remote
  if remote.nil? || remote.length == 0
    return "na"
  else
    `echo #{remote} | grep "/.*\.git" -o | sed -E "s#/##" | sed -E "s#.git##" 2>/dev/null`.strip
  end
end

.refObject



26
27
28
# File 'lib/rdeis/git.rb', line 26

def self.ref
  `#{DEIS::Git.ref_cmd}`.strip
end

.ref_cmdObject



30
31
32
# File 'lib/rdeis/git.rb', line 30

def self.ref_cmd
  "git rev-parse --verify HEAD 2>/dev/null"
end

.remoteObject



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

def self.remote
  `c=$(git remote show | wc -l ) ; if [ "$c" -gt 0 ]; then git remote show -n origin | grep " Fetch URL:" | grep ": .*" -o | sed -E "s#: ##" 2>/dev/null ; fi`.strip
end