git-process 1.1.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +14 -1
- data/LICENSE +193 -22
- data/README.md +212 -71
- data/man/git-process.1 +371 -0
- metadata +52 -140
- data/Gemfile +0 -20
- data/Gemfile.lock +0 -53
- data/Rakefile +0 -16
- data/bin/git-new-fb +0 -58
- data/bin/git-pull-request +0 -107
- data/bin/git-sync +0 -73
- data/bin/git-to-master +0 -133
- data/git-process.gemspec +0 -25
- data/lib/git-process/abstract_error_builder.rb +0 -53
- data/lib/git-process/changed_file_helper.rb +0 -115
- data/lib/git-process/git_abstract_merge_error_builder.rb +0 -146
- data/lib/git-process/git_branch.rb +0 -105
- data/lib/git-process/git_branches.rb +0 -73
- data/lib/git-process/git_config.rb +0 -153
- data/lib/git-process/git_lib.rb +0 -512
- data/lib/git-process/git_logger.rb +0 -84
- data/lib/git-process/git_merge_error.rb +0 -28
- data/lib/git-process/git_process.rb +0 -172
- data/lib/git-process/git_process_error.rb +0 -18
- data/lib/git-process/git_process_options.rb +0 -99
- data/lib/git-process/git_rebase_error.rb +0 -30
- data/lib/git-process/git_remote.rb +0 -256
- data/lib/git-process/git_status.rb +0 -108
- data/lib/git-process/github_configuration.rb +0 -298
- data/lib/git-process/github_pull_request.rb +0 -151
- data/lib/git-process/new_fb.rb +0 -50
- data/lib/git-process/parked_changes_error.rb +0 -41
- data/lib/git-process/pull_request.rb +0 -134
- data/lib/git-process/pull_request_error.rb +0 -25
- data/lib/git-process/rebase_to_master.rb +0 -148
- data/lib/git-process/sync.rb +0 -136
- data/lib/git-process/uncommitted_changes_error.rb +0 -23
- data/lib/git-process/version.rb +0 -22
- data/spec/FileHelpers.rb +0 -19
- data/spec/GitRepoHelper.rb +0 -123
- data/spec/changed_file_helper_spec.rb +0 -127
- data/spec/git_abstract_merge_error_builder_spec.rb +0 -126
- data/spec/git_branch_spec.rb +0 -123
- data/spec/git_config_spec.rb +0 -45
- data/spec/git_lib_spec.rb +0 -176
- data/spec/git_logger_spec.rb +0 -66
- data/spec/git_process_spec.rb +0 -208
- data/spec/git_remote_spec.rb +0 -227
- data/spec/git_status_spec.rb +0 -122
- data/spec/github_configuration_spec.rb +0 -152
- data/spec/github_pull_request_spec.rb +0 -96
- data/spec/github_test_helper.rb +0 -49
- data/spec/new_fb_spec.rb +0 -130
- data/spec/pull_request_helper.rb +0 -94
- data/spec/pull_request_spec.rb +0 -128
- data/spec/rebase_to_master_spec.rb +0 -429
- data/spec/spec_helper.rb +0 -21
- data/spec/sync_spec.rb +0 -304
@@ -1,84 +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 'logger'
|
14
|
-
|
15
|
-
module GitProc
|
16
|
-
|
17
|
-
#
|
18
|
-
# Provides a Logger for Git commands
|
19
|
-
#
|
20
|
-
class GitLogger
|
21
|
-
|
22
|
-
DEBUG = Logger::DEBUG
|
23
|
-
INFO = Logger::INFO
|
24
|
-
WARN = Logger::WARN
|
25
|
-
ERROR = Logger::ERROR
|
26
|
-
|
27
|
-
|
28
|
-
def initialize(log_level = nil, out = STDOUT)
|
29
|
-
if out.nil?
|
30
|
-
@logger = ::Logger.new(RUBY_PLATFORM =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
|
31
|
-
else
|
32
|
-
@logger = ::Logger.new(out)
|
33
|
-
end
|
34
|
-
@logger.level = log_level.nil? ? GitLogger::WARN : log_level
|
35
|
-
@logger.datetime_format = '%Y-%m-%d %H:%M:%S'
|
36
|
-
@logger.formatter = proc do |_, _, _, msg|
|
37
|
-
"#{msg}\n"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
def level
|
43
|
-
@logger.level
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
def debug(msg = nil, &block)
|
48
|
-
if msg.nil?
|
49
|
-
@logger.debug(&block)
|
50
|
-
else
|
51
|
-
@logger.debug(msg)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
|
56
|
-
def info(msg = nil, &block)
|
57
|
-
if msg.nil?
|
58
|
-
@logger.info(&block)
|
59
|
-
else
|
60
|
-
@logger.info(msg)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
|
-
def warn(msg = nil, &block)
|
66
|
-
if msg.nil?
|
67
|
-
@logger.send(:warn, &block)
|
68
|
-
else
|
69
|
-
@logger.send(:warn, msg)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
def error(msg = nil, &block)
|
75
|
-
if msg.nil?
|
76
|
-
@logger.error(&block)
|
77
|
-
else
|
78
|
-
@logger.error(msg)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
@@ -1,28 +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_abstract_merge_error_builder'
|
14
|
-
|
15
|
-
module GitProc
|
16
|
-
|
17
|
-
class MergeError < GitProcessError
|
18
|
-
|
19
|
-
def initialize(merge_error_message, gitlib)
|
20
|
-
@error_builder = GitProc::AbstractMergeErrorBuilder.new(gitlib, merge_error_message, 'git commit')
|
21
|
-
msg = error_builder.build_message
|
22
|
-
|
23
|
-
super(msg)
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
@@ -1,172 +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_rebase_error'
|
15
|
-
require 'git-process/git_merge_error'
|
16
|
-
require 'highline/import'
|
17
|
-
|
18
|
-
|
19
|
-
module GitProc
|
20
|
-
|
21
|
-
class Process
|
22
|
-
|
23
|
-
# @param [GitLib] gitlib
|
24
|
-
def initialize(gitlib, opts = {})
|
25
|
-
@gitlib = gitlib
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
def gitlib
|
30
|
-
@gitlib
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
def run
|
35
|
-
begin
|
36
|
-
verify_preconditions
|
37
|
-
|
38
|
-
runner
|
39
|
-
rescue GitProc::GitProcessError => exp
|
40
|
-
puts exp.message
|
41
|
-
exit(-1)
|
42
|
-
ensure
|
43
|
-
cleanup
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
def runner
|
49
|
-
# extension point - does nothing by default
|
50
|
-
end
|
51
|
-
|
52
|
-
|
53
|
-
def workdir
|
54
|
-
gitlib.workdir
|
55
|
-
end
|
56
|
-
|
57
|
-
|
58
|
-
def logger
|
59
|
-
gitlib.logger
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
def config
|
64
|
-
gitlib.config
|
65
|
-
end
|
66
|
-
|
67
|
-
|
68
|
-
def master_branch
|
69
|
-
gitlib.config.master_branch
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
def remote
|
74
|
-
gitlib.remote
|
75
|
-
end
|
76
|
-
|
77
|
-
|
78
|
-
def verify_preconditions
|
79
|
-
if should_remove_master?
|
80
|
-
if ask_about_removing_master
|
81
|
-
delete_master_branch!
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
|
87
|
-
def cleanup
|
88
|
-
# extension point
|
89
|
-
end
|
90
|
-
|
91
|
-
|
92
|
-
def fetch_remote_changes(remote_name = nil)
|
93
|
-
if remote.exists?
|
94
|
-
gitlib.fetch(remote_name || remote.name)
|
95
|
-
else
|
96
|
-
logger.debug 'Can not fetch latest changes because there is no remote defined'
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
|
101
|
-
def is_parked?
|
102
|
-
mybranches = gitlib.branches
|
103
|
-
mybranches.parking == mybranches.current
|
104
|
-
end
|
105
|
-
|
106
|
-
|
107
|
-
private
|
108
|
-
|
109
|
-
|
110
|
-
def delete_master_branch!
|
111
|
-
gitlib.branches[config.master_branch].delete!
|
112
|
-
end
|
113
|
-
|
114
|
-
|
115
|
-
def should_remove_master?
|
116
|
-
my_branches = gitlib.branches()
|
117
|
-
gitlib.has_a_remote? and
|
118
|
-
my_branches.include?(config.master_branch) and
|
119
|
-
my_branches.current.name != config.master_branch and
|
120
|
-
!keep_local_integration_branch? and
|
121
|
-
my_branches[config.integration_branch].contains_all_of(config.master_branch)
|
122
|
-
end
|
123
|
-
|
124
|
-
|
125
|
-
def keep_local_integration_branch?
|
126
|
-
keep_local_integration_branch_config_value.to_boolean
|
127
|
-
end
|
128
|
-
|
129
|
-
|
130
|
-
#noinspection RubyInstanceMethodNamingConvention
|
131
|
-
def keep_local_integration_branch_config_value
|
132
|
-
gitlib.config['gitProcess.keepLocalIntegrationBranch']
|
133
|
-
end
|
134
|
-
|
135
|
-
|
136
|
-
def ask_about_removing_master
|
137
|
-
resp = ask("You should remove your obsolete <%= color('local', [:bold]) %> branch, '#{config.master_branch}'. Should I remove it for you? (Yn) ") do |q|
|
138
|
-
q.responses[:not_valid] = 'Please respond with either (y)es or (n)o. Defaults to (y)es.'
|
139
|
-
q.case = :down
|
140
|
-
q.default = 'Y'
|
141
|
-
q.validate = /y|n/i
|
142
|
-
end
|
143
|
-
|
144
|
-
if resp == 'n'
|
145
|
-
say("(You can turn off this message using \"git config gitProcess.keepLocalIntegrationBranch true\").")
|
146
|
-
false
|
147
|
-
else
|
148
|
-
true
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
|
153
|
-
def proc_rebase(base, opts = {})
|
154
|
-
begin
|
155
|
-
gitlib.rebase(base, opts)
|
156
|
-
rescue GitExecuteError => rebase_error
|
157
|
-
raise RebaseError.new(rebase_error.message, gitlib)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
|
162
|
-
def proc_merge(base)
|
163
|
-
begin
|
164
|
-
gitlib.merge(base)
|
165
|
-
rescue GitExecuteError => merge_error
|
166
|
-
raise MergeError.new(merge_error.message, gitlib)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
end
|
171
|
-
|
172
|
-
end
|
@@ -1,18 +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
|
-
module GitProc
|
14
|
-
|
15
|
-
class GitProcessError < RuntimeError
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
@@ -1,99 +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 'optparse'
|
14
|
-
require 'trollop'
|
15
|
-
require 'git-process/version'
|
16
|
-
|
17
|
-
module GitProc
|
18
|
-
|
19
|
-
module GitProcessOptions
|
20
|
-
|
21
|
-
DEBUG = false
|
22
|
-
|
23
|
-
|
24
|
-
def parse_cli(filename, argv)
|
25
|
-
parser = Trollop::Parser.new
|
26
|
-
parser.version "#{filename} #{GitProc::Version::STRING}"
|
27
|
-
|
28
|
-
parser.banner "#{summary}\n\n"
|
29
|
-
parser.banner "\nUsage:\n #{usage(filename)}\n\nWhere [options] are:"
|
30
|
-
|
31
|
-
extend_opts(parser)
|
32
|
-
standard_opts(parser)
|
33
|
-
|
34
|
-
parser.banner "\n#{description}"
|
35
|
-
|
36
|
-
opts = Trollop::with_standard_exception_handling parser do
|
37
|
-
raise Trollop::HelpNeeded if ARGV.empty? and !empty_argv_ok?
|
38
|
-
parser.parse argv
|
39
|
-
end
|
40
|
-
|
41
|
-
opts[:info] = false if opts[:verbose] || opts[:quiet]
|
42
|
-
opts[:info] = true if opts[:info_given]
|
43
|
-
|
44
|
-
post_parse(opts, argv)
|
45
|
-
|
46
|
-
if DEBUG
|
47
|
-
puts "\n\n#{opts.map { |k, v| "#{k}:#{v}" }.join(', ')}"
|
48
|
-
puts "\nargs: #{argv.join(', ')}"
|
49
|
-
end
|
50
|
-
|
51
|
-
opts
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
|
-
def standard_opts(parser)
|
56
|
-
parser.opt :info, 'Informational messages; show the major things this is doing', :default => true, :short => :none
|
57
|
-
parser.opt :quiet, 'Quiet messages; only show errors', :short => :q
|
58
|
-
parser.opt :verbose, 'Verbose messages; show lots of details on what this is doing', :short => :v
|
59
|
-
parser.opt :version, "Print version (#{GitProc::Version::STRING}) and exit", :short => :none
|
60
|
-
parser.opt :help, 'Show this message', :short => :h
|
61
|
-
|
62
|
-
parser.conflicts :verbose, :info, :quiet
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
def summary
|
67
|
-
'Default summary'
|
68
|
-
end
|
69
|
-
|
70
|
-
|
71
|
-
def usage(filename)
|
72
|
-
"#{filename} [options]"
|
73
|
-
end
|
74
|
-
|
75
|
-
|
76
|
-
def description
|
77
|
-
'Default description'
|
78
|
-
end
|
79
|
-
|
80
|
-
|
81
|
-
def empty_argv_ok?
|
82
|
-
true
|
83
|
-
end
|
84
|
-
|
85
|
-
|
86
|
-
#noinspection RubyUnusedLocalVariable
|
87
|
-
def extend_opts(parser)
|
88
|
-
# extension point - does nothing by default
|
89
|
-
end
|
90
|
-
|
91
|
-
|
92
|
-
#noinspection RubyUnusedLocalVariable
|
93
|
-
def post_parse(opts, argv)
|
94
|
-
# extension point - does nothing by default
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
@@ -1,30 +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_abstract_merge_error_builder'
|
14
|
-
|
15
|
-
module GitProc
|
16
|
-
|
17
|
-
class RebaseError < GitProcessError
|
18
|
-
attr_reader :error_builder
|
19
|
-
|
20
|
-
|
21
|
-
def initialize(rebase_error_message, gitlib)
|
22
|
-
@error_builder = GitProc::AbstractMergeErrorBuilder.new(gitlib, rebase_error_message, 'git rebase --continue')
|
23
|
-
msg = error_builder.build_message
|
24
|
-
|
25
|
-
super(msg)
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
@@ -1,256 +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_config'
|
14
|
-
require 'addressable/uri'
|
15
|
-
#require 'git-process/git_branches'
|
16
|
-
#require 'git-process/git_status'
|
17
|
-
#require 'git-process/git_process_error'
|
18
|
-
|
19
|
-
|
20
|
-
class String
|
21
|
-
|
22
|
-
def to_boolean
|
23
|
-
return false if self == false || self.nil? || self =~ (/(false|f|no|n|0)$/i)
|
24
|
-
return true if self == true || self =~ (/(true|t|yes|y|1)$/i)
|
25
|
-
raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
class NilClass
|
32
|
-
def to_boolean
|
33
|
-
false
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
module GitProc
|
39
|
-
|
40
|
-
#
|
41
|
-
# Git Remote configuration
|
42
|
-
#
|
43
|
-
class GitRemote
|
44
|
-
|
45
|
-
# @param [GitProc::GitConfig] gitconfig
|
46
|
-
def initialize(gitconfig)
|
47
|
-
@gitconfig = gitconfig
|
48
|
-
end
|
49
|
-
|
50
|
-
|
51
|
-
# @return [#info, #warn, #debug, #error]
|
52
|
-
def logger
|
53
|
-
@logger ||= @gitconfig.logger
|
54
|
-
end
|
55
|
-
|
56
|
-
|
57
|
-
# @return [GitProc::GitConfig]
|
58
|
-
def config
|
59
|
-
@gitconfig
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
# @deprecated
|
64
|
-
# TODO: Remove
|
65
|
-
def server_name
|
66
|
-
@server_name ||= self.remote_name
|
67
|
-
end
|
68
|
-
|
69
|
-
|
70
|
-
# @return [Boolean] does this have a remote defined?
|
71
|
-
def exists?
|
72
|
-
if @has_remote.nil?
|
73
|
-
@has_remote = (config.gitlib.command(:remote) != '')
|
74
|
-
end
|
75
|
-
logger.debug { "Does a remote exist? #{@has_remote}" }
|
76
|
-
@has_remote
|
77
|
-
end
|
78
|
-
|
79
|
-
|
80
|
-
def repo_name
|
81
|
-
unless @repo_name
|
82
|
-
url = config["remote.#{name}.url"]
|
83
|
-
raise GitProcessError.new("There is no #{name} url set up.") if url.nil? or url.empty?
|
84
|
-
uri = Addressable::URI.parse(url)
|
85
|
-
@repo_name = uri.path.sub(/\.git/, '').sub(/^\//, '')
|
86
|
-
end
|
87
|
-
@repo_name
|
88
|
-
end
|
89
|
-
|
90
|
-
|
91
|
-
def name
|
92
|
-
unless @remote_name
|
93
|
-
@remote_name = config['gitProcess.remoteName']
|
94
|
-
if @remote_name.nil? or @remote_name.empty?
|
95
|
-
remotes = self.remote_names
|
96
|
-
if remotes.empty?
|
97
|
-
@remote_name = nil
|
98
|
-
else
|
99
|
-
@remote_name = remotes[0]
|
100
|
-
raise '!@remote_name.is_a? String' unless @remote_name.is_a? String
|
101
|
-
end
|
102
|
-
end
|
103
|
-
logger.debug { "Using remote name of '#{@remote_name}'" }
|
104
|
-
end
|
105
|
-
@remote_name
|
106
|
-
end
|
107
|
-
|
108
|
-
|
109
|
-
def master_branch_name
|
110
|
-
"#{self.name}/#{config.master_branch}"
|
111
|
-
end
|
112
|
-
|
113
|
-
|
114
|
-
def remote_names
|
115
|
-
remote_str = config.gitlib.command(:remote, [:show])
|
116
|
-
if remote_str.nil? or remote_str.empty?
|
117
|
-
[]
|
118
|
-
else
|
119
|
-
remote_str.split(/\n/)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
|
124
|
-
#
|
125
|
-
# Expands the git configuration server name to a url.
|
126
|
-
#
|
127
|
-
# Takes into account further expanding an SSH uri that uses SSH aliasing in .ssh/config
|
128
|
-
#
|
129
|
-
# @param [String] server_name the git configuration server name; defaults to 'origin'
|
130
|
-
#
|
131
|
-
# @option opts [String] :ssh_config_file the SSH config file to use; defaults to ~/.ssh/config
|
132
|
-
#
|
133
|
-
# @return the fully expanded URL; never nil
|
134
|
-
#
|
135
|
-
# @raise [GitHubService::NoRemoteRepository] there is not a URL set for the server name
|
136
|
-
# @raise [URI::InvalidURIError] the retrieved URL does not have a schema
|
137
|
-
# @raise [GitHubService::NoRemoteRepository] if could not figure out a host for the retrieved URL
|
138
|
-
# @raise [::ArgumentError] if a server name is not provided
|
139
|
-
def expanded_url(server_name = 'origin', raw_url = nil, opts = {})
|
140
|
-
if raw_url.nil?
|
141
|
-
raise ArgumentError.new('Need server_name') unless server_name
|
142
|
-
|
143
|
-
conf_key = "remote.#{server_name}.url"
|
144
|
-
url = config[conf_key]
|
145
|
-
|
146
|
-
raise GitHubService::NoRemoteRepository.new("There is no value set for '#{conf_key}'") if url.nil? or url.empty?
|
147
|
-
else
|
148
|
-
raise GitHubService::NoRemoteRepository.new("There is no value set for '#{raw_url}'") if raw_url.nil? or raw_url.empty?
|
149
|
-
url = raw_url
|
150
|
-
end
|
151
|
-
|
152
|
-
if /^\S+@/ =~ url
|
153
|
-
url.sub(/^(\S+@\S+?):(.*)$/, "ssh://\\1/\\2")
|
154
|
-
else
|
155
|
-
uri = URI.parse(url)
|
156
|
-
host = uri.host
|
157
|
-
scheme = uri.scheme
|
158
|
-
|
159
|
-
raise URI::InvalidURIError.new("Need a scheme in URI: '#{url}'") unless scheme
|
160
|
-
|
161
|
-
if scheme == 'file'
|
162
|
-
url
|
163
|
-
elsif host.nil?
|
164
|
-
# assume that the 'scheme' is the named configuration in ~/.ssh/config
|
165
|
-
rv = GitRemote.hostname_and_user_from_ssh_config(scheme, opts[:ssh_config_file] ||= "#{ENV['HOME']}/.ssh/config")
|
166
|
-
|
167
|
-
raise GitHubService::NoRemoteRepository.new("Could not determine a host from #{url}") if rv.nil?
|
168
|
-
|
169
|
-
host = rv[0]
|
170
|
-
user = rv[1]
|
171
|
-
url.sub(/^\S+:(\S+)$/, "ssh://#{user}@#{host}/\\1")
|
172
|
-
else
|
173
|
-
url
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
|
179
|
-
# @return [boolean]
|
180
|
-
def rerere_enabled?
|
181
|
-
re = config['rerere.enabled']
|
182
|
-
!re.nil? && re.to_boolean
|
183
|
-
end
|
184
|
-
|
185
|
-
|
186
|
-
# @return [void]
|
187
|
-
def rerere_enabled(re, global = true)
|
188
|
-
if global
|
189
|
-
config.set_global('rerere.enabled', re)
|
190
|
-
else
|
191
|
-
config['rerere.enabled'] = re
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
|
196
|
-
# @return [boolean]
|
197
|
-
def rerere_autoupdate?
|
198
|
-
re = config['rerere.autoupdate']
|
199
|
-
!re.nil? && re.to_boolean
|
200
|
-
end
|
201
|
-
|
202
|
-
|
203
|
-
# @return [void]
|
204
|
-
def rerere_autoupdate(re, global = true)
|
205
|
-
if global
|
206
|
-
config.set_global('rerere.autoupdate', re)
|
207
|
-
else
|
208
|
-
config['rerere.autoupdate'] = re
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
|
213
|
-
# @return [void]
|
214
|
-
def add_remote(remote_name, url)
|
215
|
-
config.gitlib.command(:remote, ['add', remote_name, url])
|
216
|
-
end
|
217
|
-
|
218
|
-
|
219
|
-
alias :add :add_remote
|
220
|
-
|
221
|
-
|
222
|
-
#noinspection RubyClassMethodNamingConvention
|
223
|
-
def self.hostname_and_user_from_ssh_config(host_alias, config_file)
|
224
|
-
if File.exists?(config_file)
|
225
|
-
config_lines = File.new(config_file).readlines
|
226
|
-
|
227
|
-
in_host_section = false
|
228
|
-
host_name = nil
|
229
|
-
user_name = nil
|
230
|
-
|
231
|
-
config_lines.each do |line|
|
232
|
-
line.chop!
|
233
|
-
if /^\s*Host\s+#{host_alias}\s*$/ =~ line
|
234
|
-
in_host_section = true
|
235
|
-
next
|
236
|
-
end
|
237
|
-
|
238
|
-
if in_host_section and (/^\s*HostName\s+\S+\s*$/ =~ line)
|
239
|
-
host_name = line.sub(/^\s*HostName\s+(\S+)\s*$/, '\1')
|
240
|
-
break unless user_name.nil?
|
241
|
-
elsif in_host_section and (/^\s*User\s+\S+\s*$/ =~ line)
|
242
|
-
user_name = line.sub(/^\s*User\s+(\S+)\s*$/, '\1')
|
243
|
-
break unless host_name.nil?
|
244
|
-
elsif in_host_section and (/^\s*Host\s+.*$/ =~ line)
|
245
|
-
break
|
246
|
-
end
|
247
|
-
end
|
248
|
-
host_name.nil? ? nil : [host_name, user_name]
|
249
|
-
else
|
250
|
-
nil
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
end
|
255
|
-
|
256
|
-
end
|