Module: BbDeploy::Git

Defined in:
lib/bb_deploy/git.rb

Class Method Summary collapse

Class Method Details

.check_git_status!Object

rubocop:disable Metrics/CyclomaticComplexity



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/bb_deploy/git.rb', line 34

def check_git_status! # rubocop:disable Metrics/CyclomaticComplexity
  puts "Running `git fetch` ... "
  quietly { `git fetch` }
  if `git log ..origin/#{current_branch}`.present?
    exit(0) unless BbDeploy::Task.ask("There are new commits on the remote branch 'origin/#{current_branch}'. Are you sure you want to proceed?")
  end
  status_msg_a = `git status`.split(/(?:\n+)/)
  if status_msg_a[1] =~ /your.branch.is.ahead/i
    exit(0) unless BbDeploy::Task.ask("You have local, committed changes that have not been pushed to the remote.  Are you sure you want to proceed?")
  end
  unless status_msg_a.last =~ /nothing to commit/i
    exit(0) unless BbDeploy::Task.ask("You have local, uncommitted changes.  Are you sure you want to proceed?")
  end
end

.current_branch(reload = false) ⇒ Object

NOTE - THE DEFAULT AUTO-MEMOIZATION CAN CAUSE ISSUES IF YOU FORGET IT’S HAPPENING, SO NOTE THAT IT OCCURS!!!



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/bb_deploy/git.rb', line 6

def current_branch(reload = false)
  if reload || !@current_branch
    # I don't know sed at all, hence I don't know which backslashes need to be doubled and which don't :(
    cmd = 'git branch 2> /dev/null | sed -e \'/^[^*]/d\' -e \'s/* \(.*\)/\1/\''
    result = `#{cmd}`
    raise "Unable to determine the current branch name" if result.blank?
    @current_branch = result.strip
  else
    @current_branch
  end
end

.local_release(branch_name) ⇒ Object



53
54
55
# File 'lib/bb_deploy/git.rb', line 53

def local_release(branch_name)
  `git branch --list "#{branch_name}"`
end

.migrations_present?(sha) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/bb_deploy/git.rb', line 49

def migrations_present?(sha)
  `git diff #{sha} db/migrate`.present?
end

.on_a_release_branch?Boolean

Returns:

  • (Boolean)


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

def on_a_release_branch?
  current_branch.start_with?('release_')
end

.on_master?Boolean

Returns:

  • (Boolean)


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

def on_master?
  current_branch == 'master'
end

.push_release_branch!Object



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

def push_release_branch!
  puts `git checkout -lb #{new_branch} && git push origin #{new_branch} -u`
end

.push_to_phase(phase) ⇒ Object



18
19
20
# File 'lib/bb_deploy/git.rb', line 18

def push_to_phase(phase)
  `git push #{phase} HEAD:master --force`
end

.remote_release(branch_name) ⇒ Object



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

def remote_release(branch_name)
  `git branch -r --list "origin/#{branch_name}"`
end