-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathgit_remote_spec.rb
More file actions
227 lines (159 loc) · 5.9 KB
/
git_remote_spec.rb
File metadata and controls
227 lines (159 loc) · 5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
require 'git-process/git_remote'
require 'GitRepoHelper'
include GitProc
describe GitRemote do
def log_level
Logger::ERROR
end
describe '#name' do
include GitRepoHelper
it 'should work with origin' do
change_file_and_commit('a', '')
clone_repo('master', 'origin') do |gl|
gl.remote.name.should == 'origin'
gl.branches.include?('origin/master').should be true
end
end
it 'should work with a different remote name' do
change_file_and_commit('a', '')
clone_repo('master', 'a_remote') do |gl|
gl.remote.name.should == 'a_remote'
gl.branches.include?('a_remote/master').should be true
end
end
it 'should work with an overridden remote name' do
change_file_and_commit('a', '')
clone_repo('master', 'a_remote') do |gl|
gl.config['gitProcess.remoteName'] = 'something_else'
gl.remote.name.should == 'something_else'
end
end
end
describe "#expanded_url" do
include GitRepoHelper
it "should work for an ssh address" do
remote.add('torigin', 'tuser@github.myco.com:jdigger/git-process.git')
remote.expanded_url('torigin').should == 'ssh://tuser@github.myco.com/jdigger/git-process.git'
end
it 'should work for an http address' do
remote.add('torigin', 'http://github.myco.com:8080/jdigger/git-process.git')
remote.expanded_url('torigin').should == 'http://github.myco.com:8080/jdigger/git-process.git'
end
it "should work for an https address" do
remote.add('torigin', 'https://github.myco.com/jdigger/git-process.git')
remote.expanded_url('torigin').should == 'https://github.myco.com/jdigger/git-process.git'
end
it "should work for an ssh-configured url address" do
remote.add('origin', 'mygithub:jdigger/git-process.git')
content = "\nHost mygithub\n"+
" User tuser\n"+
" HostName github.myco.com\n"
in_tempfile('ssh_config', content) do |file|
remote.expanded_url('origin', nil, :ssh_config_file => file.path).should == 'ssh://tuser@github.myco.com/jdigger/git-process.git'
end
end
end
describe "#repo_name" do
include GitRepoHelper
it "should work for an ssh address" do
remote.add('torigin', 'tuser@github.myco.com:jdigger/git-process.git')
remote.repo_name.should == 'jdigger/git-process'
end
it 'should work for an http address' do
remote.add('torigin', 'http://github.myco.com:8080/jdigger/git-process.git')
remote.repo_name.should == 'jdigger/git-process'
end
it "should work for an https address" do
remote.add('torigin', 'https://github.myco.com/jdigger/git-process.git')
remote.repo_name.should == 'jdigger/git-process'
end
it "should work for an ssh-configured url address" do
remote.add('origin', 'mygithub:jdigger/git-process.git')
content = "\nHost mygithub\n"+
" User tuser\n"+
" HostName github.myco.com\n"
in_tempfile('ssh_config', content) do |file|
remote.repo_name.should == 'jdigger/git-process'
end
end
end
describe "#hostname_and_user_from_ssh_config" do
include GitRepoHelper
it "should find in a single entry" do
content = "\nHost mygithub\n"+
" User git\n"+
" HostName github.myco.com\n"
in_tempfile('ssh_config', content) do |file|
GitRemote.hostname_and_user_from_ssh_config('mygithub', file.path).should == %w(github.myco.com git)
end
end
it "should find in multiple entries" do
content = "\nHost mygithub1\n"+
" User gittyw\n"+
" HostName github.mycoy.com\n"+
"Host mygithub2\n"+
" User gitty\n"+
" HostName github.myco.com\n"+
"Host mygithub3\n"+
" User gittyz\n"+
" HostName github.mycoz.com\n"
in_tempfile('ssh_config', content) do |file|
GitRemote.hostname_and_user_from_ssh_config('mygithub2', file.path).should == %w(github.myco.com gitty)
end
end
it "should return nil when no file" do
GitRemote.hostname_and_user_from_ssh_config('mygithub', '/bogus_file').should == nil
end
it "should return nil when given an unknown host" do
content = "\nHost mygithub1\n"+
" User gittyw\n"+
" HostName github.mycoy.com\n"+
"Host mygithub2\n"+
" User gitty\n"+
" HostName github.myco.com\n"+
"Host mygithub3\n"+
" User gittyz\n"+
" HostName github.mycoz.com\n"
in_tempfile('ssh_config', content) do |file|
GitRemote.hostname_and_user_from_ssh_config('UNKNOWNZ', file.path).should == nil
end
end
it "should return nil when no hostname for an existing host" do
content = "\nHost mygithub1\n"+
" User gittyw\n"+
" HostName github.mycoy.com\n"+
"Host mygithub2\n"+
" User gitty\n"+
"Host mygithub3\n"+
" User gittyz\n"+
" HostName github.mycoz.com\n"
in_tempfile('ssh_config', content) do |file|
GitRemote.hostname_and_user_from_ssh_config('mygithub2', file.path).should == nil
end
end
it "should return hostname but no username when no user for an existing host" do
content = "\nHost mygithub1\n"+
" User gittyw\n"+
" HostName github.mycoy.com\n"+
"Host mygithub2\n"+
" HostName github.myco.com\n"+
"Host mygithub3\n"+
" User gittyz\n"+
" HostName github.mycoz.com\n"
in_tempfile('ssh_config', content) do |file|
GitRemote.hostname_and_user_from_ssh_config('mygithub2', file.path).should == ['github.myco.com', nil]
end
end
end
end
def in_tempfile(filename, content, &block)
file = Tempfile.new(filename)
file.puts content
file.flush
begin
block.call(file)
ensure
file.close
file.unlink
end
end