Module: ElocalCapistrano::GitTools

Defined in:
lib/elocal_capistrano/git_tools.rb

Defined Under Namespace

Classes: ReleaseTag

Instance Method Summary collapse

Instance Method Details

#increment_patch_versionObject



74
75
76
77
78
# File 'lib/elocal_capistrano/git_tools.rb', line 74

def increment_patch_version
  tag = ReleaseTag.latest
  tag.patch += 1
  tag
end

#no_changes_pending?Boolean

Test whether there are any uncommitted changes in the working directory.

Returns:

  • (Boolean)


70
71
72
# File 'lib/elocal_capistrano/git_tools.rb', line 70

def no_changes_pending?
  %x(git status --porcelain).split("\n").length == 0
end

#on_master?Boolean

Test whether we are currently using the master branch. All deployment activity should take place on the master branch.

Returns:

  • (Boolean)


63
64
65
66
# File 'lib/elocal_capistrano/git_tools.rb', line 63

def on_master?
  out = %x(git symbolic-ref -q HEAD)
  out.strip == "refs/heads/master"
end

#update_versions_file(tag) ⇒ Object



88
89
90
# File 'lib/elocal_capistrano/git_tools.rb', line 88

def update_versions_file(tag)
  File.write(fetch(:versions_path), versions_hash.merge(fetch(:stage).to_s => tag.to_s).to_yaml.to_s)
end

#versions_hashObject



80
81
82
83
84
85
86
# File 'lib/elocal_capistrano/git_tools.rb', line 80

def versions_hash
  if File.file?(fetch(:versions_path))
    YAML.load_file(fetch(:versions_path))
  else
    {}
  end
end

#working_directory_copasetic?(options = {}) ⇒ Boolean

A short user prompt if there are uncommitted changes in the repo, in case the user forgets before they deploy. Naturally, one may cancel this process effectively cancelling the entire deploy cleanly. This occurs before any hard changes (e.g., writing changes, pushes, command execution, etc.) are made.

Returns:

  • (Boolean)


54
55
56
57
58
59
# File 'lib/elocal_capistrano/git_tools.rb', line 54

def working_directory_copasetic?(options={})
  return true if options[:force]
  return false unless no_changes_pending? || yes?('There are currently uncommitted changes.  Are you sure you want to continue?')
  return false unless on_master? || yes?('You are not currently on the master branch.  Are you sure you want to continue?')
  true
end

#yes?(prompt_msg) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
95
# File 'lib/elocal_capistrano/git_tools.rb', line 92

def yes?(prompt_msg)
  ask(:proceed, prompt_msg + ' [y/N]', default: 'y')
  fetch(:proceed) == 'y'
end