Class: Kaya::Support::Git

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

Class Method Summary collapse

Class Method Details

.actual_branchObject



27
# File 'lib/kaya/support/git.rb', line 27

def self.actual_branch; self.branch; end

.add_allObject



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

def self.add_all
  Kaya::Support::Console.execute("git add .")
end

.add_file(filename) ⇒ Object



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

def self.add_file filename
  Kaya::Support::Console.execute("git add #{filename}")
end

.branchObject



23
24
25
# File 'lib/kaya/support/git.rb', line 23

def self.branch
  self.branches.select{|branch| branch.include? "*"}.first.gsub("*","").gsub(" ","")
end

.branch_listObject



7
8
9
10
11
12
13
# File 'lib/kaya/support/git.rb', line 7

def self.branch_list
  self.remote_branches.map do |branch|
    branch.gsub("*","").gsub(" ","").gsub("origin/","")
  end.select do |branch|
    not (branch.include? "HEAD" or branch.include? "/")
  end
end

.branchesObject



29
30
31
# File 'lib/kaya/support/git.rb', line 29

def self.branches
  Kaya::Support::Console.execute("git branch").split("\n")
end

.checkout_and_pull_from(branch_name = nil) ⇒ Object



105
106
107
108
109
# File 'lib/kaya/support/git.rb', line 105

def self.checkout_and_pull_from branch_name=nil
  self.checkout_to(branch_name) if branch_name
  branch_name = self.branch if branch_name.nil?
  self.pull_from branch_name
end

.checkout_to(branch) ⇒ Object



101
102
103
# File 'lib/kaya/support/git.rb', line 101

def self.checkout_to branch
  Kaya::Support::Console.execute("git checkout #{branch}") unless self.actual_branch == branch
end

.commit(msg = nil) ⇒ Object



72
73
74
75
76
# File 'lib/kaya/support/git.rb', line 72

def self.commit msg = nil
  # self.ensure_being_at_kaya_branch
  msg = "KAYA COMMIT #{Time.new.strftime('%d %m %Y %H:%M:%S')}" if msg.nil?
  Kaya::Support::Console.execute"git commit -m '#{msg}'"
end

.commitsObject



127
128
129
# File 'lib/kaya/support/git.rb', line 127

def self.commits
  self.log.split("commit")[1..-1]
end

.commits_idsObject



121
122
123
124
125
# File 'lib/kaya/support/git.rb', line 121

def self.commits_ids
  self.log.split("\n").select do |line|
      self.is_commit_id? line
  end
end

.create_branch_and_checkout(branch) ⇒ Object



78
79
80
# File 'lib/kaya/support/git.rb', line 78

def self.create_branch_and_checkout branch
  Kaya::Support::Console.execute("git checkout -b #{branch}")
end

.delete_branch(branch) ⇒ Object



82
83
84
85
# File 'lib/kaya/support/git.rb', line 82

def self.delete_branch branch
  checkout_to "master"
  Kaya::Support::Console.execute("git branch -D #{branch}")
end

.fetchObject



19
20
21
# File 'lib/kaya/support/git.rb', line 19

def self.fetch
  Kaya::Support::Console.execute("git fetch")
end

.get_actual_linesObject

Returns an Array with the existing files on .gitignore

Parameters:

  • (Array)


172
173
174
175
176
177
178
179
# File 'lib/kaya/support/git.rb', line 172

def self.get_actual_lines
  f = File.open("#{Dir.pwd}/.gitignore","r")
  files_list = []
  f.each_line do |line|
    files_list << line.gsub("\n","").gsub(" ","")
  end
  files_list
end

.get_last_commit_idString

Returns las commit id. This method is used by Execution class to verify changes before each execution

Parameters:

  • the (String)

    name of the project (folder project)

Returns:

  • (String)

    the id for the las commit



115
116
117
118
119
# File 'lib/kaya/support/git.rb', line 115

