git-process 0.9.1.pre3 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +0 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +2 -0
- data/README.md +27 -9
- data/bin/git-new-fb +42 -13
- data/bin/git-pull-request +79 -13
- data/bin/git-sync +47 -13
- data/bin/git-to-master +56 -13
- data/git-process.gemspec +1 -1
- data/lib/git-process/{abstract-error-builder.rb → abstract_error_builder.rb} +13 -3
- data/lib/git-process/{git-abstract-merge-error-builder.rb → git_abstract_merge_error_builder.rb} +15 -5
- data/lib/git-process/{git-branch.rb → git_branch.rb} +13 -1
- data/lib/git-process/git_branches.rb +72 -0
- data/lib/git-process/{git-lib.rb → git_lib.rb} +82 -70
- data/lib/git-process/git_merge_error.rb +38 -0
- data/lib/git-process/git_process.rb +124 -0
- data/lib/git-process/git_process_error.rb +18 -0
- data/lib/git-process/git_process_options.rb +101 -0
- data/lib/git-process/git_rebase_error.rb +38 -0
- data/lib/git-process/{git-status.rb → git_status.rb} +13 -1
- data/lib/git-process/{github-client.rb → github_client.rb} +13 -1
- data/lib/git-process/github_pull_request.rb +107 -0
- data/lib/git-process/{github-service.rb → github_service.rb} +39 -21
- data/lib/git-process/new_fb.rb +40 -0
- data/lib/git-process/parked_changes_error.rb +40 -0
- data/lib/git-process/pull_request.rb +61 -0
- data/lib/git-process/rebase_to_master.rb +110 -0
- data/lib/git-process/sync.rb +63 -0
- data/lib/git-process/uncommitted_changes_error.rb +23 -0
- data/lib/git-process/version.rb +19 -9
- data/spec/GitRepoHelper.rb +35 -21
- data/spec/{git-abstract-merge-error-builder_spec.rb → git_abstract_merge_error_builder_spec.rb} +3 -3
- data/spec/{git-lib_spec.rb → git_lib_spec.rb} +79 -16
- data/spec/git_process_spec.rb +36 -0
- data/spec/{git-status_spec.rb → git_status_spec.rb} +28 -29
- data/spec/github_pull_request_spec.rb +91 -0
- data/spec/{github-service_spec.rb → github_service_spec.rb} +1 -1
- data/spec/new_fb_spec.rb +80 -0
- data/spec/rebase_to_master_spec.rb +314 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/sync_spec.rb +149 -0
- metadata +46 -43
- data/lib/git-process/git-branches.rb +0 -53
- data/lib/git-process/git-merge-error.rb +0 -31
- data/lib/git-process/git-new-fb-options.rb +0 -34
- data/lib/git-process/git-process-error.rb +0 -10
- data/lib/git-process/git-process-options.rb +0 -82
- data/lib/git-process/git-process.rb +0 -194
- data/lib/git-process/git-pull-request-options.rb +0 -42
- data/lib/git-process/git-rebase-error.rb +0 -31
- data/lib/git-process/git-sync-options.rb +0 -34
- data/lib/git-process/git-to-master-options.rb +0 -18
- data/lib/git-process/parked-changes-error.rb +0 -32
- data/lib/git-process/pull-request.rb +0 -38
- data/lib/git-process/uncommitted-changes-error.rb +0 -15
- data/spec/git-process_spec.rb +0 -328
- data/spec/pull-request_spec.rb +0 -57
@@ -0,0 +1,107 @@
|
|
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.require 'shellwords'
|
12
|
+
|
13
|
+
require 'git-process/github_service'
|
14
|
+
require 'octokit'
|
15
|
+
require 'octokit/repository'
|
16
|
+
|
17
|
+
|
18
|
+
module GitHub
|
19
|
+
|
20
|
+
class PullRequest
|
21
|
+
include GitHubService
|
22
|
+
|
23
|
+
attr_reader :lib, :repo
|
24
|
+
|
25
|
+
def initialize(lib, repo, opts = {})
|
26
|
+
@lib = lib
|
27
|
+
@repo = repo
|
28
|
+
@user = opts[:user]
|
29
|
+
@password = opts[:password]
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def pull_requests
|
34
|
+
@pull_requests ||= client.pull_requests(repo)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def create(base, head, title, body)
|
39
|
+
logger.info { "Creating a pull request asking for '#{head}' to be merged into '#{base}' on #{repo}." }
|
40
|
+
begin
|
41
|
+
client.create_pull_request(repo, base, head, title, body)
|
42
|
+
rescue Octokit::UnprocessableEntity => exp
|
43
|
+
pull = pull_requests.find {|p| p[:head][:ref] == head and p[:base][:ref] == base}
|
44
|
+
logger.warn { "Pull request already exists. See #{pull[:html_url]}" }
|
45
|
+
pull
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def find_pull_request(base, head)
|
51
|
+
json = pull_requests
|
52
|
+
json.find {|p| p[:head][:ref] == head and p[:base][:ref] == base}
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
def close(*args)
|
57
|
+
pull_number = nil
|
58
|
+
|
59
|
+
if args.size == 2
|
60
|
+
base = args[0]
|
61
|
+
head = args[1]
|
62
|
+
logger.info { "Closing a pull request asking for '#{head}' to be merged into '#{base}' on #{repo}." }
|
63
|
+
|
64
|
+
json = pull_requests
|
65
|
+
pull = json.find {|p| p[:head][:ref] == head and p[:base][:ref] == base}
|
66
|
+
|
67
|
+
raise NotFoundError.new(base, head, repo, json) if pull.nil?
|
68
|
+
|
69
|
+
pull_number = pull[:number]
|
70
|
+
elsif args.size == 1
|
71
|
+
pull_number = args[0]
|
72
|
+
logger.info { "Closing a pull request \##{pull_number} on #{repo}." }
|
73
|
+
end
|
74
|
+
|
75
|
+
client.patch("repos/#{Octokit::Repository.new(repo)}/pulls/#{pull_number}", {:state => 'closed'})
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
class NotFoundError < StandardError
|
80
|
+
attr_reader :base, :head, :repo
|
81
|
+
|
82
|
+
def initialize(base, head, repo, pull_requests_json)
|
83
|
+
@base = base
|
84
|
+
@head = head
|
85
|
+
@repo = repo
|
86
|
+
|
87
|
+
@pull_requests = pull_requests_json.map do |p|
|
88
|
+
{:head => p[:head][:ref], :base => p[:base][:ref]}
|
89
|
+
end
|
90
|
+
|
91
|
+
msg = "Could not find a pull request for '#{head}' to be merged with '#{base}' on #{repo}."
|
92
|
+
msg += "\n\nExisting Pull Requests:"
|
93
|
+
msg = pull_requests.inject(msg) {|a,v| "#{a}\n #{v[:head]} -> #{v[:base]}" }
|
94
|
+
|
95
|
+
super(msg)
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
def pull_requests
|
100
|
+
@pull_requests
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
@@ -1,12 +1,24 @@
|
|
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.require 'shellwords'
|
12
|
+
|
1
13
|
require 'highline/import'
|
2
|
-
require '
|
14
|
+
require 'git-process/github_client'
|
3
15
|
require 'uri'
|
4
16
|
|
5
17
|
|
6
18
|
module GitHubService
|
7
19
|
|
8
20
|
def client
|
9
|
-
|
21
|
+
if @client.nil?
|
10
22
|
auth_token
|
11
23
|
logger.debug { "Creating GitHub client for user #{user} using token '#{auth_token}'" }
|
12
24
|
@client = GitHubClient.new(:login => user, :oauth_token=> auth_token)
|
@@ -36,11 +48,13 @@ module GitHubService
|
|
36
48
|
|
37
49
|
raise URI::InvalidURIError.new("Need a scheme in URI: '#{origin_url}'") unless scheme
|
38
50
|
|
39
|
-
|
51
|
+
if host.nil?
|
40
52
|
# assume that the 'scheme' is the named configuration in ~/.ssh/config
|
41
53
|
host = hostname_from_ssh_config(scheme, opts[:ssh_config_file] ||= "#{ENV['HOME']}/.ssh/config")
|
42
54
|
end
|
43
55
|
|
56
|
+
raise GitHubService::NoRemoteRepository.new("Could not determine a host from #{origin_url}") if host.nil?
|
57
|
+
|
44
58
|
site = host_to_site(host, scheme == 'https')
|
45
59
|
end
|
46
60
|
site
|
@@ -48,23 +62,27 @@ module GitHubService
|
|
48
62
|
|
49
63
|
|
50
64
|
def hostname_from_ssh_config(host_alias, config_file)
|
51
|
-
|
65
|
+
if File.exists?(config_file)
|
66
|
+
config_lines = File.new(config_file).readlines
|
52
67
|
|
53
|
-
|
54
|
-
|
68
|
+
in_host_section = false
|
69
|
+
host_name = nil
|
55
70
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
71
|
+
sections = config_lines.each do |line|
|
72
|
+
line.chop!
|
73
|
+
if /^\s*Host\s+#{host_alias}\s*$/ =~ line
|
74
|
+
in_host_section = true
|
75
|
+
next
|
76
|
+
end
|
77
|
+
if in_host_section and (/^\s*HostName\s+\S+\s*$/ =~ line)
|
78
|
+
host_name = line.sub(/^\s*HostName\s+(\S+)\s*$/, '\1')
|
79
|
+
break
|
80
|
+
end
|
65
81
|
end
|
82
|
+
host_name
|
83
|
+
else
|
84
|
+
nil
|
66
85
|
end
|
67
|
-
host_name
|
68
86
|
end
|
69
87
|
|
70
88
|
|
@@ -93,7 +111,7 @@ module GitHubService
|
|
93
111
|
def user
|
94
112
|
unless @user
|
95
113
|
user = lib.config('github.user')
|
96
|
-
if user.empty?
|
114
|
+
if user.nil? or user.empty?
|
97
115
|
user = ask("Your <%= color('GitHub', [:bold, :blue]) %> username: ") do |q|
|
98
116
|
q.validate = /^\w\w+$/
|
99
117
|
end
|
@@ -108,7 +126,7 @@ module GitHubService
|
|
108
126
|
def password
|
109
127
|
unless @password
|
110
128
|
@password = ask("Your <%= color('GitHub', [:bold, :blue]) %> password: ") do |q|
|
111
|
-
q.validate = /^\
|
129
|
+
q.validate = /^\S\S+$/
|
112
130
|
q.echo = 'x'
|
113
131
|
end
|
114
132
|
end
|
@@ -122,7 +140,7 @@ module GitHubService
|
|
122
140
|
|
123
141
|
|
124
142
|
def create_authorization
|
125
|
-
logger.info("Authorizing
|
143
|
+
logger.info("Authorizing #{user} to work with #{site}.")
|
126
144
|
auth = pw_client.create_authorization(:scopes => ['repo', 'user', 'gist'],
|
127
145
|
:note => 'Git-Process',
|
128
146
|
:note_url => 'http://jdigger.github.com/git-process')
|
@@ -133,9 +151,9 @@ module GitHubService
|
|
133
151
|
|
134
152
|
|
135
153
|
def config_auth_token
|
136
|
-
|
154
|
+
if @auth_token.nil?
|
137
155
|
c_auth_token = lib.config('gitProcess.github.authToken')
|
138
|
-
@auth_token = c_auth_token.empty? ? nil : c_auth_token
|
156
|
+
@auth_token = (c_auth_token.nil? or c_auth_token.empty?) ? nil : c_auth_token
|
139
157
|
end
|
140
158
|
@auth_token
|
141
159
|
end
|
@@ -0,0 +1,40 @@
|
|
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.require 'shellwords'
|
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 = branches()
|
27
|
+
on_parking = (mybranches.parking == mybranches.current)
|
28
|
+
|
29
|
+
if on_parking
|
30
|
+
new_branch = checkout(@branch_name, :new_branch => '_parking_')
|
31
|
+
mybranches.parking.delete
|
32
|
+
new_branch
|
33
|
+
else
|
34
|
+
checkout(@branch_name, :new_branch => remote_master_branch)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,40 @@
|
|
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.require 'shellwords'
|
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
|
+
def initialize(lib)
|
23
|
+
@lib = lib
|
24
|
+
msg = build_message
|
25
|
+
super(msg)
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def human_message
|
30
|
+
"You made your changes on the the '_parking_' branch instead of a feature branch.\n"+"Please rename the branch to be a feature branch."
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def build_commands
|
35
|
+
['git branch -m _parking_ my_feature_branch']
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,61 @@
|
|
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.require 'shellwords'
|
12
|
+
|
13
|
+
require 'git-process/git_process'
|
14
|
+
require 'git-process/github_pull_request'
|
15
|
+
require 'highline/import'
|
16
|
+
|
17
|
+
|
18
|
+
module GitProc
|
19
|
+
|
20
|
+
class PullRequest < Process
|
21
|
+
include GitLib
|
22
|
+
|
23
|
+
|
24
|
+
def initialize(dir, opts)
|
25
|
+
super
|
26
|
+
@title = opts[:title]
|
27
|
+
@base_branch = opts[:base_branch] || master_branch
|
28
|
+
@head_branch = opts[:head_branch] || branches.current
|
29
|
+
@repo_name = opts[:repo_name] || repo_name()
|
30
|
+
@title = opts[:title] || ask_for_pull_title()
|
31
|
+
@description = opts[:description] || ask_for_pull_description()
|
32
|
+
@user = opts[:user]
|
33
|
+
@password = opts[:password]
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def runner
|
38
|
+
current_branch = branches.current
|
39
|
+
push(server_name, current_branch, current_branch, :force => false)
|
40
|
+
pr = GitHub::PullRequest.new(self, @repo_name, {:user => @user, :password => @password})
|
41
|
+
pr.create(@base_branch, @head_branch, @title, @description)
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
|
48
|
+
def ask_for_pull_title
|
49
|
+
ask("What <%= color('title', [:bold]) %> do you want to give the pull request? ") do |q|
|
50
|
+
q.validate = /^\w+.*/
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
def ask_for_pull_description
|
56
|
+
ask("What <%= color('description', [:bold]) %> do you want to give the pull request? ")
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,110 @@
|
|
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.require 'shellwords'
|
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/github_pull_request'
|
18
|
+
|
19
|
+
|
20
|
+
module GitProc
|
21
|
+
|
22
|
+
class RebaseToMaster < Process
|
23
|
+
|
24
|
+
def runner
|
25
|
+
raise UncommittedChangesError.new unless status.clean?
|
26
|
+
raise ParkedChangesError.new(self) if is_parked?
|
27
|
+
|
28
|
+
if has_a_remote?
|
29
|
+
fetch(server_name)
|
30
|
+
proc_rebase(remote_master_branch)
|
31
|
+
push(server_name, branches.current, master_branch)
|
32
|
+
close_pull_request
|
33
|
+
remove_feature_branch
|
34
|
+
else
|
35
|
+
proc_rebase(master_branch)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def remove_feature_branch
|
41
|
+
mybranches = branches
|
42
|
+
|
43
|
+
remote_master = mybranches[remote_master_branch]
|
44
|
+
current_branch = mybranches.current
|
45
|
+
|
46
|
+
unless remote_master.contains_all_of(current_branch.name)
|
47
|
+
raise GitProcessError.new("Branch '#{current_branch.name}' has not been merged into '#{remote_master_branch}'")
|
48
|
+
end
|
49
|
+
|
50
|
+
parking_branch = mybranches['_parking_']
|
51
|
+
if parking_branch
|
52
|
+
if (parking_branch.is_ahead_of(remote_master.name) and
|
53
|
+
!current_branch.contains_all_of(parking_branch.name))
|
54
|
+
|
55
|
+
parking_branch.rename('_parking_OLD_')
|
56
|
+
|
57
|
+
logger.warn {bad_parking_branch_msg}
|
58
|
+
else
|
59
|
+
parking_branch.delete
|
60
|
+
end
|
61
|
+
end
|
62
|
+
remote_master.checkout_to_new('_parking_', :no_track => true)
|
63
|
+
|
64
|
+
current_branch.delete(true)
|
65
|
+
if mybranches["#{server_name}/#{current_branch.name}"]
|
66
|
+
push(server_name, nil, nil, :delete => current_branch.name)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def close_pull_request
|
72
|
+
pr = GitHub::PullRequest.new(self, repo_name)
|
73
|
+
|
74
|
+
# Assume that if we haven't done something that would create the
|
75
|
+
# GitHub auth token, then this likely isn't a GitHub-based repo.
|
76
|
+
# (Or at least the user isn't using pull requests)
|
77
|
+
if pr.config_auth_token
|
78
|
+
begin
|
79
|
+
mybranches = branches()
|
80
|
+
pull = pr.find_pull_request(master_branch, mybranches.current.name)
|
81
|
+
if pull
|
82
|
+
pr.close(pull[:number])
|
83
|
+
else
|
84
|
+
logger.debug { "There is no pull request for #{mybranches.current.name} against #{master_branch}" }
|
85
|
+
end
|
86
|
+
rescue GitHubService::NoRemoteRepository => exp
|
87
|
+
logger.debug exp.to_s
|
88
|
+
end
|
89
|
+
else
|
90
|
+
logger.debug "There is no GitHub auth token defined, so not trying to close a pull request."
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
|
98
|
+
def bad_parking_branch_msg
|
99
|
+
hl = HighLine.new
|
100
|
+
hl.color("\n***********************************************************************************************\n\n"+
|
101
|
+
"There is an old '_parking_' branch with unacounted changes in it.\n"+
|
102
|
+
"It has been renamed to '_parking_OLD_'.\n"+
|
103
|
+
"Please rename the branch to what the changes are about (`git branch -m _parking_OLD_ my_fb_name`),\n"+
|
104
|
+
" or remove it altogher (`git branch -D _parking_OLD_`).\n\n"+
|
105
|
+
"***********************************************************************************************\n", :red, :bold)
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
@@ -0,0 +1,63 @@
|
|
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.require 'shellwords'
|
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
|
+
|
18
|
+
|
19
|
+
module GitProc
|
20
|
+
|
21
|
+
class Sync < Process
|
22
|
+
|
23
|
+
def initialize(dir, opts)
|
24
|
+
@do_rebase = opts[:rebase]
|
25
|
+
@force = opts[:force]
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def runner
|
31
|
+
raise UncommittedChangesError.new unless status.clean?
|
32
|
+
raise ParkedChangesError.new(self) if is_parked?
|
33
|
+
|
34
|
+
current_branch = branches.current
|
35
|
+
remote_branch = "#{server_name}/#{current_branch}"
|
36
|
+
|
37
|
+
fetch(server_name)
|
38
|
+
|
39
|
+
if @do_rebase
|
40
|
+
proc_rebase(remote_master_branch)
|
41
|
+
else
|
42
|
+
proc_merge(remote_master_branch)
|
43
|
+
end
|
44
|
+
|
45
|
+
old_sha = command('rev-parse', remote_branch) rescue ''
|
46
|
+
|
47
|
+
unless current_branch == master_branch
|
48
|
+
fetch(server_name)
|
49
|
+
new_sha = command('rev-parse', remote_branch) rescue ''
|
50
|
+
unless old_sha == new_sha
|
51
|
+
logger.warn("'#{current_branch}' changed on '#{server_name}'"+
|
52
|
+
" [#{old_sha[0..5]}->#{new_sha[0..5]}]; trying sync again.")
|
53
|
+
sync_with_server(@do_rebase, @force)
|
54
|
+
end
|
55
|
+
push(server_name, current_branch, current_branch, :force => @force)
|
56
|
+
else
|
57
|
+
logger.warn("Not pushing to the server because the current branch is the master branch.")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,23 @@
|
|
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.require 'shellwords'
|
12
|
+
|
13
|
+
require 'git-process/git_process_error'
|
14
|
+
|
15
|
+
module GitProc
|
16
|
+
|
17
|
+
class UncommittedChangesError < GitProcessError
|
18
|
+
def initialize()
|
19
|
+
super("There are uncommitted changes.\nPlease either commit your changes, or use 'git stash' to set them aside.")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/git-process/version.rb
CHANGED
@@ -1,12 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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.require 'shellwords'
|
8
12
|
|
9
|
-
|
10
|
-
|
13
|
+
module GitProc
|
14
|
+
module Version
|
15
|
+
MAJOR = 0
|
16
|
+
MINOR = 9
|
17
|
+
PATCH = 2
|
18
|
+
BUILD = nil
|
19
|
+
|
20
|
+
STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
|
11
21
|
end
|
12
22
|
end
|