rake_commit 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ea1f63f9545e05c6ac0a8ea9da6c7bc97748667
4
- data.tar.gz: 7850c7d442419a515964e4e47cbcff9f64d85cbc
3
+ metadata.gz: dab391ea20c75c033c4428c8cc93c3a46925831b
4
+ data.tar.gz: d33a3fa4b68229d9382b9a0660e0a9707eedc369
5
5
  SHA512:
6
- metadata.gz: c5241e7795d91d35c00ed80c63bc78e96682c4be76fc7944d00f641e4da72a1af2ffe1147b23b2f1713fe8e64239e12d0c641906ca6527ecebc4eb1d08521cef
7
- data.tar.gz: 910b3d3d580b38e8f13f4287d1dac46ff04e1b91f97521ebd41c0200cdebb9d26fb9f4261324f1bc42df26c15e6fccfb6f055ea3fcc1ba50ba0279df96855de8
6
+ metadata.gz: 6cb506b14ed438f93e4a9fe3968555006be3f7bf5768e6a64f276c4d6cda0559cd37fde3cbac3933b6ddd2357a46c799b917eb7e3ae27a43dd57f644c505a99f
7
+ data.tar.gz: cfa603c49218a9c05cc4e87f711df28c9404465bb3461709d6d23588e2d421343857f7a8b4d356b130250f0f82b2a1bc55b3e26a126ce5271adf3163b4fcd7bd
@@ -19,7 +19,9 @@ module RakeCommit
19
19
  :collapse_commits => true,
20
20
  :incremental => false,
21
21
  :prompt_exclusions => [],
22
- :build_command => "rake"
22
+ :build_command => "rake",
23
+ :commit_message_wrap => nil, # integer or nil
24
+ :commit_message_type => CommitMessage::MessageType::MESSAGE
23
25
  }
24
26
 
25
27
  if File.exists?(".rake_commit")
@@ -31,7 +33,7 @@ module RakeCommit
31
33
  if git_svn?
32
34
  RakeCommit::GitSvn.new(options[:prompt_exclusions]).commit
33
35
  elsif git?
34
- RakeCommit::Git.new(options[:build_command], options[:collapse_commits], options[:rebase_only], options[:incremental], options[:prompt_exclusions], options[:precommit]).commit
36
+ RakeCommit::Git.new(options[:build_command], options[:collapse_commits], options[:rebase_only], options[:incremental], options[:prompt_exclusions], options[:precommit], options[:commit_message_wrap], options[:commit_message_type]).commit
35
37
  else
36
38
  RakeCommit::Svn.new(options[:prompt_exclusions]).commit
37
39
  end
@@ -63,6 +65,12 @@ module RakeCommit
63
65
  opts.on("-b", "--build-command SCRIPT", "the command that verifies the commit, defaults to rake") do |command|
64
66
  options[:build_command] = command
65
67
  end
68
+ opts.on("--word-wrap [80]", "word wrap the commit message (default no wrap)") do |commit_message_wrap|
69
+ options[:commit_message_wrap] = commit_message_wrap.to_i
70
+ end
71
+ opts.on("-m", "--message-type [MESSAGE|WHATWHY]", "the type of commit message to prompt for (only works on Git)") do |commit_message_type|
72
+ options[:commit_message_type] = commit_message_type.downcase
73
+ end
66
74
  end
67
75
 
68
76
  parser.parse(args)
@@ -1,16 +1,60 @@
1
+ require 'word_wrap'
2
+
1
3
  module RakeCommit
2
4
  class CommitMessage
5
+ module MessageType
6
+ MESSAGE = "message"
7
+ WHAT_AND_WHY = "whatwhy"
8
+ end
9
+
10
+ SUBJECT_MAX_LENGTH = 50
3
11
 
4
12
  attr_reader :author, :feature, :message
5
13
 
6
- def initialize(prompt_exclusions = [])
14
+ def initialize(prompt_exclusions = [], type = MessageType::MESSAGE)
7
15
  @author = RakeCommit::PromptLine.new("author", prompt_exclusions).prompt
8
16
  @feature = RakeCommit::PromptLine.new("feature", prompt_exclusions).prompt
