git-process 1.1.4 → 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 (58) hide show
  1. data/CHANGELOG.md +14 -1
  2. data/LICENSE +193 -22
  3. data/README.md +212 -71
  4. data/man/git-process.1 +371 -0
  5. metadata +52 -140
  6. data/Gemfile +0 -20
  7. data/Gemfile.lock +0 -53
  8. data/Rakefile +0 -16
  9. data/bin/git-new-fb +0 -58
  10. data/bin/git-pull-request +0 -107
  11. data/bin/git-sync +0 -73
  12. data/bin/git-to-master +0 -133
  13. data/git-process.gemspec +0 -25
  14. data/lib/git-process/abstract_error_builder.rb +0 -53
  15. data/lib/git-process/changed_file_helper.rb +0 -115
  16. data/lib/git-process/git_abstract_merge_error_builder.rb +0 -146
  17. data/lib/git-process/git_branch.rb +0 -105
  18. data/lib/git-process/git_branches.rb +0 -73
  19. data/lib/git-process/git_config.rb +0 -153
  20. data/lib/git-process/git_lib.rb +0 -512
  21. data/lib/git-process/git_logger.rb +0 -84
  22. data/lib/git-process/git_merge_error.rb +0 -28
  23. data/lib/git-process/git_process.rb +0 -172
  24. data/lib/git-process/git_process_error.rb +0 -18
  25. data/lib/git-process/git_process_options.rb +0 -99
  26. data/lib/git-process/git_rebase_error.rb +0 -30
  27. data/lib/git-process/git_remote.rb +0 -256
  28. data/lib/git-process/git_status.rb +0 -108
  29. data/lib/git-process/github_configuration.rb +0 -298
  30. data/lib/git-process/github_pull_request.rb +0 -151
  31. data/lib/git-process/new_fb.rb +0 -50
  32. data/lib/git-process/parked_changes_error.rb +0 -41
  33. data/lib/git-process/pull_request.rb +0 -134
  34. data/lib/git-process/pull_request_error.rb +0 -25
  35. data/lib/git-process/rebase_to_master.rb +0 -148
  36. data/lib/git-process/sync.rb +0 -136
  37. data/lib/git-process/uncommitted_changes_error.rb +0 -23
  38. data/lib/git-process/version.rb +0 -22
  39. data/spec/FileHelpers.rb +0 -19
  40. data/spec/GitRepoHelper.rb +0 -123
  41. data/spec/changed_file_helper_spec.rb +0 -127
  42. data/spec/git_abstract_merge_error_builder_spec.rb +0 -126
  43. data/spec/git_branch_spec.rb +0 -123
  44. data/spec/git_config_spec.rb +0 -45
  45. data/spec/git_lib_spec.rb +0 -176
  46. data/spec/git_logger_spec.rb +0 -66
  47. data/spec/git_process_spec.rb +0 -208
  48. data/spec/git_remote_spec.rb +0 -227
  49. data/spec/git_status_spec.rb +0 -122
  50. data/spec/github_configuration_spec.rb +0 -152
  51. data/spec/github_pull_request_spec.rb +0 -96
  52. data/spec/github_test_helper.rb +0 -49
  53. data/spec/new_fb_spec.rb +0 -130
  54. data/spec/pull_request_helper.rb +0 -94
  55. data/spec/pull_request_spec.rb +0 -128
  56. data/spec/rebase_to_master_spec.rb +0 -429
  57. data/spec/spec_helper.rb +0 -21
  58. data/spec/sync_spec.rb +0 -304
