Class: Brut::CLI::Apps::Deploy::GitChecks
- Inherits:
-
Object
- Object
- Brut::CLI::Apps::Deploy::GitChecks
- Defined in:
- lib/brut/cli/apps/deploy/git_checks.rb
Defined Under Namespace
Classes: Results
Instance Method Summary collapse
- #check! ⇒ Object
-
#initialize(executor:) ⇒ GitChecks
constructor
A new instance of GitChecks.
Constructor Details
#initialize(executor:) ⇒ GitChecks
Returns a new instance of GitChecks.
2 3 4 |
# File 'lib/brut/cli/apps/deploy/git_checks.rb', line 2 def initialize(executor:) @executor = executor end |
Instance Method Details
#check! ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 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/brut/cli/apps/deploy/git_checks.rb', line 12 def check! branch = "" @executor.system!("git branch --show-current") do |output| branch << output end branch = branch.strip.chomp if branch != "main" return Results.new("main-branch" => "You are on branch '#{branch}', but should be on branch 'main'") end @executor.system!("git status") do |*| # reset local caches to account for Docker/host wierdness # ignore end local_changes = "" @executor.system!("git diff-index --name-only HEAD --") do |output| local_changes << output end if local_changes.strip != "" return Results.new("local-changes" => "The following files have not been checked in: #{local_changes}") end rev_list = "" @executor.system!("git rev-list --left-right --count origin/main...main") do |output| rev_list << output end remote_ahead, local_ahead = rev_list.strip.chomp.split(/\t/,2).map(&:to_i) if remote_ahead != 0 if remote_ahead == 1 return Results.new("remote-ahead" => "There is 1 commit in origin you don't have") else return Results.new("remote-ahead" => "There are #{remote_ahead} commits in origin you don't have") end end if local_ahead != 0 if local_ahead == 1 return Results.new("remote-behind" => "There is 1 commit not pushed to origin") else return Results.new("remote-behind" => "There are #{local_ahead} commits not pushed to origin") end end Results.new end |