Class: Mutx::Support::Git
- Inherits:
-
Object
- Object
- Mutx::Support::Git
- Defined in:
- lib/mutx/support/git.rb
Class Method Summary collapse
- .actual_branch ⇒ Object
- .add_all ⇒ Object
- .add_commit(msg = nil) ⇒ Object
- .add_file(filename) ⇒ Object
- .branch ⇒ Object
- .branch_list ⇒ Object
- .branches ⇒ Object
-
.changed_files_on_last_commit ⇒ Array
Returns an Array of changed files on last commit.
- .checkout_and_pull_from(branch_name = nil) ⇒ Object
- .checkout_to(branch) ⇒ Object
- .commit(msg = nil) ⇒ Object
- .commits ⇒ Object
- .commits_ids ⇒ Object
- .create_branch_and_checkout(branch) ⇒ Object
- .delete_branch(branch) ⇒ Object
- .fetch ⇒ Object
-
.get_actual_lines ⇒ Object
Returns an Array with the existing files on .gitignore.
-
.get_last_commit_id ⇒ String
Returns las commit id.
- .git_push_origin_to(branch_name = nil) ⇒ Object
- .is_commit_id?(line) ⇒ Boolean
-
.is_there_commit_id_diff?(obtained_commit) ⇒ Bool
Returns true if the obtained commit is different from the last saved commit.
- .last_commit ⇒ Object
- .last_remote_commit ⇒ Object
- .log ⇒ Object
- .log_last_commit ⇒ Object
-
.pull ⇒ Object
Performs pull from actual branc.
- .pull_from(branch_name = nil) ⇒ Object
- .push ⇒ Object
- .push_origin_to_actual_branch ⇒ Object
- .remote_branches ⇒ Object
- .remote_commits ⇒ Object
- .remote_log ⇒ Object
- .remote_url ⇒ Object
- .reset_hard ⇒ Object
- .reset_hard_and_pull ⇒ Object
- .return_to_branch(branch) ⇒ Object
- .up_to_date? ⇒ Boolean
Class Method Details
.actual_branch ⇒ Object
33 |
# File 'lib/mutx/support/git.rb', line 33 def self.actual_branch; self.branch; end |
.add_all ⇒ Object
44 45 46 |
# File 'lib/mutx/support/git.rb', line 44 def self.add_all Mutx::Support::Console.execute("git add .") end |
.add_commit(msg = nil) ⇒ Object
39 40 41 42 |
# File 'lib/mutx/support/git.rb', line 39 def self.add_commit msg=nil self.add_all self.commit msg end |
.add_file(filename) ⇒ Object
48 49 50 |
# File 'lib/mutx/support/git.rb', line 48 def self.add_file filename Mutx::Support::Console.execute("git add #{filename}") end |
.branch ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/mutx/support/git.rb', line 24 def self.branch branch_name = self.branches.select{|branch| branch.include? "*"}.first if branch_name.respond_to? :gsub branch_name.gsub("*","").gsub(" ","") unless branch_name.nil? else branch_name end end |
.branch_list ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/mutx/support/git.rb', line 8 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 |
.branches ⇒ Object
35 36 37 |
# File 'lib/mutx/support/git.rb', line 35 def self.branches Mutx::Support::Console.execute("git branch").split("\n") end |
.changed_files_on_last_commit ⇒ Array
Returns an Array of changed files on last commit
172 173 174 175 |
# File 'lib/mutx/support/git.rb', line 172 def self.changed_files_on_last_commit res = Mutx::Support::Console.execute("git diff-tree --no-commit-id --name-only -r #{self.get_last_commit_id}") res.split(" ") end |
.checkout_and_pull_from(branch_name = nil) ⇒ Object
106 107 108 109 110 |
# File 'lib/mutx/support/git.rb', line 106 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
102 103 104 |
# File 'lib/mutx/support/git.rb', line 102 def self.checkout_to branch Mutx::Support::Console.execute("git checkout #{branch}") unless self.actual_branch == branch end |
.commit(msg = nil) ⇒ Object
73 74 75 76 77 |
# File 'lib/mutx/support/git.rb', line 73 def self.commit msg = nil # self.ensure_being_at_mutx_branch msg = "MuTX COMMIT #{Time.new.strftime('%d %m %Y %H:%M:%S')}" if msg.nil? Mutx::Support::Console.execute"git commit -m '#{msg}'" end |
.commits ⇒ Object
131 132 133 134 |
# File 'lib/mutx/support/git.rb', line 131 def self.commits log = self.log log.split("commit")[1..-1] end |
.commits_ids ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'lib/mutx/support/git.rb', line 122 def self.commits_ids log = self.log log.split('\n').select do |line| self.is_commit_id? line end.map do |line| line.split(" ")[1] end end |
.create_branch_and_checkout(branch) ⇒ Object
79 80 81 |
# File 'lib/mutx/support/git.rb', line 79 def self.create_branch_and_checkout branch Mutx::Support::Console.execute("git checkout -b #{branch}") end |
.delete_branch(branch) ⇒ Object
83 84 85 86 |
# File 'lib/mutx/support/git.rb', line 83 def self.delete_branch branch checkout_to "master" Mutx::Support::Console.execute("git branch -D #{branch}") end |
.fetch ⇒ Object
20 21 22 |
# File 'lib/mutx/support/git.rb', line 20 def self.fetch Mutx::Support::Console.execute("git fetch") end |
.get_actual_lines ⇒ Object
Returns an Array with the existing files on .gitignore
191 192 193 194 195 196 197 198 |
# File 'lib/mutx/support/git.rb', line 191 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_id ⇒ String
Returns las commit id. This method is used by Execution class to verify changes before each execution
116 117 118 119 120 |
# File 'lib/mutx/support/git.rb', line 116 def self.get_last_commit_id self.commits_ids.map do |commit| commit.gsub("commit ","") end.first end |
.git_push_origin_to(branch_name = nil) ⇒ Object
56 57 58 59 |
# File 'lib/mutx/support/git.rb', line 56 def self.git_push_origin_to branch_name=nil branch_name = self.branch if branch_name.nil? Mutx::Support::Console.execute("git push origin #{branch_name}") end |
.is_commit_id?(line) ⇒ Boolean
136 137 138 |
# File 'lib/mutx/support/git.rb', line 136 def self.is_commit_id? line line.start_with? "commit " end |
.is_there_commit_id_diff?(obtained_commit) ⇒ Bool
Returns true if the obtained commit is different from the last saved commit
179 180 181 |
# File 'lib/mutx/support/git.rb', line 179 def self.is_there_commit_id_diff? obtained_commit obtained_commit != self.get_last_commit_id end |
.last_commit ⇒ Object
166 167 168 |
# File 'lib/mutx/support/git.rb', line 166 def self.last_commit self.commits.first end |
.last_remote_commit ⇒ Object
140 141 142 143 |
# File 'lib/mutx/support/git.rb', line 140 def self.last_remote_commit remotes = self.remote_commits remotes.first if remotes.respond_to? :first end |
.log ⇒ Object
158 159 160 |
# File 'lib/mutx/support/git.rb', line 158 def self.log res = Mutx::Support::Console.execute "git log" end |
.log_last_commit ⇒ Object
162 163 164 |
# File 'lib/mutx/support/git.rb', line 162 def self.log_last_commit "Commit: #{self.commits.first}" end |
.pull ⇒ Object
Performs pull from actual branc
89 90 91 |
# File 'lib/mutx/support/git.rb', line 89 def self.pull self.pull_from(self.actual_branch) end |
.pull_from(branch_name = nil) ⇒ Object
93 94 95 96 |
# File 'lib/mutx/support/git.rb', line 93 def self.pull_from(branch_name=nil) branch_name = self.branch if branch_name.nil? Mutx::Support::Console.execute("git pull origin #{branch_name}") end |
.push ⇒ Object
52 53 54 |
# File 'lib/mutx/support/git.rb', line 52 def self.push Mutx::Support::Console.execute("git push") end |
.push_origin_to_actual_branch ⇒ Object
69 70 71 |
# File 'lib/mutx/support/git.rb', line 69 def self.push_origin_to_actual_branch git_push_origin_to(self.actual_branch) end |
.remote_branches ⇒ Object
16 17 18 |
# File 'lib/mutx/support/git.rb', line 16 def self.remote_branches Mutx::Support::Console.execute("git branch -r").split("\n") end |
.remote_commits ⇒ Object
149 150 151 |
# File 'lib/mutx/support/git.rb', line 149 def self.remote_commits self.remote_log.split("commit")[1..-1] end |
.remote_log ⇒ Object
153 154 155 156 |
# File 'lib/mutx/support/git.rb', line 153 def self.remote_log self.fetch Mutx::Support::Console.execute "git log origin/#{self.actual_branch}" end |
.remote_url ⇒ Object
184 185 186 187 |
# File 'lib/mutx/support/git.rb', line 184 def self.remote_url res = Mutx::Support::Console.execute("git config --get remote.origin.url").split("\n").first.gsub(":","/").gsub("git@", 'http://').chop res[0..-5] if res.end_with? ".git" end |
.reset_hard ⇒ Object
61 62 63 |
# File 'lib/mutx/support/git.rb', line 61 def self.reset_hard Mutx::Support::Console.execute("git reset --hard") end |
.reset_hard_and_pull ⇒ Object
65 66 67 |
# File 'lib/mutx/support/git.rb', line 65 def self.reset_hard_and_pull self.reset_hard and self.pull end |
.return_to_branch(branch) ⇒ Object
98 99 100 |
# File 'lib/mutx/support/git.rb', line 98 def self.return_to_branch branch self.checkout_to branch end |
.up_to_date? ⇒ Boolean
145 146 147 |
# File 'lib/mutx/support/git.rb', line 145 def self.up_to_date? self.get_last_commit_id == self.last_remote_commit end |