Class: Maximus::GitControl
- Inherits:
-
Object
- Object
- Maximus::GitControl
- Defined in:
- lib/maximus/git_control.rb
Overview
Git management
Instance Method Summary collapse
-
#associations ⇒ Hash
Define associations to linters based on file extension.
-
#commit_export(commit_sha = head_sha) ⇒ Hash
30,000 foot view of a commit.
-
#compare(sha1 = master_commit_sha, sha2 = head_sha) ⇒ Hash
Compare two commits and get line number ranges of changed patches.
-
#initialize(opts = {}) ⇒ GitControl
constructor
Set up instance variables.
-
#lints_and_stats(lint_by_path = false, git_shas = compare, nuclear = false) ⇒ Hash
Run appropriate lint for every sha in commit history.
Methods included from GitHelper
#branch, #commit_information, #files_by_sha, #first_commit, #head_sha, #lines_by_sha, #master_commit_sha, #previous_commit, #remote, #sha_range, #working_copy_files
Methods included from Helper
#discover_path, #edit_yaml, #file_count, #file_list, #is_middleman?, #is_rails?, #node_module_exists, #path_exists?, #prompt, #reporter_path, #root_dir, #truthy?
Constructor Details
#initialize(opts = {}) ⇒ GitControl
Set up instance variables
Inherits settings from Config#initialize
18 19 20 21 22 23 24 25 26 |
# File 'lib/maximus/git_control.rb', line 18 def initialize(opts = {}) opts[:config] ||= Maximus::Config.new({ commit: opts[:commit] }) @config = opts[:config] @settings = @config.settings @psuedo_commit = ( !@settings[:commit].blank? && %w(working last master).include?(@settings[:commit]) ) @g = Git.open(@config.working_dir) end |
Instance Method Details
#associations ⇒ Hash
Define associations to linters based on file extension
145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/maximus/git_control.rb', line 145 def associations { css: ['css'], scss: ['scss', 'sass'], js: ['js'], ruby: ['rb', 'Gemfile', 'lock', 'yml', 'Rakefile', 'ru', 'rdoc', 'rake', 'Capfile', 'jbuilder'], rails: ['slim', 'haml', 'jbuilder', 'erb'], images: ['png', 'jpg', 'jpeg', 'gif'], static: ['pdf', 'txt', 'doc', 'docx', 'csv', 'xls', 'xlsx'], markup: ['html', 'xml', 'xhtml'], markdown: ['md', 'markdown', 'mdown'], php: ['php', 'ini'] } end |
#commit_export(commit_sha = head_sha) ⇒ Hash
30,000 foot view of a commit
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/maximus/git_control.rb', line 31 def commit_export(commit_sha = head_sha) commit_sha = commit_sha.to_s ce_commit = @g.gcommit(commit_sha) if first_commit == commit_sha ce_diff = diff_initial(first_commit) else last_commit = @g.gcommit(previous_commit(commit_sha)) ce_diff = diff(last_commit, ce_commit) end { commit_sha: commit_sha, branch: branch, message: ce_commit., remote_repo: remote, git_author: ce_commit..name, git_author_email: ce_commit..email, commit_date: ce_commit..date.to_s, diff: ce_diff } end |
#compare(sha1 = master_commit_sha, sha2 = head_sha) ⇒ Hash
Compare two commits and get line number ranges of changed patches
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/maximus/git_control.rb', line 72 def compare(sha1 = master_commit_sha, sha2 = head_sha) diff_return = {} sha1 = define_psuedo_commit if @settings[:commit] # Reverse so that we go in chronological order git_spread = commit_range(sha1, sha2).reverse git_spread.each do |git_sha| # Grab all files in that commit and group them by extension # If working copy, just give the diff names of the files changed files = @psuedo_commit ? working_copy_files : files_by_sha(git_sha) diff_return[git_sha] = match_associations(git_sha, files) end diff_return end |
#lints_and_stats(lint_by_path = false, git_shas = compare, nuclear = false) ⇒ Hash
Run appropriate lint for every sha in commit history. For each sha a new branch is created then deleted
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/maximus/git_control.rb', line 114 def lints_and_stats(lint_by_path = false, git_shas = compare, nuclear = false) return false if git_shas.blank? base_branch = branch git_ouput = {} git_shas.each do |sha, exts| create_branch(sha) unless @psuedo_commit sha = sha.to_s puts sha.color(:blue) exts.each do |ext, files| # For relevant_lines data lint_opts = { git_files: files, config: @config, file_paths: (lint_file_paths(files, ext) if lint_by_path) } git_ouput[sha] = nuclear ? lints_and_stats_nuclear(lint_opts) : lints_and_stats_switch(ext, lint_opts) end destroy_branch(base_branch, sha) unless @psuedo_commit end git_ouput end |