9
- @message = RakeCommit::PromptLine.new("message", prompt_exclusions).prompt
17
+ @message = case type
18
+ when MessageType::MESSAGE
19
+ RakeCommit::PromptLine.new("message", prompt_exclusions).prompt
20
+ when MessageType::WHAT_AND_WHY
21
+ what = RakeCommit::PromptLine.new("what", prompt_exclusions).prompt
22
+ why = RakeCommit::PromptLine.new("why", prompt_exclusions).prompt
23
+
24
+ subject_space_remaining = SUBJECT_MAX_LENGTH - @feature.length
25
+ truncated_what = what[0...subject_space_remaining]
26
+ subject = RakeCommit::PromptLine.new("subject", prompt_exclusions, truncated_what).prompt
27
+
28
+ create_message_with_subject_what_and_why(subject, what, why)
29
+ end
30
+ end
31
+
32
+ def joined_message(wrap = nil)
33
+ message = [@feature, @message].compact.join(' - ')
34
+ message = WordWrap.ww(message, wrap) if wrap
35
+ message
36
+ end
37
+
38
+ def joined_message_with_author(wrap = nil)
39
+ message = [@author, @feature, @message].compact.join(' - ')
40
+ message = WordWrap.ww(message, wrap) if wrap
41
+ message
10
42
  end
11
43
 
12
- def joined_message
13
- [@author, @feature, @message].compact.join(' - ')
44
+ private
45
+
46
+ def create_message_with_subject_what_and_why(subject, what, why)
47
+ <<-EOS
48
+ #{subject}
49
+
50
+ What
51
+ ===
52
+ #{what}
53
+
54
+ Why
55
+ ===
56
+ #{why}
57
+ EOS
14
58
  end
15
59
  end
16
60
  end
@@ -3,13 +3,15 @@ require 'shellwords'
3
3
  module RakeCommit
4
4
  class Git
5
5
 
6
- def initialize(build_command, collapse_commits = true, rebase_only = false, incremental = false, prompt_exclusions = [], precommit = nil)
6
+ def initialize(build_command, collapse_commits = true, rebase_only = false, incremental = false, prompt_exclusions = [], precommit = nil, commit_message_wrap = nil, commit_message_type = MessageType::MESSAGE)
7
7
  @build_command = build_command
8
8
  @collapse_commits = collapse_commits
9
9
  @rebase_only = rebase_only
10
10
  @incremental = incremental
11
11
  @prompt_exclusions = prompt_exclusions
12
12
  @precommit = precommit
13
+ @commit_message_wrap = commit_message_wrap
14
+ @commit_message_type = commit_message_type
13
15
  end
14
16
 
15
17
  def commit
@@ -23,8 +25,10 @@ module RakeCommit
23
25
  if collapse_git_commits?
24
26
  return unless collapse_git_commits
25
27
  elsif rebase_only?
26
- add
27
- incremental_commit unless nothing_to_commit?
28
+ unless nothing_to_commit?
29
+ puts "You have uncommitted changes. Please amend, stash, or clean and retry."
30
+ exit 1
31
+ end
28
32
  pull_rebase rescue return false
29
33
  end
30
34
  RakeCommit::Shell.system(@build_command)
@@ -73,11 +77,11 @@ module RakeCommit
73
77
  end
74
78
 
75
79
  def incremental_commit
76
- commit_message = RakeCommit::CommitMessage.new(@prompt_exclusions)
80
+ commit_message = RakeCommit::CommitMessage.new(@prompt_exclusions, @commit_message_type)
77
81
  unless commit_message.author.nil?
78
82
  RakeCommit::Shell.system("git config user.name #{Shellwords.shellescape(commit_message.author)}")
79
83
  end
80
- message = [commit_message.feature, commit_message.message].compact.join(" - ")
84
+ message = commit_message.joined_message(@commit_message_wrap)
81
85
  RakeCommit::Shell.system("git commit -m #{Shellwords.shellescape(message)}")
82
86
  end
83
87
 
@@ -17,7 +17,7 @@ module RakeCommit
17
17
  end
18
18
 
19
19
  def git_svn_commit_with_message
20
- message = RakeCommit::CommitMessage.new(@prompt_exclusions).joined_message
20
+ message = RakeCommit::CommitMessage.new(@prompt_exclusions).joined_message_with_author
21
21
  RakeCommit::Shell.system "git commit -m #{message.inspect}"
22
22
  end
23
23
 
@@ -5,21 +5,29 @@ module RakeCommit
5
5
  class PromptLine
6
6
  include Readline
