git-process-lib 2.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.
Files changed (69) hide show
  1. data/CHANGELOG.md +123 -0
  2. data/Gemfile +21 -0
  3. data/Gemfile.lock +57 -0
  4. data/LICENSE +193 -0
  5. data/README.md +342 -0
  6. data/Rakefile +32 -0
  7. data/bin/git-new-fb +39 -0
  8. data/bin/git-pull-request +63 -0
  9. data/bin/git-sync +38 -0
  10. data/bin/git-to-master +44 -0
  11. data/docs/git-new-fb.1.adoc +83 -0
  12. data/docs/git-process.1.adoc +227 -0
  13. data/docs/git-pull-request.1.adoc +166 -0
  14. data/docs/git-sync.1.adoc +120 -0
  15. data/docs/git-to-master.1.adoc +172 -0
  16. data/git-new-fb.gemspec +20 -0
  17. data/git-process-lib.gemspec +25 -0
  18. data/git-process.gemspec +22 -0
  19. data/git-pull-request.gemspec +20 -0
  20. data/git-sync.gemspec +20 -0
  21. data/git-to-master.gemspec +20 -0
  22. data/lib/git-process/abstract_error_builder.rb +53 -0
  23. data/lib/git-process/changed_file_helper.rb +115 -0
  24. data/lib/git-process/git_abstract_merge_error_builder.rb +130 -0
  25. data/lib/git-process/git_branch.rb +105 -0
  26. data/lib/git-process/git_branches.rb +81 -0
  27. data/lib/git-process/git_config.rb +135 -0
  28. data/lib/git-process/git_lib.rb +646 -0
  29. data/lib/git-process/git_logger.rb +84 -0
  30. data/lib/git-process/git_merge_error.rb +28 -0
  31. data/lib/git-process/git_process.rb +159 -0
  32. data/lib/git-process/git_process_error.rb +18 -0
  33. data/lib/git-process/git_process_options.rb +101 -0
  34. data/lib/git-process/git_rebase_error.rb +30 -0
  35. data/lib/git-process/git_remote.rb +222 -0
  36. data/lib/git-process/git_status.rb +108 -0
  37. data/lib/git-process/github_configuration.rb +298 -0
  38. data/lib/git-process/github_pull_request.rb +165 -0
  39. data/lib/git-process/new_fb.rb +49 -0
  40. data/lib/git-process/parked_changes_error.rb +41 -0
  41. data/lib/git-process/pull_request.rb +136 -0
  42. data/lib/git-process/pull_request_error.rb +25 -0
  43. data/lib/git-process/rebase_to_master.rb +148 -0
  44. data/lib/git-process/sync_process.rb +55 -0
  45. data/lib/git-process/syncer.rb +157 -0
  46. data/lib/git-process/uncommitted_changes_error.rb +23 -0
  47. data/lib/git-process/version.rb +22 -0
  48. data/local-build.rb +24 -0
  49. data/spec/FileHelpers.rb +19 -0
  50. data/spec/GitRepoHelper.rb +123 -0
  51. data/spec/changed_file_helper_spec.rb +127 -0
  52. data/spec/git_abstract_merge_error_builder_spec.rb +64 -0
  53. data/spec/git_branch_spec.rb +123 -0
  54. data/spec/git_config_spec.rb +45 -0
  55. data/spec/git_lib_spec.rb +176 -0
  56. data/spec/git_logger_spec.rb +66 -0
  57. data/spec/git_process_spec.rb +208 -0
  58. data/spec/git_remote_spec.rb +227 -0
  59. data/spec/git_status_spec.rb +122 -0
  60. data/spec/github_configuration_spec.rb +152 -0
  61. data/spec/github_pull_request_spec.rb +117 -0
  62. data/spec/github_test_helper.rb +49 -0
  63. data/spec/new_fb_spec.rb +126 -0
  64. data/spec/pull_request_helper.rb +94 -0
  65. data/spec/pull_request_spec.rb +137 -0
  66. data/spec/rebase_to_master_spec.rb +362 -0
  67. data/spec/spec_helper.rb +21 -0
  68. data/spec/sync_spec.rb +1474 -0
  69. metadata +249 -0