def self.get_last_commit_id
  self.commits_ids.map do |commit|
      commit.gsub("commit ","")
  end.first
end

.git_add_commit(msg = nil) ⇒ Object



33
34
35
36
# File 'lib/kaya/support/git.rb', line 33

def self.git_add_commit msg=nil
  self.add_all
  self.commit msg
end

.git_push_origin_to(branch_name = nil) ⇒ Object



50
51
52
53
# File 'lib/kaya/support/git.rb', line 50

def self.git_push_origin_to branch_name=nil
  branch_name = self.branch if branch_name.nil?
  Kaya::Support::Console.execute("git push origin #{branch_name}")
end

.git_push_origin_to_actual_branchObject



63
64
65
66
# File 'lib/kaya/support/git.rb', line 63

def self.git_push_origin_to_actual_branch
  branch_name = self.branch
  self.git_push_origin_to branch_name
end

.is_commit_id?(line) ⇒ Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/kaya/support/git.rb', line 131

def self.is_commit_id? line
  line.start_with? "commit "
end

.is_there_commit_id_diff?(obtained_commit) ⇒ Boolean

Returns:

  • (Boolean)


160
161
162
# File 'lib/kaya/support/git.rb', line 160

def self.is_there_commit_id_diff? obtained_commit
    obtained_commit != self.last_commit_id
end

.last_commitObject



156
157
158
# File 'lib/kaya/support/git.rb', line 156

def self.last_commit
  self.commits.first
end

.last_remote_commitObject



135
136
137
# File 'lib/kaya/support/git.rb', line 135

def self.last_remote_commit
  self.remote_commits.first
end

.logObject



148
149
150
# File 'lib/kaya/support/git.rb', line 148

def self.log
  Kaya::Support::Console.execute "git log"
end

.log_last_commitObject



152
153
154
# File 'lib/kaya/support/git.rb', line 152

def self.log_last_commit
  "Commit: #{self.commits.first}"
end

.pullObject

Performs pull from actual branc



88
89
90
# File 'lib/kaya/support/git.rb', line 88

def self.pull
  self.pull_from(self.actual_branch)
end

.pull_from(branch_name = nil) ⇒ Object



92
93
94
95
# File 'lib/kaya/support/git.rb', line 92

def self.pull_from(branch_name=nil)
  branch_name = self.branch if branch_name.nil?
  Kaya::Support::Console.execute("git pull origin #{branch_name}")
end

.pushObject



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

def self.push
  Kaya::Support::Console.execute("git push")
end

.remote_branchesObject



15
16
17
# File 'lib/kaya/support/git.rb', line 15

def self.remote_branches
  Kaya::Support::Console.execute("git branch -r").split("\n")
end

.remote_commitsObject



139
140
141
# File 'lib/kaya/support/git.rb', line 139

def self.remote_commits
  self.remote_log.split("commit")[1..-1]
end

.remote_logObject



143
144
145
146
# File 'lib/kaya/support/git.rb', line 143

def self.remote_log
  self.fetch
  Kaya::Support::Console.execute "git log origin/#{self.actual_branch}"
end

.remote_urlObject



164
165
166
167
168
# File 'lib/kaya/support/git.rb', line 164

def self.remote_url

  res = Kaya::Support::Console.execute("git config --get remote.origin.url").gsub(":","/").gsub("git@", 'http://').chop
  res[0..-5] if res.end_with? ".git"
end

.reset_hardObject



55
56
57
# File 'lib/kaya/support/git.rb', line 55

def self.reset_hard
  Kaya::Support::Console.execute("git reset --hard")
end

.reset_hard_and_pullObject



59
60
61
# File 'lib/kaya/support/git.rb', line 59

def self.reset_hard_and_pull
  self.reset_hard and self.pull
end

.return_to_branch(branch) ⇒ Object



97
98
99
# File 'lib/kaya/support/git.rb', line 97

def self.return_to_branch branch
  self.checkout_to branch
end