git-pivotal-tracker-integration 1.1.0 → 1.2.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.
- checksums.yaml +4 -4
- data/README.md +34 -1
- data/bin/git-finish +16 -2
- data/bin/git-release +19 -0
- data/bin/git-start +16 -2
- data/lib/git-pivotal-tracker-integration/command/base.rb +47 -0
- data/lib/git-pivotal-tracker-integration/{base.rb → command/command.rb} +3 -14
- data/lib/git-pivotal-tracker-integration/command/configuration.rb +92 -0
- data/lib/git-pivotal-tracker-integration/command/finish.rb +36 -0
- data/lib/git-pivotal-tracker-integration/command/prepare-commit-msg.sh +26 -0
- data/lib/git-pivotal-tracker-integration/command/release.rb +56 -0
- data/lib/git-pivotal-tracker-integration/command/start.rb +64 -0
- data/lib/git-pivotal-tracker-integration/util/git.rb +242 -0
- data/lib/git-pivotal-tracker-integration/util/shell.rb +36 -0
- data/lib/git-pivotal-tracker-integration/util/story.rb +128 -0
- data/lib/git-pivotal-tracker-integration/util/util.rb +20 -0
- data/lib/git-pivotal-tracker-integration/version-update/gradle.rb +64 -0
- data/lib/git-pivotal-tracker-integration/version-update/version_update.rb +20 -0
- data/lib/git_pivotal_tracker_integration.rb +18 -0
- data/spec/git-pivotal-tracker-integration/command/base_spec.rb +38 -0
- data/spec/git-pivotal-tracker-integration/command/configuration_spec.rb +91 -0
- data/spec/git-pivotal-tracker-integration/command/finish_spec.rb +45 -0
- data/spec/git-pivotal-tracker-integration/command/release_spec.rb +57 -0
- data/spec/git-pivotal-tracker-integration/command/start_spec.rb +50 -0
- data/spec/git-pivotal-tracker-integration/util/git_spec.rb +239 -0
- data/spec/git-pivotal-tracker-integration/util/shell_spec.rb +52 -0
- data/spec/git-pivotal-tracker-integration/util/story_spec.rb +137 -0
- data/spec/git-pivotal-tracker-integration/version-update/gradle_spec.rb +74 -0
- metadata +104 -21
- data/lib/git-pivotal-tracker-integration/finish.rb +0 -106
- data/lib/git-pivotal-tracker-integration/pivotal_configuration.rb +0 -90
- data/lib/git-pivotal-tracker-integration/prepare-commit-msg.sh +0 -12
- data/lib/git-pivotal-tracker-integration/start.rb +0 -167
@@ -0,0 +1,20 @@
|
|
1
|
+
# Git Pivotal Tracker Integration
|
2
|
+
# Copyright (c) 2013 the original author or authors.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require "git_pivotal_tracker_integration"
|
17
|
+
|
18
|
+
# A module encapsulating version update implementations
|
19
|
+
module GitPivotalTrackerIntegration::VersionUpdate
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Git Pivotal Tracker Integration
|
2
|
+
# Copyright (c) 2013 the original author or authors.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
# The root module for the project
|
17
|
+
module GitPivotalTrackerIntegration
|
18
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Git Pivotal Tracker Integration
|
2
|
+
# Copyright (c) 2013 the original author or authors.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require "spec_helper"
|
17
|
+
require "git-pivotal-tracker-integration/command/base"
|
18
|
+
require "git-pivotal-tracker-integration/command/configuration"
|
19
|
+
require "git-pivotal-tracker-integration/util/git"
|
20
|
+
|
21
|
+
describe GitPivotalTrackerIntegration::Command::Base do
|
22
|
+
|
23
|
+
before do
|
24
|
+
$stdout = StringIO.new
|
25
|
+
$stderr = StringIO.new
|
26
|
+
|
27
|
+
@project = double("project")
|
28
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:repository_root)
|
29
|
+
GitPivotalTrackerIntegration::Command::Configuration.any_instance.should_receive(:api_token)
|
30
|
+
GitPivotalTrackerIntegration::Command::Configuration.any_instance.should_receive(:project_id)
|
31
|
+
PivotalTracker::Project.should_receive(:find).and_return(@project)
|
32
|
+
@base = GitPivotalTrackerIntegration::Command::Base.new
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should not run" do
|
36
|
+
lambda { @base.run }.should raise_error
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# Git Pivotal Tracker Integration
|
2
|
+
# Copyright (c) 2013 the original author or authors.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require "spec_helper"
|
17
|
+
require "git-pivotal-tracker-integration/command/configuration"
|
18
|
+
require "git-pivotal-tracker-integration/util/git"
|
19
|
+
require "pivotal-tracker"
|
20
|
+
|
21
|
+
describe GitPivotalTrackerIntegration::Command::Configuration do
|
22
|
+
|
23
|
+
before do
|
24
|
+
$stdout = StringIO.new
|
25
|
+
$stderr = StringIO.new
|
26
|
+
@configuration = GitPivotalTrackerIntegration::Command::Configuration.new
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not prompt the user for the API token if it is already configured" do
|
30
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:get_config).with("pivotal.api-token", :inherited).and_return("test_api_token")
|
31
|
+
|
32
|
+
api_token = @configuration.api_token
|
33
|
+
|
34
|
+
expect(api_token).to eq("test_api_token")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should prompt the user for the API token if it is not configured" do |variable|
|
38
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:get_config).with("pivotal.api-token", :inherited).and_return("")
|
39
|
+
@configuration.should_receive(:ask).and_return("test_api_token")
|
40
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:set_config).with("pivotal.api-token", "test_api_token", :global)
|
41
|
+
|
42
|
+
api_token = @configuration.api_token
|
43
|
+
|
44
|
+
expect(api_token).to eq("test_api_token")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should not prompt the user for the project id if it is already configured" do
|
48
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:get_config).with("pivotal.project-id", :inherited).and_return("test_project_id")
|
49
|
+
|
50
|
+
project_id = @configuration.project_id
|
51
|
+
|
52
|
+
expect(project_id).to eq("test_project_id")
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should prompt the user for the API token if it is not configured" do
|
56
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:get_config).with("pivotal.project-id", :inherited).and_return("")
|
57
|
+
menu = double("menu")
|
58
|
+
menu.should_receive(:prompt=)
|
59
|
+
PivotalTracker::Project.should_receive(:all).and_return([
|
60
|
+
PivotalTracker::Project.new(:id => "id-2", :name => "name-2"),
|
61
|
+
PivotalTracker::Project.new(:id => "id-1", :name => "name-1")])
|
62
|
+
menu.should_receive(:choice).with("name-1")
|
63
|
+
menu.should_receive(:choice).with("name-2")
|
64
|
+
@configuration.should_receive(:choose) { |&arg| arg.call menu }.and_return("test_project_id")
|
65
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:set_config).with("pivotal.project-id", "test_project_id", :local)
|
66
|
+
|
67
|
+
project_id = @configuration.project_id
|
68
|
+
|
69
|
+
expect(project_id).to eq("test_project_id")
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should persist the story when requested" do
|
73
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:set_config).with("pivotal-story-id", 12345678, :branch)
|
74
|
+
|
75
|
+
@configuration.story = PivotalTracker::Story.new(:id => 12345678)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should return a story when requested" do
|
79
|
+
project = double("project")
|
80
|
+
stories = double("stories")
|
81
|
+
story = double("story")
|
82
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:get_config).with("pivotal-story-id", :branch).and_return("12345678")
|
83
|
+
project.should_receive(:stories).and_return(stories)
|
84
|
+
stories.should_receive(:find).with(12345678).and_return(story)
|
85
|
+
|
86
|
+
result = @configuration.story project
|
87
|
+
|
88
|
+
expect(result).to be(story)
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Git Pivotal Tracker Integration
|
2
|
+
# Copyright (c) 2013 the original author or authors.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require "spec_helper"
|
17
|
+
require "git-pivotal-tracker-integration/command/configuration"
|
18
|
+
require "git-pivotal-tracker-integration/command/finish"
|
19
|
+
require "git-pivotal-tracker-integration/util/git"
|
20
|
+
require "pivotal-tracker"
|
21
|
+
|
22
|
+
describe GitPivotalTrackerIntegration::Command::Finish do
|
23
|
+
|
24
|
+
before do
|
25
|
+
$stdout = StringIO.new
|
26
|
+
$stderr = StringIO.new
|
27
|
+
|
28
|
+
@project = double("project")
|
29
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:repository_root)
|
30
|
+
GitPivotalTrackerIntegration::Command::Configuration.any_instance.should_receive(:api_token)
|
31
|
+
GitPivotalTrackerIntegration::Command::Configuration.any_instance.should_receive(:project_id)
|
32
|
+
PivotalTracker::Project.should_receive(:find).and_return(@project)
|
33
|
+
@finish = GitPivotalTrackerIntegration::Command::Finish.new
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should run" do
|
37
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:trivial_merge?)
|
38
|
+
GitPivotalTrackerIntegration::Command::Configuration.any_instance.should_receive(:story)
|
39
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:merge)
|
40
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:branch_name).and_return("master")
|
41
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:push).with("master")
|
42
|
+
|
43
|
+
@finish.run
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Git Pivotal Tracker Integration
|
2
|
+
# Copyright (c) 2013 the original author or authors.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require "spec_helper"
|
17
|
+
require "git-pivotal-tracker-integration/command/configuration"
|
18
|
+
require "git-pivotal-tracker-integration/command/release"
|
19
|
+
require "git-pivotal-tracker-integration/util/git"
|
20
|
+
require "git-pivotal-tracker-integration/util/story"
|
21
|
+
require "pivotal-tracker"
|
22
|
+
|
23
|
+
describe GitPivotalTrackerIntegration::Command::Release do
|
24
|
+
|
25
|
+
before do
|
26
|
+
$stdout = StringIO.new
|
27
|
+
$stderr = StringIO.new
|
28
|
+
|
29
|
+
@project = double("project")
|
30
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:repository_root)
|
31
|
+
GitPivotalTrackerIntegration::Command::Configuration.any_instance.should_receive(:api_token)
|
32
|
+
GitPivotalTrackerIntegration::Command::Configuration.any_instance.should_receive(:project_id)
|
33
|
+
PivotalTracker::Project.should_receive(:find).and_return(@project)
|
34
|
+
@release = GitPivotalTrackerIntegration::Command::Release.new
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should run" do
|
38
|
+
story = PivotalTracker::Story.new(:id => 12345678)
|
39
|
+
updater = double("updater")
|
40
|
+
GitPivotalTrackerIntegration::Util::Story.should_receive(:select_story).and_return(story)
|
41
|
+
GitPivotalTrackerIntegration::Util::Story.should_receive(:pretty_print)
|
42
|
+
GitPivotalTrackerIntegration::VersionUpdate::Gradle.should_receive(:new).and_return(updater)
|
43
|
+
updater.should_receive(:supports?).and_return(true)
|
44
|
+
updater.should_receive(:current_version).and_return("test_current_version")
|
45
|
+
@release.should_receive(:ask).and_return("test_release_version")
|
46
|
+
@release.should_receive(:ask).and_return("test_next_version")
|
47
|
+
updater.should_receive(:update_version).with("test_release_version")
|
48
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:create_release_tag).with("test_release_version", story)
|
49
|
+
updater.should_receive(:update_version).with("test_next_version")
|
50
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:create_commit).with("test_next_version Development", story)
|
51
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:branch_name).and_return("master")
|
52
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:push).with("master", "vtest_release_version")
|
53
|
+
|
54
|
+
@release.run(nil)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# Git Pivotal Tracker Integration
|
2
|
+
# Copyright (c) 2013 the original author or authors.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require "spec_helper"
|
17
|
+
require "git-pivotal-tracker-integration/command/configuration"
|
18
|
+
require "git-pivotal-tracker-integration/command/start"
|
19
|
+
require "git-pivotal-tracker-integration/util/git"
|
20
|
+
require "git-pivotal-tracker-integration/util/story"
|
21
|
+
require "pivotal-tracker"
|
22
|
+
|
23
|
+
describe GitPivotalTrackerIntegration::Command::Start do
|
24
|
+
|
25
|
+
before do
|
26
|
+
$stdout = StringIO.new
|
27
|
+
$stderr = StringIO.new
|
28
|
+
|
29
|
+
@project = double("project")
|
30
|
+
@story = double("story")
|
31
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:repository_root)
|
32
|
+
GitPivotalTrackerIntegration::Command::Configuration.any_instance.should_receive(:api_token)
|
33
|
+
GitPivotalTrackerIntegration::Command::Configuration.any_instance.should_receive(:project_id)
|
34
|
+
PivotalTracker::Project.should_receive(:find).and_return(@project)
|
35
|
+
@start = GitPivotalTrackerIntegration::Command::Start.new
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should run" do
|
39
|
+
GitPivotalTrackerIntegration::Util::Story.should_receive(:select_story).with(@project, "test_filter").and_return(@story)
|
40
|
+
GitPivotalTrackerIntegration::Util::Story.should_receive(:pretty_print)
|
41
|
+
@story.should_receive(:id).twice.and_return(12345678)
|
42
|
+
@start.should_receive(:ask).and_return("development_branch")
|
43
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:create_branch).with("12345678-development_branch")
|
44
|
+
GitPivotalTrackerIntegration::Command::Configuration.any_instance.should_receive(:story=)
|
45
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:add_hook)
|
46
|
+
@story.should_receive(:update).with(:current_state => "started")
|
47
|
+
|
48
|
+
@start.run "test_filter"
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,239 @@
|
|
1
|
+
# Git Pivotal Tracker Integration
|
2
|
+
# Copyright (c) 2013 the original author or authors.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require "spec_helper"
|
17
|
+
require "git-pivotal-tracker-integration/util/git"
|
18
|
+
require "git-pivotal-tracker-integration/util/shell"
|
19
|
+
|
20
|
+
describe GitPivotalTrackerIntegration::Util::Git do
|
21
|
+
|
22
|
+
before do
|
23
|
+
$stdout = StringIO.new
|
24
|
+
$stderr = StringIO.new
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return the current branch name" do
|
28
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git branch").and_return(" master\n * dev_branch")
|
29
|
+
|
30
|
+
current_branch = GitPivotalTrackerIntegration::Util::Git.branch_name
|
31
|
+
|
32
|
+
expect(current_branch).to eq("dev_branch")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return the repository root" do
|
36
|
+
Dir.mktmpdir do |root|
|
37
|
+
child_directory = File.expand_path "child", root
|
38
|
+
Dir.mkdir child_directory
|
39
|
+
|
40
|
+
git_directory = File.expand_path ".git", root
|
41
|
+
Dir.mkdir git_directory
|
42
|
+
|
43
|
+
Dir.should_receive(:pwd).and_return(child_directory)
|
44
|
+
|
45
|
+
repository_root = GitPivotalTrackerIntegration::Util::Git.repository_root
|
46
|
+
|
47
|
+
expect(repository_root).to eq(root)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should raise an error there is no repository root" do
|
52
|
+
Dir.mktmpdir do |root|
|
53
|
+
child_directory = File.expand_path "child", root
|
54
|
+
Dir.mkdir child_directory
|
55
|
+
|
56
|
+
Dir.should_receive(:pwd).and_return(child_directory)
|
57
|
+
|
58
|
+
expect { GitPivotalTrackerIntegration::Util::Git.repository_root }.to raise_error
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should get configuration when :branch scope is specified" do
|
63
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:branch_name).and_return("test_branch_name")
|
64
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git config branch.test_branch_name.test_key", false).and_return("test_value")
|
65
|
+
|
66
|
+
value = GitPivotalTrackerIntegration::Util::Git.get_config "test_key", :branch
|
67
|
+
|
68
|
+
expect(value).to eq("test_value")
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should get configuration when :inherited scope is specified" do
|
72
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git config test_key", false).and_return("test_value")
|
73
|
+
|
74
|
+
value = GitPivotalTrackerIntegration::Util::Git.get_config "test_key", :inherited
|
75
|
+
|
76
|
+
expect(value).to eq("test_value")
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should raise an error when an unknown scope is specified (get)" do
|
80
|
+
expect { GitPivotalTrackerIntegration::Util::Git.get_config "test_key", :unknown }.to raise_error
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should set configuration when :branch scope is specified" do
|
84
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:branch_name).and_return("test_branch_name")
|
85
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git config --local branch.test_branch_name.test_key test_value")
|
86
|
+
|
87
|
+
GitPivotalTrackerIntegration::Util::Git.set_config "test_key", "test_value", :branch
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should set configuration when :global scope is specified" do
|
91
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git config --global test_key test_value")
|
92
|
+
|
93
|
+
GitPivotalTrackerIntegration::Util::Git.set_config "test_key", "test_value", :global
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should set configuration when :local scope is specified" do
|
97
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git config --local test_key test_value")
|
98
|
+
|
99
|
+
GitPivotalTrackerIntegration::Util::Git.set_config "test_key", "test_value", :local
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should raise an error when an unknown scope is specified (set)" do
|
103
|
+
expect { GitPivotalTrackerIntegration::Util::Git.set_config "test_key", "test_valeu", :unknown }.to raise_error
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should create a branch and set the root_branch and root_remote properties on it" do
|
107
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:branch_name).and_return("master")
|
108
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:get_config).with("remote", :branch).and_return("origin")
|
109
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git pull --quiet --ff-only")
|
110
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).and_return("git checkout --quiet -b dev_branch")
|
111
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:set_config).with("root-branch", "master", :branch)
|
112
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:set_config).with("root-remote", "origin", :branch)
|
113
|
+
|
114
|
+
GitPivotalTrackerIntegration::Util::Git.create_branch "dev_branch"
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should not add a hook if it already exists" do
|
118
|
+
Dir.mktmpdir do |root|
|
119
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:repository_root).and_return(root)
|
120
|
+
hook = "#{root}/.git/hooks/prepare-commit-msg"
|
121
|
+
File.should_receive(:exist?).with(hook).and_return(true)
|
122
|
+
|
123
|
+
GitPivotalTrackerIntegration::Util::Git.add_hook "prepare-commit-msg", __FILE__
|
124
|
+
|
125
|
+
File.should_receive(:exist?).and_call_original
|
126
|
+
expect(File.exist?(hook)).to be_false
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should add a hook if it does not exist" do
|
131
|
+
Dir.mktmpdir do |root|
|
132
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:repository_root).and_return(root)
|
133
|
+
hook = "#{root}/.git/hooks/prepare-commit-msg"
|
134
|
+
File.should_receive(:exist?).with(hook).and_return(false)
|
135
|
+
|
136
|
+
GitPivotalTrackerIntegration::Util::Git.add_hook "prepare-commit-msg", __FILE__
|
137
|
+
|
138
|
+
File.should_receive(:exist?).and_call_original
|
139
|
+
expect(File.exist?(hook)).to be_true
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should add a hook if it already exists and overwrite is true" do
|
144
|
+
Dir.mktmpdir do |root|
|
145
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:repository_root).and_return(root)
|
146
|
+
hook = "#{root}/.git/hooks/prepare-commit-msg"
|
147
|
+
|
148
|
+
GitPivotalTrackerIntegration::Util::Git.add_hook "prepare-commit-msg", __FILE__, true
|
149
|
+
|
150
|
+
File.should_receive(:exist?).and_call_original
|
151
|
+
expect(File.exist?(hook)).to be_true
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should fail if remote tip and local tip do not match" do
|
156
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:branch_name).and_return("development_branch")
|
157
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:get_config).with("root-branch", :branch).and_return("master")
|
158
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:get_config).with("root-remote", :branch).and_return("origin")
|
159
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git fetch origin")
|
160
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git rev-parse origin/master").and_return("remote_tip")
|
161
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git rev-parse master").and_return("local_tip")
|
162
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git merge-base master development_branch").and_return("common_ancestor")
|
163
|
+
|
164
|
+
lambda { GitPivotalTrackerIntegration::Util::Git.trivial_merge? }.should raise_error(SystemExit)
|
165
|
+
|
166
|
+
expect($stderr.string).to match(/FAIL/)
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should fail if local tip and common ancestor do not match" do
|
170
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:branch_name).and_return("development_branch")
|
171
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:get_config).with("root-branch", :branch).and_return("master")
|
172
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:get_config).with("root-remote", :branch).and_return("origin")
|
173
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git fetch origin")
|
174
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git rev-parse origin/master").and_return("HEAD")
|
175
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git rev-parse master").and_return("HEAD")
|
176
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git merge-base master development_branch").and_return("common_ancestor")
|
177
|
+
|
178
|
+
lambda { GitPivotalTrackerIntegration::Util::Git.trivial_merge? }.should raise_error(SystemExit)
|
179
|
+
|
180
|
+
expect($stderr.string).to match(/FAIL/)
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should pass if remote tip, local tip, and common ancestor all match" do
|
184
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:branch_name).and_return("development_branch")
|
185
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:get_config).with("root-branch", :branch).and_return("master")
|
186
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:get_config).with("root-remote", :branch).and_return("origin")
|
187
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git fetch origin")
|
188
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git rev-parse origin/master").and_return("HEAD")
|
189
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git rev-parse master").and_return("HEAD")
|
190
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git merge-base master development_branch").and_return("HEAD")
|
191
|
+
|
192
|
+
GitPivotalTrackerIntegration::Util::Git.trivial_merge?
|
193
|
+
|
194
|
+
expect($stdout.string).to match(/OK/)
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should merge and delete branches" do
|
198
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:branch_name).and_return("development_branch")
|
199
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:get_config).with("root-branch", :branch).and_return("master")
|
200
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git checkout --quiet master")
|
201
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git merge --quiet --no-ff -m \"Merge development_branch to master\n\n[Completes #12345678]\" development_branch")
|
202
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git branch --quiet -D development_branch")
|
203
|
+
|
204
|
+
GitPivotalTrackerIntegration::Util::Git.merge PivotalTracker::Story.new(:id => 12345678)
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should push changes without refs" do
|
208
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:get_config).with("remote", :branch).and_return("origin")
|
209
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git push --quiet origin ")
|
210
|
+
|
211
|
+
GitPivotalTrackerIntegration::Util::Git.push
|
212
|
+
end
|
213
|
+
|
214
|
+
it "should push changes with refs" do
|
215
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:get_config).with("remote", :branch).and_return("origin")
|
216
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git push --quiet origin foo bar")
|
217
|
+
|
218
|
+
GitPivotalTrackerIntegration::Util::Git.push "foo", "bar"
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should create a commit" do
|
222
|
+
story = PivotalTracker::Story.new(:id => 123456789)
|
223
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git commit --quiet --all --allow-empty --message \"test_message\n\n[#123456789]\"")
|
224
|
+
|
225
|
+
GitPivotalTrackerIntegration::Util::Git.create_commit "test_message", story
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should create a release tag" do
|
229
|
+
story = PivotalTracker::Story.new(:id => 123456789)
|
230
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:branch_name).and_return("master")
|
231
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:create_branch).with("pivotal-tracker-release", false)
|
232
|
+
GitPivotalTrackerIntegration::Util::Git.should_receive(:create_commit).with("1.0.0.RELEASE Release", story)
|
233
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git tag v1.0.0.RELEASE")
|
234
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git checkout --quiet master")
|
235
|
+
GitPivotalTrackerIntegration::Util::Shell.should_receive(:exec).with("git branch --quiet -D pivotal-tracker-release")
|
236
|
+
|
237
|
+
GitPivotalTrackerIntegration::Util::Git.create_release_tag "1.0.0.RELEASE", story
|
238
|
+
end
|
239
|
+
end
|