class GitSquash

Constants

VERSION

Attributes

argv[RW]

Public Instance Methods

run(argv) click to toggle source
# File lib/git-squash.rb, line 8
def run(argv)
  @argv = argv
  reset_command
  add_command
  commit_command
  push_force_command
end

Private Instance Methods

add_command() click to toggle source
# File lib/git-squash.rb, line 32
def add_command
  puts "Executing add command".green
  puts "git add .".yellow
  puts
  %x(git add .)
end
commit_command() click to toggle source
# File lib/git-squash.rb, line 25
def commit_command
  puts "Executing commit command".green
  puts "git commit -S -am #{ message }".yellow
  puts
  %x(git commit -S -am "#{ message }")
end
commit_id() click to toggle source
# File lib/git-squash.rb, line 45
def commit_id
  %x(git merge-base HEAD #{ from_branch })
end
current_branch() click to toggle source
# File lib/git-squash.rb, line 49
def current_branch
  @current_branch ||= repo.head.name
end
from_branch() click to toggle source
# File lib/git-squash.rb, line 57
def from_branch
  @argv[1] || 'master'
end
get_repo() click to toggle source
# File lib/git-squash.rb, line 65
def get_repo
  repo_dir = `git rev-parse --show-toplevel`.chomp
  begin
    @repo = Grit::Repo.new(repo_dir)
  rescue
    raise "We don't seem to be in a git repository."
  end
end
message() click to toggle source
# File lib/git-squash.rb, line 61
def message
  @argv[0] || 'no commit message'
end
push_force_command() click to toggle source
# File lib/git-squash.rb, line 18
def push_force_command
  puts "Executing push command".green
  puts "git push origin -f #{ current_branch }".yellow
  puts
  %x(git push origin -f #{ current_branch })
end
repo() click to toggle source
# File lib/git-squash.rb, line 53
def repo
  @repo ||= get_repo
end
reset_command() click to toggle source
# File lib/git-squash.rb, line 39
def reset_command
  puts "Executing reset command from: #{ from_branch }".green
  puts "git reset --soft #{ commit_id }".yellow
  %x(git reset --soft #{ commit_id })
end