Class: RakeCommit::Commit

Inherits:
Object
  • Object
show all
Defined in:
lib/rake_commit/commit.rb

Instance Method Summary collapse

Instance Method Details

#commitObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rake_commit/commit.rb', line 17

def commit
  options = {
    :collapse_commits => true,
    :incremental => false,
    :prompt_exclusions => []
  }

  if File.exists?(".rake_commit")
    defaults = File.read(".rake_commit")
    options = parse_options(Shellwords.split(defaults), options)
  end
  options = parse_options(ARGV, options)

  if git_svn?
    RakeCommit::GitSvn.new(options[:prompt_exclusions]).commit
  elsif git?
    RakeCommit::Git.new(options[:collapse_commits], options[:incremental], options[:prompt_exclusions], options[:precommit]).commit
  else
    RakeCommit::Svn.new(options[:prompt_exclusions]).commit
  end
end

#git?Boolean

Returns:



7
8
9
10
# File 'lib/rake_commit/commit.rb', line 7

def git?
  `git rev-parse`
  $?.success?
end

#git_svn?Boolean

Returns:



12
13
14
15
# File 'lib/rake_commit/commit.rb', line 12

def git_svn?
  `git svn info 2> /dev/null`
  $?.success?
end

#parse_options(args, options) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rake_commit/commit.rb', line 39

def parse_options(args, options)
  parser = OptionParser.new do |opts|
    opts.banner = "Usage: rake_commit [OPTIONS]"
    opts.on("-h", "--help", "Show this message") do
      puts opts
      exit
    end
    opts.on("-i", "--incremental", "Prompt for a local commit") do
      options[:incremental] = true
    end
    opts.on("-n", "--no-collapse", "Run the build and push without collapsing commits") do
      options[:collapse_commits] = false
    end
    opts.on("-w", "--without-prompt PROMPT", "Skips the given prompt (author, feature, message)") do |prompt_exclusion|
      options[:prompt_exclusions] << prompt_exclusion
    end
    opts.on("-p", "--precommit SCRIPT", "command to run before commiting changes") do |command|
      options[:precommit] = command
    end
  end

  parser.parse(args)
  options
end