forked from mislav/hub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.feature
313 lines (289 loc) · 9.85 KB
/
create.feature
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
Feature: hub create
Background:
Given I am in "dotfiles" git repo
And I am "mislav" on github.com with OAuth token "OTOKEN"
Scenario: Create repo
Given the GitHub API server:
"""
post('/user/repos') {
assert :private => false
status 201
json :full_name => 'mislav/dotfiles'
}
"""
When I successfully run `hub create`
Then the url for "origin" should be "[email protected]:mislav/dotfiles.git"
And the output should contain exactly "https://github.com/mislav/dotfiles\n"
Scenario: Create private repo
Given the GitHub API server:
"""
post('/user/repos') {
assert :private => true
status 201
json :full_name => 'mislav/dotfiles'
}
"""
When I successfully run `hub create -p`
Then the url for "origin" should be "[email protected]:mislav/dotfiles.git"
Scenario: Alternate origin remote name
Given the GitHub API server:
"""
post('/user/repos') {
status 201
json :full_name => 'mislav/dotfiles'
}
"""
When I successfully run `hub create --remote-name=work`
Then the url for "work" should be "[email protected]:mislav/dotfiles.git"
And there should be no "origin" remote
Scenario: HTTPS is preferred
Given the GitHub API server:
"""
post('/user/repos') {
status 201
json :full_name => 'mislav/dotfiles'
}
"""
And HTTPS is preferred
When I successfully run `hub create`
Then the url for "origin" should be "https://github.com/mislav/dotfiles.git"
Scenario: Create in organization
Given the GitHub API server:
"""
post('/orgs/acme/repos') {
status 201
json :full_name => 'acme/dotfiles'
}
"""
When I successfully run `hub create acme/dotfiles`
Then the url for "origin" should be "[email protected]:acme/dotfiles.git"
And the output should contain exactly "https://github.com/acme/dotfiles\n"
Scenario: Creating repo failed
Given the GitHub API server:
"""
post('/user/repos') { status 500 }
"""
When I run `hub create`
Then the stderr should contain "Error creating repository: Internal Server Error (HTTP 500)"
And the exit status should be 1
And there should be no "origin" remote
Scenario: With custom name
Given the GitHub API server:
"""
post('/user/repos') {
assert :name => 'myconfig'
status 201
json :full_name => 'mislav/myconfig'
}
"""
When I successfully run `hub create myconfig`
Then the url for "origin" should be "[email protected]:mislav/myconfig.git"
Scenario: With description and homepage
Given the GitHub API server:
"""
post('/user/repos') {
assert :description => 'mydesc',
:homepage => 'http://example.com'
status 201
json :full_name => 'mislav/dotfiles'
}
"""
When I successfully run `hub create -d mydesc -h http://example.com`
Then the url for "origin" should be "[email protected]:mislav/dotfiles.git"
Scenario: Not in git repo
Given the current dir is not a repo
When I run `hub create`
Then the stderr should contain "'create' must be run from inside a git repository"
And the exit status should be 1
Scenario: Cannot create from bare repo
Given the current dir is not a repo
And I run `git init --bare`
When I run `hub create`
Then the stderr should contain exactly "unable to determine git working directory\n"
And the exit status should be 1
Scenario: Origin remote already exists
Given the GitHub API server:
"""
post('/user/repos') {
status 201
json :full_name => 'mislav/dotfiles'
}
"""
And the "origin" remote has url "git://github.com/mislav/dotfiles.git"
When I successfully run `hub create`
Then the url for "origin" should be "git://github.com/mislav/dotfiles.git"
And the output should contain exactly "https://github.com/mislav/dotfiles\n"
Scenario: Unrelated origin remote already exists
Given the GitHub API server:
"""
post('/user/repos') {
status 201
json :full_name => 'mislav/dotfiles'
}
"""
And the "origin" remote has url "git://example.com/unrelated.git"
When I successfully run `hub create`
Then the url for "origin" should be "git://example.com/unrelated.git"
And the stdout should contain exactly "https://github.com/mislav/dotfiles\n"
And the stderr should contain exactly:
"""
A git remote named 'origin' already exists and is set to push to 'git://example.com/unrelated.git'.\n
"""
Scenario: Another remote already exists
Given the GitHub API server:
"""
post('/user/repos') {
status 201
json :full_name => 'mislav/dotfiles'
}
"""
And the "github" remote has url "git://github.com/mislav/dotfiles.git"
When I successfully run `hub create`
Then the url for "origin" should be "[email protected]:mislav/dotfiles.git"
Scenario: GitHub repo already exists
Given the GitHub API server:
"""
get('/repos/mislav/dotfiles') {
json :full_name => 'mislav/dotfiles'
}
"""
When I successfully run `hub create`
Then the output should contain "Existing repository detected\n"
And the url for "origin" should be "[email protected]:mislav/dotfiles.git"
Scenario: GitHub repo already exists and is not private
Given the GitHub API server:
"""
get('/repos/mislav/dotfiles') {
json :full_name => 'mislav/dotfiles',
:private => false
}
"""
When I run `hub create -p`
Then the output should contain "Repository 'mislav/dotfiles' already exists and is public\n"
And the exit status should be 1
And there should be no "origin" remote
Scenario: GitHub repo already exists and is private
Given the GitHub API server:
"""
get('/repos/mislav/dotfiles') {
json :full_name => 'mislav/dotfiles',
:private => true
}
"""
When I successfully run `hub create -p`
Then the url for "origin" should be "[email protected]:mislav/dotfiles.git"
Scenario: Renamed GitHub repo already exists
Given the GitHub API server:
"""
get('/repos/mislav/dotfiles') {
redirect 'https://api.github.com/repositories/12345', 301
}
get('/repositories/12345') {
json :full_name => 'mislav/DOTfiles'
}
"""
When I successfully run `hub create`
And the url for "origin" should be "[email protected]:mislav/DOTfiles.git"
Scenario: Renamed GitHub repo is unrelated
Given the GitHub API server:
"""
get('/repos/mislav/dotfiles') {
redirect 'https://api.github.com/repositories/12345', 301
}
get('/repositories/12345') {
json :full_name => 'mislav/old-dotfiles'
}
post('/user/repos') {
status 201
json :full_name => 'mislav/mydotfiles'
}
"""
When I successfully run `hub create`
And the url for "origin" should be "[email protected]:mislav/mydotfiles.git"
Scenario: API response changes the clone URL
Given the GitHub API server:
"""
post('/user/repos') {
status 201
json :full_name => 'Mooslav/myconfig'
}
"""
When I successfully run `hub create`
Then the url for "origin" should be "[email protected]:Mooslav/myconfig.git"
And the output should contain exactly "https://github.com/Mooslav/myconfig\n"
Scenario: Open new repository in web browser
Given the GitHub API server:
"""
post('/user/repos') {
status 201
json :full_name => 'Mooslav/myconfig'
}
"""
When I successfully run `hub create -o`
Then the output should contain exactly ""
And "open https://github.com/Mooslav/myconfig" should be run
Scenario: Current directory contains spaces
Given I am in "my dot files" git repo
Given the GitHub API server:
"""
post('/user/repos') {
assert :name => 'my-dot-files'
status 201
json :full_name => 'mislav/my-dot-files'
}
"""
When I successfully run `hub create`
Then the url for "origin" should be "[email protected]:mislav/my-dot-files.git"
Scenario: Verbose API output
Given the GitHub API server:
"""
get('/repos/mislav/dotfiles') { status 404 }
post('/user/repos') {
response['location'] = 'http://disney.com'
status 201
json :full_name => 'mislav/dotfiles'
}
"""
And $HUB_VERBOSE is "on"
When I successfully run `hub create`
Then the stderr should contain:
"""
> GET https://api.github.com/repos/mislav/dotfiles
> Authorization: token [REDACTED]
> Accept: application/vnd.github.v3+json;charset=utf-8
< HTTP 404
"""
And the stderr should contain:
"""
> POST https://api.github.com/user/repos
> Authorization: token [REDACTED]
"""
And the stderr should contain:
"""
< HTTP 201
< Location: http://disney.com
{"full_name":"mislav/dotfiles"}\n
"""
Scenario: Create Enterprise repo
Given I am "nsartor" on git.my.org with OAuth token "FITOKEN"
Given the GitHub API server:
"""
post('/api/v3/user/repos', :host_name => 'git.my.org') {
assert :private => false
status 201
json :full_name => 'nsartor/dotfiles'
}
"""
And $GITHUB_HOST is "git.my.org"
When I successfully run `hub create`
Then the url for "origin" should be "[email protected]:nsartor/dotfiles.git"
And the output should contain exactly "https://git.my.org/nsartor/dotfiles\n"
Scenario: Invalid GITHUB_HOST
Given I am "nsartor" on {} with OAuth token "FITOKEN"
And $GITHUB_HOST is "{}"
When I run `hub create`
Then the exit status should be 1
And the stderr should contain exactly:
"""
invalid hostname: "{}"\n
"""