rake_commit 0.14.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dde978cb78d5edf140a4bf1ff0e21e57ab0f2095
4
+ data.tar.gz: 7bfd75289e088c36682f8c5d5b05cdd0c5dd3c7d
5
+ SHA512:
6
+ metadata.gz: c4752cf9d414aeb1720927e4ae0d74f0e05639764809eea8d7bf85523d462222612f1bfacff4eca473511b196d478c109dbf34df4f0ed60021dd38ca5fb0630f
7
+ data.tar.gz: da5e2bb5ecddf53a4290e5597d869de7112fe9dc417dead2e95f0387dd17a91df8ece66ca12e905394b7ffa11543eae48524f8ce03ab84f07a71cb40273620b0
@@ -1,11 +1,13 @@
1
- = rake_commit
1
+ # rake_commit
2
2
 
3
- {<img src="http://travis-ci.org/pgr0ss/rake_commit.png" />}[http://travis-ci.org/pgr0ss/rake_commit]
3
+ [![Gem Version](https://badge.fury.io/rb/rake_commit.png)](http://badge.fury.io/rb/rake_commit)
4
+ [![Build Status](https://travis-ci.org/pgr0ss/rake_commit.png?branch=master)](https://travis-ci.org/pgr0ss/rake_commit)
4
5
 
5
6
  This gem automates a pretty standard workflow when committing code to git, svn, and git-svn. Run rake_commit in your current project, which does the following, depending on source control:
6
7
 
7
- ==== git
8
+ ### git
8
9
 
10
+ ```
9
11
  1. Checks in current changes into a temp commit just in case
10
12
  2. Resets soft back to origin/branch (in order to collapse changes into one commit)
11
13
  3. Adds new files to git and removes deleted files
@@ -14,52 +16,82 @@ This gem automates a pretty standard workflow when committing code to git, svn,
14
16
  6. Pulls changes from origin (and does a rebase to keep a linear history)
15
17
  7. Runs the default rake task (which should run the tests)
16
18
  8. Pushes the commit to origin
19
+ ```
17
20
 
18
- ==== git-svn
21
+ ### git-svn
19
22
 
23
+ ```
20
24
  1. Adds new files to git and removes deleted files
21
25
  2. Prompts for a commit message
22
26
  3. Commits to local git
23
27
  4. Pulls changes from SVN
24
28
  5. Runs the default rake task (which should run the tests)
25
29
  6. Pushes the commit to SVN
30
+ ```
26
31
 
27
- ==== subversion
32
+ ### subversion
28
33
 
34
+ ```
29
35
  1. Prompts for a commit message
30
36
  2. Adds new files to subversion
31
37
  3. Deletes missing files from subversion
32
38
  4. svn update
33
39
  5. Runs the default rake task (which should run the tests)
34
40
  6. Checks in the code
41
+ ```
35
42
 
36
43
 
37
44
  The first version started with the code posted at Jay Field's Blog: http://blog.jayfields.com/2006/12/ruby-rake-commit.html.
38
45
  Improvements have been added in from several more projects.
39
46
 
40
- == Installation
47
+ ## Installation
41
48
 
42
- gem install rake_commit
49
+ ```bash
50
+ gem install rake_commit
51
+ ```
43
52
 
44
- == Usage
53
+ ## Usage
45
54
 
46
- cd /path/to/project
47
- rake_commit
55
+ ```bash
56
+ cd /path/to/project
57
+ rake_commit
58
+ ```
48
59
 
49
- === Command line arguments
60
+ ### Command line arguments
50
61
 
51
- --help
62
+ ```bash
63
+ --help
64
+ ```
52
65
 
53
66
  Print help information.
54
67
 
55
- --incremental
68
+ ```bash
69
+ --incremental
70
+ ```
56
71
 
57
72
  This will prompt as normal and then commit without running tests or pushing. This is useful for make incremental commits while working.
58
73
 
59
- --no-collapse
74
+ ```bash
75
+ --no-collapse
76
+ ```
60
77
 
61
78
  This tells rake_commit not to prompt and make a new commit. This is useful when you've done a merge by hand and want to preserve the commit. It will stil run rake and then push if rake succeeds.
62
79
 
63
- --without-prompt <prompt>
80
+ ```bash
81
+ --without-prompt <prompt>
82
+ ```
64
83
 
65
- This will cause rake_commit to skip the named prompt. For example, if you are working by yourself and do not need to prompt for a pair, you can use --without-prompt pair.
84
+ This will cause rake_commit to skip the named prompt. For example, if you are working by yourself and do not need to prompt for an author, you can use `--without-prompt author`.
85
+
86
+ ### Configuration
87
+
88
+ If the same command line arguments are always used, they can be added to a `.rake_commit` file in the root of the project. For example, this `.rake_commit` file will tell `rake_commit` to only prompt for message:
89
+
90
+ ```
91
+ --without-prompt author
92
+ --without-prompt feature
93
+ ```
94
+
95
+ ## License
96
+
97
+ rake_commit is released under the [MIT license](http://www.opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require "rake/testtask"
2
2
 
3
- task :default => :test
3
+ task :default => ['test', 'gem:build']
4
4
 
5
5
  Rake::TestTask.new do |t|
6
6
  t.pattern = "test/**/*_test.rb"
@@ -1,10 +1,11 @@
1
1
  require 'optparse'
2
2
  require 'rexml/document'
3
+ require 'shellwords'
3
4
 
4
5
  module RakeCommit
5
6
  class Commit
6
7
  def git?
7
- `git symbolic-ref HEAD 2>/dev/null`
8
+ `git rev-parse`
8
9
  $?.success?
9
10
  end
10
11
 
@@ -22,14 +23,14 @@ module RakeCommit
22
23
 
23
24
  if File.exists?(".rake_commit")
24
25
  defaults = File.read(".rake_commit")
25
- options = parse_options(defaults.split(" "), options)
26
+ options = parse_options(Shellwords.split(defaults), options)
26
27
  end
27
28
  options = parse_options(ARGV, options)
28
29
 
29
30
  if git_svn?
30
31
  RakeCommit::GitSvn.new(options[:prompt_exclusions]).commit
31
32
  elsif git?
32
- RakeCommit::Git.new(options[:collapse_commits], options[:incremental], options[:prompt_exclusions]).commit
33
+ RakeCommit::Git.new(options[:collapse_commits], options[:incremental], options[:prompt_exclusions], options[:precommit]).commit
33
34
  else
34
35
  RakeCommit::Svn.new(options[:prompt_exclusions]).commit
35
36
  end
@@ -51,10 +52,13 @@ module RakeCommit
51
52
  opts.on("-w", "--without-prompt PROMPT", "Skips the given prompt (author, feature, message)") do |prompt_exclusion|
52
53
  options[:prompt_exclusions] << prompt_exclusion
53
54
  end
55
+ opts.on("-p", "--precommit SCRIPT", "command to run before commiting changes") do |command|
56
+ options[:precommit] = command
57
+ end
54
58
  end
55
59
 
56
60
  parser.parse(args)
57
61
  options
58
62
  end
59
63
  end
60
- end
64
+ end
@@ -1,16 +1,16 @@
1
1
  module RakeCommit
2
2
  class CommitMessage
3
3
 
4
- attr_reader :pair, :feature, :message
4
+ attr_reader :author, :feature, :message
5
5
 
6
6
  def initialize(prompt_exclusions = [])
7
- @pair = RakeCommit::PromptLine.new("pair", prompt_exclusions).prompt
7
+ @author = RakeCommit::PromptLine.new("author", prompt_exclusions).prompt
8
8
  @feature = RakeCommit::PromptLine.new("feature", prompt_exclusions).prompt
9
9
  @message = RakeCommit::PromptLine.new("message", prompt_exclusions).prompt
10
10
  end
11
11
 
12
12
  def joined_message
13
- [@pair, @feature, @message].compact.join(' - ')
13
+ [@author, @feature, @message].compact.join(' - ')
14
14
  end
15
15
  end
16
- end
16
+ end
@@ -1,22 +1,32 @@
1
+ require 'shellwords'
2
+
1
3
  module RakeCommit
2
4
  class Git
3
5
 
4
- def initialize(collapse_commits = true, incremental = false, prompt_exclusions = [])
6
+ def initialize(collapse_commits = true, incremental = false, prompt_exclusions = [], precommit = nil)
5
7
  @collapse_commits = collapse_commits
6
8
  @incremental = incremental
7
9
  @prompt_exclusions = prompt_exclusions
10
+ @precommit = precommit
8
11
  end
9
12
 
10
13
  def commit
11
14
  if @incremental
12
15
  incremental_commit
13
- else
14
- collapse_git_commits if @collapse_commits && collapse_git_commits?
16
+ elsif rebase_in_progress?
17
+ rebase_continue
18
+ RakeCommit::Shell.system("rake")
19
+ push
20
+ elsif @collapse_commits && collapse_git_commits? && collapse_git_commits
15
21
  RakeCommit::Shell.system("rake")
16
22
  push
17
23
  end
18
24
  end
19
25
 
26
+ def rebase_in_progress?
27
+ File.directory?(".git/rebase-merge") || File.directory?(".git/rebase-apply")
28
+ end
29
+
20
30
  def collapse_git_commits?
21
31
  return true unless merge_commits?
22
32
  status
@@ -24,14 +34,20 @@ module RakeCommit
24
34
  input == "y"
25
35
  end
26
36
 
37
+ def rebase_continue
38
+ RakeCommit::Shell.system("git rebase --continue")
39
+ end
40
+
27
41
  def collapse_git_commits
42
+ RakeCommit::Shell.system(@precommit) unless @precommit.nil?
28
43
  add
29
44
  temp_commit
30
45
  reset_soft
31
46
  status
32
47
  return if nothing_to_commit?
33
48
  incremental_commit
34
- pull_rebase
49
+ pull_rebase rescue return false
50
+ return true
35
51
  end
36
52
 
37
53
  def status
@@ -44,11 +60,11 @@ module RakeCommit
44
60
 
45
61
  def incremental_commit
46
62
  commit_message = RakeCommit::CommitMessage.new(@prompt_exclusions)
47
- unless commit_message.pair.nil?
48
- RakeCommit::Shell.system("git config user.name #{commit_message.pair.inspect}")
63
+ unless commit_message.author.nil?
64
+ RakeCommit::Shell.system("git config user.name #{Shellwords.shellescape(commit_message.author)}")
49
65
  end
50
66
  message = [commit_message.feature, commit_message.message].compact.join(" - ")
51
- RakeCommit::Shell.system("git commit -m #{message.inspect}")
67
+ RakeCommit::Shell.system("git commit -m #{Shellwords.shellescape(message)}")
52
68
  end
53
69
 
54
70
  def reset_soft
@@ -1,10 +1,12 @@
1
1
  module RakeCommit
2
2
  class GitSvn
3
- def initialize(prompt_exclusions = [])
3
+ def initialize(prompt_exclusions = [], precommit = nil)
4
4
  @prompt_exclusions = prompt_exclusions
5
+ @precommit = precommit
5
6
  end
6
7
 
7
8
  def commit
9
+ RakeCommit::Shell.system(@precommit) unless @precommit.nil?
8
10
  git = RakeCommit::Git.new
9
11
  git.add
10
12
  git.status
@@ -3,6 +3,7 @@ require 'tmpdir'
3
3
 
4
4
  module RakeCommit
5
5
  class PromptLine
6
+ include Readline
6
7
 
7
8
  def initialize(attribute, prompt_exclusions = [])
8
9
  @attribute = attribute
@@ -13,38 +14,51 @@ module RakeCommit
13
14
  return nil if @prompt_exclusions.include?(@attribute)
14
15
  input = nil
15
16
  loop do
16
- input = Readline.readline(message).chomp
17
- break unless (input.empty? && saved_data.empty?)
17
+ input = readline(message).chomp
18
+ break unless (input.empty? && !previous_input)
18
19
  end
19
20
 
20
21
  unless input.empty?
21
- save(input)
22
+ save_history(input)
22
23
  return input
23
24
  end
24
25
 
25
- puts "using: #{saved_data}"
26
- return saved_data
26
+ puts "using: #{previous_input}"
27
+ return previous_input
27
28
  end
28
29
 
29
30
  def message
30
- previous = saved_data
31
31
  previous_message = "\n"
32
- previous_message += "previous #{@attribute}: #{previous}\n" unless previous.empty?
32
+ previous_message += "previous #{@attribute}: #{previous_input}\n" if previous_input
33
33
  puts previous_message
34
34
  "#{@attribute}: "
35
35
  end
36
36
 
37
- def save(input)
38
- File.open(path(@attribute), "w") {|f| f.write(input) }
37
+ def save_history(input)
38
+ File.open(history_file, "a") { |f| f.puts(input) }
39
39
  end
40
40
 
41
41
  private
42
- def saved_data
43
- @saved_data ||= File.exists?(path(@attribute)) ? File.read(path(@attribute)) : ""
42
+ def previous_input
43
+ @previous_input ||= history.last
44
44
  end
45
45
 
46
- def path(attribute)
47
- File.expand_path(Dir.tmpdir + "/#{attribute}.data")
46
+ def history
47
+ @history ||= load_history
48
+ end
49
+
50
+ def load_history
51
+ HISTORY.pop until HISTORY.empty?
52
+ HISTORY.push(*saved_history)
53
+ HISTORY.to_a
54
+ end
55
+
56
+ def saved_history
57
+ File.exists?(history_file) ? File.read(history_file).split("\n") : []
58
+ end
59
+
60
+ def history_file
61
+ @history_file ||= File.expand_path(Dir.tmpdir + "/#{@attribute}.data")
48
62
  end
49
63
 
50
64
  end
@@ -3,13 +3,15 @@ require 'fileutils'
3
3
  module RakeCommit
4
4
  class Svn
5
5
 
6
- def initialize(prompt_exclusions = [])
6
+ def initialize(prompt_exclusions = [], precommit = nil)
7
7
  @prompt_exclusions = prompt_exclusions
8
+ @precommit = precommit
8
9
  end
9
10
 
10
11
  def commit
11
12
  if files_to_check_in?
12
13
  message = RakeCommit::CommitMessage.new(@prompt_exclusions).joined_message
14
+ RakeCommit::Shell.system(@precommit) unless @precommit.nil?
13
15
  add
14
16
  delete
15
17
  up
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rake_commit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Paul Gross
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-10-17 00:00:00.000000000 Z
11
+ date: 2014-01-11 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: See http://github.com/pgr0ss/rake_commit
15
14
  email: pgross@gmail.com
@@ -18,43 +17,40 @@ executables:
18
17
  extensions: []
19
18
  extra_rdoc_files: []
20
19
  files:
21
- - README.rdoc
20
+ - README.md
22
21
  - Rakefile
23
- - lib/rake_commit/commit.rb
24
- - lib/rake_commit/commit_message.rb
25
- - lib/rake_commit/cruise_status.rb
26
- - lib/rake_commit/git.rb
22
+ - lib/rake_commit.rb
27
23
  - lib/rake_commit/git_svn.rb
28
- - lib/rake_commit/prompt_line.rb
29
24
  - lib/rake_commit/shell.rb
25
+ - lib/rake_commit/prompt_line.rb
26
+ - lib/rake_commit/cruise_status.rb
27
+ - lib/rake_commit/commit_message.rb
28
+ - lib/rake_commit/commit.rb
29
+ - lib/rake_commit/git.rb
30
30
  - lib/rake_commit/svn.rb
31
- - lib/rake_commit.rb
32
31
  - bin/rake_commit
33
32
  homepage: http://github.com/pgr0ss/rake_commit
34
- licenses: []
33
+ licenses:
34
+ - MIT
35
+ metadata: {}
35
36
  post_install_message:
36
37
  rdoc_options: []
37
38
  require_paths:
38
39
  - lib
39
40
  required_ruby_version: !ruby/object:Gem::Requirement
40
- none: false
41
41
  requirements:
42
- - - ! '>='
42
+ - - '>='
43
43
  - !ruby/object:Gem::Version
44
44
  version: '0'
45
- segments:
46
- - 0
47
- hash: 3950958568738927598
48
45
  required_rubygems_version: !ruby/object:Gem::Requirement
49
- none: false
50
46
  requirements:
51
- - - ! '>='
47
+ - - '>='
52
48
  - !ruby/object:Gem::Version
53
49
  version: '0'
54
50
  requirements: []
55
51
  rubyforge_project: rake_commit
56
- rubygems_version: 1.8.24
52
+ rubygems_version: 2.1.11
57
53
  signing_key:
58
- specification_version: 3
54
+ specification_version: 4
59
55
  summary: A gem which helps with checking in code
60
56
  test_files: []