Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 8 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
View
8 lib/git_tracker/prepare_commit_message.rb
@@ -16,15 +16,21 @@ def initialize(file, source=nil, commit_sha=nil)
end
def run
- story = story_number_from_branch
+ exit_when_commit_exists
+ story = story_number_from_branch
message = CommitMessage.new(file)
exit if message.mentions_story?(story)
+
message.append("[##{story}]")
end
private
+ def exit_when_commit_exists
+ exit if source == 'commit'
+ end
+
def story_number_from_branch
story = Branch.story_number
exit unless story
View
3  spec/git_tracker/branch_spec.rb
@@ -1,3 +1,4 @@
+require 'spec_helper'
require 'git_tracker/branch'
describe GitTracker::Branch do
@@ -19,7 +20,7 @@ def stub_branch(ref, exit_status = 0)
it 'aborts with non-zero exit status when not in a Git repository' do
stub_branch(nil, 128)
- -> { subject.current }.should raise_error SystemExit
+ lambda { subject.current }.should_not succeed
end
end
View
2  spec/git_tracker/commit_message_spec.rb
@@ -9,7 +9,7 @@
let(:file) { "COMMIT_EDITMSG" }
it "requires path to the temporary commit message file" do
- -> { GitTracker::CommitMessage.new }.should raise_error ArgumentError
+ lambda { GitTracker::CommitMessage.new }.should raise_error ArgumentError
end
describe "#mentions_story?" do
View
13 spec/git_tracker/prepare_commit_message_spec.rb
@@ -1,3 +1,4 @@
+require 'spec_helper'
require 'git_tracker/prepare_commit_message'
describe GitTracker::PrepareCommitMessage do
@@ -40,11 +41,19 @@
GitTracker::Branch.stub(:story_number) { story }
end
+ context 'with an existing commit (via `-c`, `-C`, or `--amend` options)' do
+ let(:hook) { described_class.new('FILE2', 'commit', '60a086f3') }
+
+ it 'exits with status code 0' do
+ lambda { hook.run }.should succeed
+ end
+ end
+
context "branch name without a Pivotal Tracker story number" do
let(:story) { nil }
it "exits without updating the commit message" do
- lambda { hook.run }.should raise_exception(SystemExit)
+ lambda { hook.run }.should succeed
GitTracker::CommitMessage.should_not have_received(:append)
end
end
@@ -67,7 +76,7 @@
end
it "exits without updating the commit message" do
- lambda { hook.run }.should raise_exception(SystemExit)
+ lambda { hook.run }.should succeed
GitTracker::CommitMessage.should_not have_received(:append)
end
end
View
3  spec/git_tracker/repository_spec.rb
@@ -1,3 +1,4 @@
+require 'spec_helper'
require 'git_tracker/repository'
describe GitTracker::Repository do
@@ -17,7 +18,7 @@
it 'aborts when not in a git repository' do
$?.stub(:exitstatus) { 128 }
- -> { subject.root }.should raise_error SystemExit
+ lambda { subject.root }.should_not succeed
end
end
View
4 spec/git_tracker_spec.rb
@@ -1,3 +1,4 @@
+require 'spec_helper'
require 'git_tracker'
describe GitTracker do
@@ -16,8 +17,7 @@
# TODO: stop the abort from writing to stderr during tests?
it "doesn't run hooks we don't know about" do
- lambda { subject.execute('non-existent-hook', *args) }.
- should raise_error SystemExit, "[git_tracker] command: 'non-existent-hook' does not exist."
+ lambda { subject.execute('non-existent-hook', *args) }.should_not succeed
end
end
View
1  spec/spec_helper.rb
@@ -1,5 +1,6 @@
require 'fake_file'
require 'commit_message_helper'
+require_relative 'support/matchers/exit_code_matchers'
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
View
33 spec/support/matchers/exit_code_matchers.rb
@@ -0,0 +1,33 @@
+require 'rspec/expectations'
+
+RSpec::Matchers.define :succeed do
+ actual = nil
+
+ match do |block|
+ begin
+ block.call
+ rescue SystemExit => e
+ actual = e.status
+ end
+ actual and actual == successful_exit_code
+ end
+
+ failure_message_for_should do |block|
+ "expected block to call exit(#{successful_exit_code}) but exit" +
+ (actual.nil? ? " not called" : "(#{actual}) was called")
+ end
+
+ failure_message_for_should_not do |block|
+ "expected block not to call exit(#{successful_exit_code})"
+ end
+
+ description do
+ "expect block to call exit(#{successful_exit_code})"
+ end
+
+ def successful_exit_code
+ 0
+ end
+
+end
+

No commit comments for this range

Something went wrong with that request. Please try again.