7
7
 
8
- def initialize(attribute, prompt_exclusions = [])
8
+ def initialize(attribute, prompt_exclusions = [], default_value = nil)
9
9
  @attribute = attribute
10
10
  @prompt_exclusions = prompt_exclusions
11
+ @default_value = default_value
11
12
  end
12
13
 
13
14
  def prompt
14
15
  return nil if @prompt_exclusions.include?(@attribute)
16
+
17
+ puts "\n"
18
+ puts "previous #{@attribute}: #{previous_input}" if previous_input
19
+
20
+ set_readline_default_input(@default_value) if @default_value
21
+ set_readline_history
22
+
15
23
  input = nil
16
24
  loop do
17
- input = readline(message).chomp
25
+ input = readline("#{@attribute}: ").chomp
18
26
  break unless (input.empty? && !previous_input)
19
27
  end
20
28
 
21
29
  unless input.empty?
22
- save_history(input)
30
+ append_history(input)
23
31
  return input
24
32
  end
25
33
 
@@ -27,18 +35,20 @@ module RakeCommit
27
35
  return previous_input
28
36
  end
29
37
 
30
- def message
31
- previous_message = "\n"
32
- previous_message += "previous #{@attribute}: #{previous_input}\n" if previous_input
33
- puts previous_message
34
- "#{@attribute}: "
35
- end
38
+ private
36
39
 
37
- def save_history(input)
40
+ def append_history(input)
38
41
  File.open(history_file, "a") { |f| f.puts(input) }
39
42
  end
40
43
 
41
- private
44
+ def set_readline_default_input(default_input)
45
+ Readline.pre_input_hook = lambda do
46
+ Readline.insert_text(default_input)
47
+ Readline.redisplay
48
+ Readline.pre_input_hook = nil
49
+ end
50
+ end
51
+
42
52
  def previous_input
43
53
  @previous_input ||= history.last
44
54
  end
@@ -47,13 +57,12 @@ module RakeCommit
47
57
  @history ||= load_history
48
58
  end
49
59
 
50
- def load_history
60
+ def set_readline_history
51
61
  HISTORY.pop until HISTORY.empty?
52
- HISTORY.push(*saved_history)
53
- HISTORY.to_a
62
+ HISTORY.push(*history)
54
63
  end
55
64
 
56
- def saved_history
65
+ def load_history
57
66
  File.exists?(history_file) ? File.read(history_file).split("\n") : []
58
67
  end
59
68
 
@@ -10,7 +10,7 @@ module RakeCommit
10
10
 
11
11
  def commit
12
12
  if files_to_check_in?
13
- message = RakeCommit::CommitMessage.new(@prompt_exclusions).joined_message
13
+ message = RakeCommit::CommitMessage.new(@prompt_exclusions).joined_message_with_author
14
14
  RakeCommit::Shell.system(@precommit) unless @precommit.nil?
15
15
  add
16
16
  delete
metadata CHANGED
@@ -1,15 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rake_commit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Gross
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-18 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2016-04-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.2.2
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '11'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.9.2.2
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '11'
33
+ - !ruby/object:Gem::Dependency
34
+ name: word_wrap
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: mocha
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.9.12
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '='
59
+ - !ruby/object:Gem::Version
60
+ version: 0.9.12
61
+ - !ruby/object:Gem::Dependency
62
+ name: test-unit
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.1'
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 3.1.5
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '3.1'
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 3.1.5
13
81
  description: See http://github.com/pgr0ss/rake_commit
14
82
  email: pgross@gmail.com
15
83
  executables:
@@ -39,17 +107,17 @@ require_paths:
39
107
  - lib
40
108
  required_ruby_version: !ruby/object:Gem::Requirement
41
109
  requirements:
42
- - - '>='
110
+ - - ">="
43
111
  - !ruby/object:Gem::Version
44
112
  version: '0'
45
113
  required_rubygems_version: !ruby/object:Gem::Requirement
46
114
  requirements:
47
- - - '>='
115
+ - - ">="
48
116
  - !ruby/object:Gem::Version
49
117
  version: '0'
50
118
  requirements: []
51
119
  rubyforge_project: rake_commit
52
- rubygems_version: 2.4.6
120
+ rubygems_version: 2.4.5.1
53
121
  signing_key:
54
122
  specification_version: 4
55
123
  summary: A gem which helps with checking in code