git_tracker 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,29 +1,117 @@
1
1
  # GitTracker
2
2
 
3
- TODO: Write a gem description
3
+ *GitTracker*, or *git-tracker*, is a Git hook that will scan your current
4
+ branch number looking for something it recognizes as a [Pivotal Tracker][pt]
5
+ story number. If it finds one, it will automagically add it, in the [special
6
+ format][pt-format], to your commit message.
4
7
 
5
8
  ## Installation
6
9
 
7
- Add this line to your application's Gemfile:
10
+ You need to get the `git-tracker` executable on your system.
8
11
 
9
- gem 'git_tracker'
12
+ ### RubyGems
10
13
 
11
- And then execute:
14
+ Currently, this is the only option, but I plan to have a standalone version
15
+ ready soon.
12
16
 
13
- $ bundle
17
+ ```bash
18
+ $ gem install git_tracker
19
+ ```
14
20
 
15
- Or install it yourself as:
21
+ Once you have the `git-tracker` executable on your system you need to install
22
+ the hook into your local Git repository.
16
23
 
17
- $ gem install git_tracker
24
+ ```bash
25
+ # from inside a local Git repository
26
+ $ git-tracker install
27
+ ```
28
+
29
+ This will put the `prepare-commit-msg` hook in the `/path/to/repo/.git/hooks`
30
+ directory and make it executable.
31
+
32
+ **NOTE:** This will need to be done for each repository that you wish to use
33
+ the hook.
18
34
 
19
35
  ## Usage
20
36
 