@@ -1,50 +0,0 @@
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_process'
14
-
15
- module GitProc
16
-
17
- class NewFeatureBranch < Process
18
-
19
- def initialize(dir, opts)
20
- @branch_name = opts[:branch_name]
21
- super
22
- end
23
-
24
-
25
- def runner
26
- mybranches = gitlib.branches()
27
- on_parking = (mybranches.parking == mybranches.current)
28
-
29
- if on_parking
30
- base_branch = if mybranches[config.integration_branch].contains_all_of(mybranches.parking.name)
31
- config.integration_branch
32
- else
33
- '_parking_'
34
- end
35
-
36
- logger.info { "Creating #{@branch_name} off of #{base_branch}" }
37
- new_branch = gitlib.checkout(@branch_name, :new_branch => base_branch)
38
-
39
- branches = gitlib.branches()
40
- branches[@branch_name].upstream(config.integration_branch)
41
- branches.parking.delete!
42
- new_branch
43
- else
44
- gitlib.checkout(@branch_name, :new_branch => config.integration_branch)
45
- end
46
- end
47
-
48
- end
49
-
50
- end
@@ -1,41 +0,0 @@
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_process_error'
14
-
15
- module GitProc
16
-
17
- class ParkedChangesError < GitProcessError
18
- include GitProc::AbstractErrorBuilder
19
-
20
- attr_reader :error_message, :lib
21
-
22
-
23
- def initialize(lib)
24
- @lib = lib
25
- msg = build_message
26
- super(msg)
27
- end
28
-
29
-
30
- def human_message
31
- "You made your changes on the the '_parking_' branch instead of a feature branch.\n"+'Please rename the branch to be a feature branch.'
32
- end
33
-
34
-
35
- def build_commands
36
- ['git branch -m _parking_ my_feature_branch']
37
- end
38
-
39
- end
40
-
41
- end
@@ -1,134 +0,0 @@
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_process'
14
- require 'git-process/github_pull_request'
15
- require 'git-process/pull_request_error'
16
- require 'highline/import'
17
-
18
-
19
- module GitProc
20
-
21
- class PullRequest < Process
22
-
23
- def initialize(dir, opts)
24
- super
25
- @base_branch = opts[:base_branch]
26
- @head_branch = opts[:head_branch]
27
- @_repo_name = opts[:repo_name]
28
- @_remote_name = opts[:server]
29
- @pr_number = opts[:prNumber]
30
- @title = opts[:title]
31
- @description = opts[:description]
32
- @user = opts[:user]
33
- @password = opts[:password]
34
- end
35
-
36
-
37
- def runner
38
- if @pr_number.nil? or @pr_number.empty?
39
- pr = create_pull_request
40
- logger.info { "Created pull request at #{pr.html_url}" }
41
- else
42
- checkout_pull_request
43
- end
44
- end
45
-
46
-
47
- def create_pull_request_client(remote_name, repo_name)
48
- PullRequest.create_pull_request_client(self, remote_name, repo_name, @user, @password)
49
- end
50
-
51
-
52
- def create_pull_request
53
- current_branch = gitlib.branches.current.name
54
- base_branch = @base_branch || config.master_branch
55
- head_branch = @head_branch || current_branch
56
- title = @title || current_branch
57
- description = @description || ''
58
-
59
- PullRequest.create_pull_request(gitlib, remote.name, remote.name, remote.repo_name, current_branch, base_branch, head_branch, title, description, logger, @user, @password)
60
- end
61
-
62
-
63
- def checkout_pull_request
64
- PullRequest.checkout_pull_request(gitlib, @pr_number, remote.name, remote.repo_name, @user, @password, logger)
65
- end
66
-
67
-
68
- class << self
69
-
70
- def create_pull_request_client(lib, remote_name, repo_name, username, password)
71
- GitHub::PullRequest.new(lib, remote_name, repo_name, {:user => username, :password => password})
72
- end
73
-
74
-
75
- def create_pull_request(lib, server_name, remote_name, repo_name, current_branch, base_branch, head_branch, title, description, logger, username, password)
76
- if base_branch == head_branch
77
- raise PullRequestError.new("Can not create a pull request where the base branch and head branch are the same: #{base_branch}")
78
- end
79
-
80
- lib.push(server_name, current_branch, current_branch, :force => false)
81
- pr = create_pull_request_client(lib, remote_name, repo_name, username, password)
82
- pr.create(base_branch, head_branch, title, description)
83
- end
84
-
85
-
86
- def checkout_pull_request(lib, pr_number, remote_name, repo_name, username, password, logger)
87
- logger.info { 'Getting #pr_number' }
88
-
89
- lib.fetch(remote_name)
90
-
91
- pr = create_pull_request_client(lib, remote_name, repo_name, username, password)
92
- json = pr.pull_request(pr_number)
93
- head_branch_name = json.head.ref
94
- base_branch_name = json.base.ref
95
-
96
- remote_head_server_name = match_remote_to_pr_remote(lib, json.head.repo.ssh_url)
97
- remote_base_server_name = match_remote_to_pr_remote(lib, json.base.repo.ssh_url)
98
- lib.checkout(head_branch_name, :new_branch => "#{remote_head_server_name}/#{head_branch_name}")
99
- lib.branch(head_branch_name, :upstream => "#{remote_base_server_name}/#{base_branch_name}")
100
- #logger.info(json.to_hash)
101
-
102
- lib.fetch(remote_base_server_name) if remote_head_server_name != remote_base_server_name
103
- end
104
-
105
-
106
- def match_remote_to_pr_remote(lib, pr_remote)
107
- pr_url = lib.remote.expanded_url(nil, pr_remote)
108
- servers = lib.remote.remote_names
109
- server_urls = servers.collect { |s| {:server_name => s, :url => lib.remote.expanded_url(s)} }
110
-
111
- pair = server_urls.find do |su|
112
- url = su[:url]
113
- uri = URI.parse(url)
114
- host = uri.host
115
- path = uri.path
116
-
117
- pr_uri = URI.parse(lib.remote.expanded_url(nil, pr_url))
118
- pr_host = pr_uri.host
119
- pr_path = pr_uri.path
120
-
121
- pr_host == host and pr_path == path
122
- end
123
-
124
- if pair.nil?
125
- raise GitHubService::NoRemoteRepository.new("Could not match pull request url (#{pr_url}) to any of the registered remote urls: #{server_urls.map {|s| '{' + s[:server_name] + ': ' + s[:url] + '}'}.join(', ')}")
126
- end
127
-
128
- pair[:server_name]
129
- end
130
-
131
- end
132
-
133
- end
134
- end
@@ -1,25 +0,0 @@
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_process_error'
14
-
15
- module GitProc
16
-
17
- class PullRequestError < GitProcessError
18
-
19
- def initialize(msg)
20
- super(msg)
21
- end
22
-
23
- end
24
-
25
- end
@@ -1,148 +0,0 @@
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_process'
14
- require 'git-process/git_rebase_error'
15
- require 'git-process/git_process_error'
16
- require 'git-process/parked_changes_error'
17
- require 'git-process/uncommitted_changes_error'
18
- require 'git-process/github_pull_request'
19
- require 'git-process/pull_request'
20
-
21
-
22
- module GitProc
23
-
24
- class RebaseToMaster < Process
25
-
26
- def initialize(dir, opts)
27
- @keep = opts[:keep]
28
- @interactive = opts[:interactive]
29
- @pr_number = opts[:prNumber]
30
- @user = opts[:user]
31
- @password = opts[:password]
32
- super
33
- end
34
-
35
-
36
- def verify_preconditions
37
- super
38
-
39
- raise UncommittedChangesError.new unless gitlib.status.clean?
40
- raise ParkedChangesError.new(gitlib) if is_parked?
41
- end
42
-
43
-
44
- def runner
45
- if remote.exists?
46
- gitlib.fetch(remote.name)
47
-
48
- unless @pr_number.nil? or @pr_number.empty?
49
- checkout_pull_request
50
- end
51
-
52
- proc_rebase(config.integration_branch)
53
- proc_rebase(config.integration_branch, :interactive => true) if @interactive
54
- current = gitlib.branches.current.name
55
- gitlib.push(remote.name, current, config.master_branch)
56
-
57
- unless @keep
58
- close_pull_request
59
- remove_feature_branch
60
- end
61
- else
62
- proc_rebase(config.integration_branch)
63
- end
64
- end
65
-
66
-
67
- def checkout_pull_request
68
- PullRequest.checkout_pull_request(gitlib, @pr_number, remote.name, remote.repo_name, @user, @password, logger)
69
- end
70
-
71
-
72
- def remove_feature_branch
73
- mybranches = gitlib.branches
74
-
75
- remote_master = mybranches[remote.master_branch_name]
76
- current_branch = mybranches.current
77
- logger.debug { "Removing feature branch (#{current_branch})" }
78
-
79
- unless remote_master.contains_all_of(current_branch.name)
80
- raise GitProcessError.new("Branch '#{current_branch.name}' has not been merged into '#{remote.master_branch_name}'")
81
- end
82
-
83
- parking_branch = mybranches['_parking_']
84
- if parking_branch
85
- if parking_branch.is_ahead_of(remote_master.name) and
86
- !current_branch.contains_all_of(parking_branch.name)
87
-
88
- parking_branch.rename('_parking_OLD_')
89
-
90
- logger.warn { bad_parking_branch_msg }
91
- else
92
- parking_branch.delete!
93
- end
94
- end
95
- remote_master.checkout_to_new('_parking_', :no_track => true)
96
-
97
- current_branch.delete!(true)
98
- if mybranches["#{remote.name}/#{current_branch.name}"]
99
- gitlib.push(remote.name, nil, nil, :delete => current_branch.name)
100
- end
101
- end
102
-
103
-
104
- def close_pull_request
105
- pr = GitHub::PullRequest.new(gitlib, remote.name, remote.repo_name)
106
-
107
- # Assume that if we haven't done something that would create the
108
- # GitHub auth token, then this likely isn't a GitHub-based repo.
109
- # (Or at least the user isn't using pull requests)
110
- if pr.configuration.get_config_auth_token
111
- begin
112
- if @pr_number
113
- pr.close(@pr_number)
114
- else
115
- mybranches = gitlib.branches()
116
- pull = pr.find_pull_request(config.master_branch, mybranches.current.name)
117
- if pull
118
- pr.close(pull[:number])
119
- else
120
- logger.debug { "There is no pull request for #{mybranches.current.name} against #{config.master_branch}" }
121
- end
122
- end
123
- rescue GitHubService::NoRemoteRepository => exp
124
- logger.debug exp.to_s
125
- end
126
- else
127
- logger.debug 'There is no GitHub auth token defined, so not trying to close a pull request.'
128
- end
129
- end
130
-
131
-
132
- private
133
-
134
-
135
- def bad_parking_branch_msg
136
- hl = HighLine.new
137
- hl.color(
138
- "\n***********************************************************************************************\n\n"+
139
- "There is an old '_parking_' branch with unacounted changes in it.\n"+
140
- "It has been renamed to '_parking_OLD_'.\n"+
141
- "Please rename the branch to what the changes are about (`git branch -m _parking_OLD_ my_fb_name`),\n"+
142
- " or remove it altogher (`git branch -D _parking_OLD_`).\n\n"+
143
- "***********************************************************************************************\n", :red, :bold)
144
- end
145
-
146
- end
147
-
148
- end
@@ -1,136 +0,0 @@
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_lib'
14
- require 'git-process/git_process'
15
- require 'git-process/parked_changes_error'
16
- require 'git-process/uncommitted_changes_error'
17
- require 'git-process/changed_file_helper'
18
-
19
-
20
- module GitProc
21
-
22
- class Sync < Process
23
-
24
- def initialize(base, opts)
25
- if !opts[:merge].nil? and opts[:merge] == opts[:rebase]
26
- raise ArgumentError.new(":merge = #{opts[:merge]} and :rebase = #{opts[:rebase]}")
27
- end
28
-
29
- raise ArgumentError.new(':rebase is not set') if opts[:rebase].nil?
30
-
31
- @do_rebase = opts[:rebase]
32
- @force = opts[:force]
33
- @local = opts[:local]
34
-
35
- super
36
-
37
- @change_file_helper = ChangeFileHelper.new(gitlib)
38
- self
39
- end
40
-
41
-
42
- #noinspection RubyControlFlowConversionInspection
43
- def verify_preconditions
44
- super
45
-
46
- if not gitlib.status.clean?
47
- @change_file_helper.offer_to_help_uncommitted_changes
48
- end
49
-
50
- raise ParkedChangesError.new(self) if is_parked?
51
- end
52
-
53
-
54
- def cleanup
55
- gitlib.stash_pop if @stash_pushed
56
- end
57
-
58
-
59
- def remote_branch_sha
60
- gitlib.rev_parse(@remote_branch) rescue ''
61
- end
62
-
63
-
64
- def current_branch
65
- @current_branch ||= gitlib.branches.current
66
- end
67
-
68
-
69
- def runner
70
- @remote_branch ||= "#{remote.name}/#{current_branch}"
71
-
72
- # if the remote branch has changed, merge those changes in before
73
- # doing anything with the integration branch
74
- if remote_has_changed?
75
- logger.info('There have been changes on this remote branch, so will merge them in.')
76
- proc_merge(@remote_branch)
77
- end
78
-
79
- if do_rebase?
80
- @force = true
81
- proc_rebase(config.integration_branch)
82
- else
83
- proc_merge(config.integration_branch)
84
- end
85
-
86
- push_to_server
87
- end
88
-
89
-
90
- private
91
-
92
-
93
- def remote_has_changed?
94
- old_sha = remote_branch_sha
95
- fetch_remote_changes
96
- new_sha = remote_branch_sha
97
-
98
- old_sha != new_sha
99
- end
100
-
101
-
102
- def do_rebase?
103
- @do_rebase ||= config['gitProcess.defaultRebaseSync'].to_boolean
104
- end
105
-
106
-
107
- def push_to_server
108
- if @local
109
- logger.debug('Not pushing to the server because the user selected local-only.')
110
- elsif not gitlib.has_a_remote?
111
- logger.debug('Not pushing to the server because there is no remote.')
112
- elsif @current_branch == config.master_branch
113
- logger.warn('Not pushing to the server because the current branch is the mainline branch.')
114
- else
115
- handle_remote_changed
116
-
117
- gitlib.push(remote.name, @current_branch, @current_branch, :force => @force)
118
- end
119
- end
120
-
121
-
122
- def handle_remote_changed
123
- old_sha = remote_branch_sha
124
- fetch_remote_changes
125
- new_sha = remote_branch_sha
126
-
127
- unless old_sha == new_sha
128
- logger.warn("'#{@current_branch}' changed on '#{config.server_name}'"+
129
- " [#{old_sha[0..5]}->#{new_sha[0..5]}]; trying sync again.")
130
- runner # try again
131
- end
132
- end
133
-
134
- end
135
-
136
- end