@@ -0,0 +1,64 @@
1
+ require 'git-process/git_abstract_merge_error_builder'
2
+ require 'git-process/git_lib'
3
+ require 'FileHelpers'
4
+
5
+ describe GitProc::AbstractMergeErrorBuilder do
6
+
7
+ def builder
8
+ @builder ||= GitProc::AbstractMergeErrorBuilder.new(gitlib, '', nil)
9
+ end
10
+
11
+
12
+ after(:each) do
13
+ rm_rf(gitlib.workdir)
14
+ end
15
+
16
+
17
+ def gitlib
18
+ if @lib.nil?
19
+ @lib = GitProc::GitLib.new(Dir.mktmpdir, :log_level => Logger::ERROR)
20
+ mock_status(@lib)
21
+ end
22
+ @lib
23
+ end
24
+
25
+
26
+ def metaclass(obj)
27
+ class << obj
28
+ self
29
+ end
30
+ end
31
+
32
+
33
+ def mock_status(lib)
34
+ spec = self
35
+ metaclass(lib).send(:define_method, :status) do
36
+ @status ||= spec.double('status')
37
+ end
38
+ end
39
+
40
+
41
+ def match_commands(expected)
42
+ commands = builder.commands
43
+ expected.each do |e|
44
+ commands.slice!(0).should == e
45
+ end
46
+ commands.should be_empty
47
+ end
48
+
49
+
50
+ it "merged with a file added in both branches" do
51
+ gitlib.status.stub(:unmerged).and_return(%w(a))
52
+ gitlib.status.stub(:modified).and_return(%w(b))
53
+ gitlib.status.stub(:added).and_return(%w(a c))
54
+
55
+ builder.resolved_files.should == %w()
56
+ builder.unresolved_files.should == %w(a)
57
+ c = [
58
+ '# \'a\' was added in both branches; Fix the conflict.',
59
+ 'git add a',
60
+ ]
61
+ match_commands c
62
+ end
63
+
64
+ end
@@ -0,0 +1,123 @@
1
+ require 'git-process/git_lib'
2
+ require 'GitRepoHelper'
3
+
4
+ describe GitProc::GitBranch do
5
+ include GitRepoHelper
6
+
7
+
8
+ def log_level
9
+ Logger::ERROR
10
+ end
11
+
12
+
13
+ before(:each) do
14
+ create_files(%w(.gitignore))
15
+ gitlib.commit('initial')
16
+ end
17
+
18
+
19
+ after(:each) do
20
+ rm_rf(gitlib.workdir)
21
+ end
22
+
23
+
24
+ describe 'contains_all_of' do
25
+
26
+ it 'should handle the trivial case' do
27
+ current = gitlib.branches.current
28
+ current.contains_all_of(current.name).should == true
29
+ end
30
+
31
+
32
+ it 'should handle new branch containing base branch that did not change' do
33
+ base_branch = gitlib.branches.current
34
+
35
+ gitlib.checkout('fb', :new_branch => base_branch.name)
36
+ current = gitlib.branches.current
37
+
38
+ change_file_and_commit('a', 'hello')
39
+
40
+ current.contains_all_of(base_branch.name).should == true
41
+ end
42
+
43
+
44
+ it "should handle new branch containing base branch that did change" do
45
+ base_branch = gitlib.branches.current
46
+
47
+ gitlib.checkout('fb', :new_branch => base_branch.name)
48
+ current = gitlib.branches.current
49
+
50
+ gitlib.checkout(base_branch.name)
51
+ change_file_and_commit('a', 'goodbye')
52
+
53
+ current.contains_all_of(base_branch.name).should == false
54
+ end
55
+
56
+
57
+ it 'should handle containing in both branches' do
58
+ base_branch = gitlib.branches.current
59
+
60
+ gitlib.checkout('fb', :new_branch => base_branch.name)
61
+ current = gitlib.branches.current
62
+
63
+ change_file_and_commit('a', 'hello')
64
+
65
+ gitlib.checkout(base_branch.name)
66
+ change_file_and_commit('a', 'goodbye')
67
+
68
+ current.contains_all_of(base_branch.name).should == false
69
+ end
70
+
71
+ end
72
+
73
+
74
+ describe "is_ahead_of" do
75
+
76
+ it "should handle the trivial case" do
77
+ current = gitlib.branches.current
78
+ current.is_ahead_of(current.name).should == false # same is not "ahead of"
79
+ end
80
+
81
+
82
+ it "should handle new branch containing base branch that did not change" do
83
+ base_branch = gitlib.branches.current
84
+
85
+ gitlib.checkout('fb', :new_branch => base_branch.name)
86
+ current = gitlib.branches.current
87
+
88
+ change_file_and_commit('a', 'hello')
89
+
90
+ current.is_ahead_of(base_branch.name).should == true
91
+ end
92
+
93
+
94
+ it "should handle new branch containing base branch that did change" do
95
+ base_branch = gitlib.branches.current
96
+
97
+ gitlib.checkout('fb', :new_branch => base_branch.name)
98
+ current = gitlib.branches.current
99
+
100
+ gitlib.checkout(base_branch.name)
101
+ change_file_and_commit('a', 'goodbye')
102
+
103
+ current.is_ahead_of(base_branch.name).should == false
104
+ end
105
+
106
+
107
+ it "should handle containing in both branches" do
108
+ base_branch = gitlib.branches.current
109
+
110
+ gitlib.checkout('fb', :new_branch => base_branch.name)
111
+ current = gitlib.branches.current
112
+
113
+ change_file_and_commit('a', 'hello')
114
+
115
+ gitlib.checkout(base_branch.name)
116
+ change_file_and_commit('a', 'goodbye')
117
+
118
+ current.is_ahead_of(base_branch.name).should == false
119
+ end
120
+
121
+ end
122
+
123
+ end
@@ -0,0 +1,45 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ require 'FileHelpers'
14
+ require 'git-process/git_lib'
15
+ require 'git-process/git_config'
16
+ include GitProc
17
+
18
+ describe GitConfig do
19
+
20
+ def tmpdir
21
+ @tmpdir ||= Dir.mktmpdir
22
+ end
23
+
24
+
25
+ after(:each) do
26
+ rm_rf(tmpdir)
27
+ end
28
+
29
+
30
+ it 'should retrieve values by []' do
31
+ lib = GitLib.new(tmpdir, :log_level => Logger::ERROR)
32
+ lib.command(:config, %w(somevalue.subvalue here))
33
+ config = GitConfig.new(lib)
34
+ config['somevalue.subvalue'].should == 'here'
35
+ end
36
+
37
+
38
+ it "should set values by []" do
39
+ lib = GitLib.new(tmpdir, :log_level => Logger::ERROR)
40
+ config = GitConfig.new(lib)
41
+ config['somevalue.subvalue'] = 'there'
42
+ lib.command(:config, %w(--get somevalue.subvalue)).should == 'there'
43
+ end
44
+
45
+ end
@@ -0,0 +1,176 @@
1
+ require 'git-process/git_lib'
2
+ require 'GitRepoHelper'
3
+ include GitProc
4
+
5
+
6
+ describe GitLib, :git_repo_helper do
7
+
8
+
9
+ def log_level
10
+ Logger::ERROR
11
+ end
12
+
13
+
14
+ describe 'workdir' do
15
+
16
+ it 'should use the passed in directory when the top level is a git workdir' do
17
+ dir = Dir.mktmpdir
18
+ mkdir_p "#{dir}/.git"
19
+ gitlib = GitLib.new(dir, :log_level => Logger::ERROR)
20
+ gitlib.workdir.should == dir
21
+ end
22
+
23
+
24
+ it "should find the parent git workdir" do
25
+ topdir = Dir.mktmpdir
26
+ mkdir_p "#{topdir}/.git"
27
+ dir = "#{topdir}/a/b/c/d/e/f/g"
28
+ mkdir_p dir
29
+ gitlib = GitLib.new(dir, :log_level => Logger::ERROR)
30
+ gitlib.workdir.should == topdir
31
+ end
32
+
33
+ end
34
+
35
+
36
+ describe 'branches' do
37
+
38
+ it 'list all the branches' do
39
+ gitlib.branch('ba', :base_branch => 'master')
40
+ gitlib.branch('bb', :base_branch => 'master')
41
+ gitlib.branch('origin/master', :base_branch => 'master')
42
+
43
+ gitlib.branches.names.should == %w(ba bb master origin/master)
44
+ end
45
+
46
+ end
47
+
48
+
49
+ describe 'fetch' do
50
+
51
+ it 'parse the list of changes' do
52
+ output = '''
53
+ remote: Counting objects: 1028, done.
54
+ remote: Compressing objects: 100% (301/301), done.
55
+ remote: Total 699 (delta 306), reused 654 (delta 273)
56
+ Receiving objects: 100% (699/699), 600.68 KiB | 686 KiB/s, done.
57
+ Resolving deltas: 100% (306/306), completed with 84 local objects.
58
+ From remote.system.com:tuser/test-proj
59
+ 8e667e0..19ecc91 SITE_TOUR_MODAL -> origin/SITE_TOUR_MODAL
60
+ + cea75d7...d656188 WEBCMS-2014 -> origin/WEBCMS-2014 (forced update)
61
+ * [new branch] WEBCMS-2047 -> origin/WEBCMS-2047
62
+ ca9e80e..d383005 WEBCMS-2157 -> origin/WEBCMS-2157
63
+ 77b5d5c..f485c7f WEBCMS-2159 -> origin/WEBCMS-2159
64
+ * [new branch] WEBCMS-2166 -> origin/WEBCMS-2166
65
+ c648f2a..86ee15e WEBCMS-2167 -> origin/WEBCMS-2167
66
+ * [new tag] RELEASE_1.0.1.53 -> RELEASE_1.0.1.53
67
+ * [new tag] RELEASE_1.0.1.54 -> RELEASE_1.0.1.54
68
+ x [deleted] (none) -> origin/WEBCMS-4650-resi-breadcrumbs
69
+ * [new branch] WEBCMS-2169 -> origin/WEBCMS-2169
70
+ * [new branch] base-carousel -> origin/base-carousel
71
+ 1de9c437..7546667 develop -> origin/develop
72
+ 90e8d75..23ae7d1 new-ui-smoketest -> origin/new-ui-smoketest
73
+ * [new branch] webcms-2023 -> origin/webcms-2023
74
+ b9797f8..dd24a9f webcms-2135 -> origin/webcms-2135
75
+ * [new branch] webcms-831-faq-web-service -> origin/webcms-831-faq-web-service
76
+ x [deleted] (none) -> origin/webcms-1315-masthead
77
+ '''
78
+ changes = gitlib.fetch_changes(output)
79
+
80
+ changes[:new_branch].size().should == 6
81
+ changes[:new_tag].size().should == 2
82
+ changes[:deleted].size().should == 2
83
+ changes[:force_updated].size().should == 1
84
+ changes[:updated].size().should == 7
85
+
86
+ empty_changes = gitlib.fetch_changes('')
87
+
88
+ empty_changes[:new_branch].size().should == 0
89
+ empty_changes[:new_tag].size().should == 0
90
+ empty_changes[:deleted].size().should == 0
91
+ empty_changes[:force_updated].size().should == 0
92
+ empty_changes[:updated].size().should == 0
93
+ end
94
+
95
+ end
96
+
97
+
98
+ describe "branch" do
99
+
100
+ it "should create a branch with default base" do
101
+ gitlib.stub(:command).with(:branch, %w(test_branch master))
102
+ gitlib.branch('test_branch')
103
+ end
104
+
105
+
106
+ it "should create a branch with explicit base" do
107
+ gitlib.should_receive(:command).with(:branch, %w(test_branch other_branch))
108
+ gitlib.branch('test_branch', :base_branch => 'other_branch')
109
+ end
110
+
111
+
112
+ it 'should delete a branch without force' do
113
+ gitlib.should_receive(:command).with(:branch, %w(-d test_branch))
114
+ gitlib.branch('test_branch', :delete => true)
115
+ end
116
+
117
+
118
+ it 'should delete a branch with force' do
119
+ gitlib.should_receive(:command).with(:branch, %w(-D test_branch))
120
+ gitlib.branch('test_branch', :delete => true, :force => true)
121
+ end
122
+
123
+
124
+ it "should rename a branch" do
125
+ gitlib.should_receive(:command).with(:branch, %w(-m test_branch new_branch))
126
+ gitlib.branch('test_branch', :rename => 'new_branch')
127
+ end
128
+
129
+ end
130
+
131
+
132
+ describe "push" do
133
+
134
+ it "should push local branch to remote" do
135
+ gitlib.should_receive(:command).with(:push, %w(remote local_branch:test_branch))
136
+
137
+ gitlib.push('remote', 'local_branch', 'test_branch')
138
+ end
139
+
140
+
141
+ it "should push current branch to remote" do
142
+ gitlib.stub(:command).with(:branch, %w(-a --no-color)).and_return("* my_branch\n")
143
+ gitlib.should_receive(:command).with(:push, %w(remote my_branch:my_branch))
144
+
145
+ gitlib.push('remote', 'my_branch', nil)
146
+ end
147
+
148
+
149
+ it "should remove named branch on remote" do
150
+ gitlib.remote.stub(:name).and_return('remote_server')
151
+ gitlib.config.stub(:master_branch).and_return('master')
152
+ gitlib.should_receive(:command).with(:push, %w(remote_server --delete my_branch))
153
+
154
+ gitlib.push('remote_server', 'my_branch', nil, :delete => true)
155
+ end
156
+
157
+
158
+ it "should remove current branch on remote" do
159
+ gitlib.remote.stub(:name).and_return('remote_server')
160
+ gitlib.config.stub(:master_branch).and_return('master')
161
+ gitlib.should_receive(:command).with(:push, %w(remote_server --delete my_branch))
162
+
163
+ gitlib.push('remote_server', nil, nil, :delete => 'my_branch')
164
+ end
165
+
166
+
167
+ it "should not remove integration branch on remote" do
168
+ gitlib.remote.stub(:name).and_return('remote_server')
169
+ gitlib.config.stub(:master_branch).and_return('master')
170
+
171
+ expect { gitlib.push('remote_server', nil, nil, :delete => 'master') }.to raise_error GitProcessError
172
+ end
173
+
174
+ end
175
+
176
+ end
@@ -0,0 +1,66 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ require 'git-process/git_logger'
14
+ include GitProc
15
+
16
+ describe GitLogger do
17
+
18
+ it 'should log info blocks' do
19
+ val = false
20
+ GitLogger.new(GitLogger::INFO, nil).info { val = true }
21
+ val.should == true
22
+ end
23
+
24
+
25
+ it 'should not log info blocks by default' do
26
+ val = false
27
+ GitLogger.new(nil, nil).info { val = true }
28
+ val.should == false
29
+ end
30
+
31
+
32
+ it 'should log warn blocks' do
33
+ val = false
34
+ GitLogger.new(GitLogger::WARN, nil).warn { val = true }
35
+ val.should == true
36
+ end
37
+
38
+
39
+ it "should log warn blocks by default" do
40
+ val = false
41
+ GitLogger.new(nil, nil).warn { val = true }
42
+ val.should == true
43
+ end
44
+
45
+
46
+ it "should log error blocks" do
47
+ val = false
48
+ GitLogger.new(GitLogger::ERROR, nil).error { val = true }
49
+ val.should == true
50
+ end
51
+
52
+
53
+ it "should log error blocks by default" do
54
+ val = false
55
+ GitLogger.new.error { val = true }
56
+ val.should == true
57
+ end
58
+
59
+
60
+ it 'should log debug blocks' do
61
+ val = false
62
+ GitLogger.new(GitLogger::DEBUG, nil).debug { val = true }
63
+ val.should == true
64
+ end
65
+
66
+ end