21
- TODO: Write usage instructions here
37
+ With the hook installed in a repository, create branches being sure to include
38
+ the Pivotal Tracker story number in the branch name.
39
+
40
+ ```bash
41
+ $ git checkout -b a_useful_and_helpful_name_#8675309
42
+ ```
43
+
44
+ When you commit, Git will fire the hook which will find the story number in the
45
+ branch name and prepare your commit message so that it include the story number
46
+ in the special Pivotal Tracker syntax.
47
+
48
+ ```bash
49
+ # on branch named `best_feature_ever-#8675309`
50
+ $ git commit
51
+ ```
52
+
53
+ Will result in a commit message something like: *(notice the two empty lines at
54
+ the top)*
55
+
56
+ ```diff
57
+
58
+
59
+ [#8675309]
60
+ # Please enter the commit message for your changes. Lines starting
61
+ # with '#' will be ignored, and an empty message aborts the commit.
62
+ # On branch best_feature_ever-#8675309
63
+ # Changes to be committed:
64
+ # (use "git reset HEAD <file>..." to unstage)
65
+ #
66
+ # new file: feature.rb
67
+ #
68
+
69
+ ```
70
+
71
+ You should then add a [useful and responsible commit message][tpope]. :heart:
72
+
73
+ ### Passing commit messages via command line
22
74
 
23
- ## Contributing
75
+ If you pass a commit message on the command line the hook will still add the
76
+ story number, preceded by an empty line, to the end of your message.
77
+
78
+ ```bash
79
+ # on branch named `best_feature_ever-#8675309`
80
+ $ git commit -m'Look at this rad code, yo!'
81
+ ```
82
+
83
+ Results in this commit message:
84
+
85
+ ```
86
+ Look at this rad code, yo!
87
+
88
+ [#8675309]
89
+ ```
90
+
91
+ However, if you include the story number in the Pivotal Tracker format in your
92
+ commit message, the hook will do nothing.
93
+
94
+ ```bash
95
+ # on branch named `best_feature_ever-#8675309`
96
+ $ git commit -m'[#8675309] Look at this rad code, yo!'
97
+ ```
98
+
99
+ Results in this commit message:
100
+
101
+
102
+ ```
103
+ [#12356] Look at this rad code, yo!
104
+ ```
105
+
106
+ ## Contributing :octocat:
24
107
 
25
108
  1. Fork it
26
109
  2. Create your feature branch (`git checkout -b my-new-feature`)
27
110
  3. Commit your changes (`git commit -am 'Added some feature'`)
28
111
  4. Push to the branch (`git push origin my-new-feature`)
29
112
  5. Create new Pull Request
113
+
114
+
115
+ [pt]: https://www.pivotaltracker.com/
116
+ [pt-format]: https://www.pivotaltracker.com/help/api?version=v3#scm_post_commit_message_syntax
117
+ [tpope]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
data/git_tracker.gemspec CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.add_development_dependency "rspec", "~> 2.0"
17
17
  gem.add_development_dependency "rspec-spies", "~> 2.0"
18
18
  gem.add_development_dependency "pry", "~> 0.9.8"
19
+ gem.add_development_dependency "activesupport", "~> 3.2"
19
20
 
20
21
  gem.files = `git ls-files`.split("\n")
21
22
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -0,0 +1,38 @@
1
+ require 'git_tracker/repository'
2
+
3
+ module GitTracker
4
+ class Hook
5
+
6
+ def self.install
7
+ install_at(Repository.root)
8
+ end
9
+
10
+ def self.install_at(root)
11
+ hook = hook_from(root)
12
+ write(hook)
13
+ end
14
+
15
+ private
16
+
17
+ def self.hook_from(root)
18
+ File.join(root, '.git', 'hooks', 'prepare-commit-msg')
19
+ end
20
+
21
+ def self.write(hook)
22
+ File.open(hook, 'w') do |f|
23
+ f.write(hook_body)
24
+ f.chmod(0755)
25
+ end
26
+ end
27
+
28
+ def self.hook_body
29
+ return <<-HOOK
30
+ #!/usr/bin/env bash
31
+
32
+ git-tracker prepare-commit-msg "$@"
33
+
34
+ HOOK
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,13 @@
1
+ require 'english'
2
+
3
+ module GitTracker
4
+ module Repository
5
+
6
+ def self.root
7
+ path = `git rev-parse --show-toplevel`.chomp
8
+ abort unless $CHILD_STATUS.exitstatus == 0
9
+ path
10
+ end
11
+
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module GitTracker
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/git_tracker.rb CHANGED
@@ -1,14 +1,19 @@
1
- require "git_tracker/version"
1
+ require "git_tracker/hook"
2
2
  require "git_tracker/prepare_commit_message"
3
+ require "git_tracker/version"
3
4
 
4
5
  module GitTracker
5
- def self.execute(hook, *args)
6
- hook_name = hook.gsub(/-/, '_')
7
- abort("[git_tracker] hook: '#{hook}' does not exist.") unless respond_to?(hook_name)
8
- send(hook_name, *args)
6
+ def self.execute(cmd_arg, *args)
7
+ command = cmd_arg.gsub(/-/, '_')
8
+ abort("[git_tracker] command: '#{cmd_arg}' does not exist.") unless respond_to?(command)
9
+ send(command, *args)
9
10
  end
10
11
 
11
12
  def self.prepare_commit_msg(*args)
12
13
  PrepareCommitMessage.run(*args)
13
14
  end
15
+
16
+ def self.install
17
+ Hook.install
18
+ end
14
19
  end
@@ -1,5 +1,6 @@
1
+ require 'spec_helper'
1
2
  require 'git_tracker/commit_message'
2
- require 'commit_message_helper'
3
+ require 'active_support/core_ext/string/strip'
3
4
 
4
5
  describe GitTracker::CommitMessage do
5
6
  include CommitMessageHelper
@@ -87,12 +88,11 @@ describe GitTracker::CommitMessage do
87
88
  stub_original_commit_message("\n\n# some other comments\n")
88
89
  subject.append("[#8675309]")
89
90
 
90
- fake_file.content.should ==
91
- <<-COMMIT_MESSAGE
91
+ fake_file.content.should == <<-COMMIT_MESSAGE.strip_heredoc
92
92
 
93
93
 
94
- [#8675309]
95
- # some other comments
94
+ [#8675309]
95
+ # some other comments
96
96
  COMMIT_MESSAGE
97
97
  end
98
98
 
@@ -100,13 +100,13 @@ describe GitTracker::CommitMessage do
100
100
  stub_original_commit_message("A first line\n\nWith more here\n# other comments\n")
101
101
  subject.append("[#8675309]")
102
102
 
103
- fake_file.content.should == <<-COMMIT_MESSAGE
104
- A first line
103
+ fake_file.content.should == <<-COMMIT_MESSAGE.strip_heredoc
104
+ A first line
105
105
 
106
- With more here
106
+ With more here
107
107
 
108
- [#8675309]
109
- # other comments
108
+ [#8675309]
109
+ # other comments
110
110
  COMMIT_MESSAGE
111
111
  end
112
112
 
@@ -114,13 +114,13 @@ With more here
114
114
  stub_original_commit_message("# comment #1\n# comment B\n# comment III")
115
115
  subject.append("[#8675309]")
116
116
 
117
- fake_file.content.should == <<-COMMIT_MESSAGE
117
+ fake_file.content.should == <<-COMMIT_MESSAGE.strip_heredoc
118
118
 
119
119
 
120
- [#8675309]
121
- # comment #1
122
- # comment B
123
- # comment III
120
+ [#8675309]
121
+ # comment #1
122
+ # comment B
123
+ # comment III
124
124
  COMMIT_MESSAGE
125
125
  end
126
126
  end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+ require 'git_tracker/hook'
3
+ require 'active_support/core_ext/string/strip'
4
+
5
+ describe GitTracker::Hook do
6
+ subject { described_class }
7
+ let(:root) { '/path/to/git/repo/toplevel' }
8
+ let(:hook_path) { File.join(root, '.git', 'hooks', 'prepare-commit-msg') }
9
+
10
+ describe '.install' do
11
+ before do
12
+ GitTracker::Repository.stub(:root) { root }
13
+ end
14
+
15
+ it 'installs to the root of the Git repository' do
16
+ subject.should_receive(:install_at).with(root)
17
+ subject.install
18
+ end
19
+ end
20
+
21
+ describe '.install_at' do
22
+ let(:fake_file) { GitTracker::FakeFile.new }
23
+ before do
24
+ File.stub(:open).and_yield(fake_file)
25
+ end
26
+
27
+ it 'writes the hook into the hooks directory' do
28
+ File.should_receive(:open).with(hook_path, 'w')
29
+ subject.install_at(root)
30
+ end
31
+
32
+ it 'makes the hook executable' do
33
+ subject.install_at(root)
34
+ fake_file.mode.should == 0755
35
+ end
36
+
37
+ it 'writes the hook code in the hook file' do
38
+ subject.install_at(root)
39
+ fake_file.content.should == <<-HOOK_CODE.strip_heredoc
40
+ #!/usr/bin/env bash
41
+
42
+ git-tracker prepare-commit-msg "$@"
43
+
44
+ HOOK_CODE
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,22 @@
1
+ require 'git_tracker/repository'
2
+
3
+ describe GitTracker::Repository do
4
+ subject { described_class }
5
+
6
+ describe '.root' do
7
+ let(:git_command) { 'git rev-parse --show-toplevel' }
8
+ before do
9
+ subject.stub(:`).with(git_command) { "/path/to/git/repo/root\n" }
10
+ end
11
+
12
+ it "gets the path to the local Repository's top-level directory" do
13
+ subject.root.should == '/path/to/git/repo/root'
14
+ end
15
+
16
+ it 'aborts when not in a git repository' do
17
+ $?.stub(:exitstatus) { 128 }
18
+ -> { subject.root }.should raise_error SystemExit
19
+ end
20
+ end
21
+
22
+ end
@@ -17,7 +17,7 @@ describe GitTracker do
17
17
  # TODO: stop the abort from writing to stderr during tests?
18
18
  it "doesn't run hooks we don't know about" do
19
19
  lambda { subject.execute('non-existent-hook', *args) }.
20
- should raise_error SystemExit, "[git_tracker] hook: 'non-existent-hook' does not exist."
20
+ should raise_error SystemExit, "[git_tracker] command: 'non-existent-hook' does not exist."
21
21
  end
22
22
  end
23
23
 
@@ -28,4 +28,11 @@ describe GitTracker do
28
28
  end
29
29
  end
30
30
 
31
+ describe ".install" do
32
+ it 'tells the hook to install itself' do
33
+ GitTracker::Hook.should_receive(:install)
34
+ subject.install
35
+ end
36
+ end
37
+
31
38
  end
@@ -0,0 +1,8 @@
1
+ require 'fake_file'
2
+ require 'commit_message_helper'
3
+
4
+ RSpec.configure do |config|
5
+ config.treat_symbols_as_metadata_keys_with_true_values = true
6
+ config.run_all_when_everything_filtered = true
7
+ config.filter_run :focus
8
+ end
@@ -18,12 +18,3 @@ EXAMPLE
18
18
  end
19
19
  end
20
20
 
21
- module GitTracker
22
- class FakeFile
23
- attr_reader :content
24
-
25
- def write(content)
26
- @content = content
27
- end
28
- end
29
- end
@@ -0,0 +1,13 @@
1
+ module GitTracker
2
+ class FakeFile
3
+ attr_reader :content, :mode
4
+
5
+ def write(content)
6
+ @content = content
7
+ end
8
+
9
+ def chmod(mode_int)
10
+ @mode = mode_int
11
+ end
12
+ end
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_tracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-23 00:00:00.000000000 Z
12
+ date: 2012-03-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70146115751180 !ruby/object:Gem::Requirement
16
+ requirement: &70106555555260 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70146115751180
24
+ version_requirements: *70106555555260
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec-spies
27
- requirement: &70146115750200 !ruby/object:Gem::Requirement
27
+ requirement: &70106555554300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '2.0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70146115750200
35
+ version_requirements: *70106555554300
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: pry
38
- requirement: &70146115749520 !ruby/object:Gem::Requirement
38
+ requirement: &70106555553320 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,18 @@ dependencies:
43
43
  version: 0.9.8
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70146115749520
46
+ version_requirements: *70106555553320
47
+ - !ruby/object:Gem::Dependency
48
+ name: activesupport
49
+ requirement: &70106555552580 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70106555552580
47
58
  description: ! " Some simple tricks that make working with Pivotal Tracker even\n
48
59
  \ better... and easier... um, besier!\n"
49
60
  email:
@@ -64,14 +75,20 @@ files:
64
75
  - lib/git_tracker.rb
65
76
  - lib/git_tracker/branch.rb
66
77
  - lib/git_tracker/commit_message.rb
78
+ - lib/git_tracker/hook.rb
67
79
  - lib/git_tracker/prepare_commit_message.rb
80
+ - lib/git_tracker/repository.rb
68
81
  - lib/git_tracker/version.rb
69
82
  - prepare-commit-msg.example
70
83
  - spec/git_tracker/branch_spec.rb
71
84
  - spec/git_tracker/commit_message_spec.rb
85
+ - spec/git_tracker/hook_spec.rb
72
86
  - spec/git_tracker/prepare_commit_message_spec.rb
87
+ - spec/git_tracker/repository_spec.rb
73
88
  - spec/git_tracker_spec.rb
89
+ - spec/spec_helper.rb
74
90
  - spec/support/commit_message_helper.rb
91
+ - spec/support/fake_file.rb
75
92
  homepage: https://github.com/highgroove/git_tracker
76
93
  licenses: []
77
94
  post_install_message:
@@ -99,6 +116,10 @@ summary: Teaching Git about Pivotal Tracker.
99
116
  test_files:
100
117
  - spec/git_tracker/branch_spec.rb
101
118
  - spec/git_tracker/commit_message_spec.rb
119
+ - spec/git_tracker/hook_spec.rb
102
120
  - spec/git_tracker/prepare_commit_message_spec.rb
121
+ - spec/git_tracker/repository_spec.rb
103
122
  - spec/git_tracker_spec.rb
123
+ - spec/spec_helper.rb
104
124
  - spec/support/commit_message_helper.rb
125
+ - spec/support/fake_file.rb