|
23 | 23 |
|
24 | 24 | keys manage ssh keys used for `git push` deployments |
25 | 25 | perms manage permissions for applications |
| 26 | + git manage git for applications |
26 | 27 |
|
27 | 28 | Shortcut commands, use ``deis shortcuts`` to see all:: |
28 | 29 |
|
@@ -436,6 +437,9 @@ def apps_create(self, args): |
436 | 437 |
|
437 | 438 | -b --buildpack BUILDPACK |
438 | 439 | a buildpack url to use for this app |
| 440 | +
|
| 441 | + -r --remote REMOTE |
| 442 | + name of remote to create, default 'deis' |
439 | 443 | """ |
440 | 444 | body = {} |
441 | 445 | app_name = None |
@@ -467,24 +471,15 @@ def apps_create(self, args): |
467 | 471 | if buildpack: |
468 | 472 | self._config_set(app_id, {'BUILDPACK_URL': buildpack}) |
469 | 473 |
|
470 | | - # set a git remote if necessary |
471 | | - try: |
472 | | - self._session.git_root() |
473 | | - except EnvironmentError: |
474 | | - return |
475 | | - hostname = urlparse.urlparse(self._settings['controller']).netloc.split(':')[0] |
476 | | - git_remote = "ssh://git@{hostname}:2222/{app_id}.git".format(**locals()) |
477 | 474 | if args.get('--no-remote'): |
| 475 | + hostname = urlparse.urlparse(self._settings['controller']).netloc.split(':')[0] |
| 476 | + git_remote = "ssh://git@{hostname}:2222/{app_id}.git".format(**locals()) |
478 | 477 | self._logger.info('remote available at {}'.format(git_remote)) |
479 | 478 | else: |
480 | | - try: |
481 | | - subprocess.check_call( |
482 | | - ['git', 'remote', 'add', 'deis', git_remote], |
483 | | - stdout=subprocess.PIPE) |
484 | | - self._logger.info('Git remote deis added') |
485 | | - except subprocess.CalledProcessError: |
486 | | - self._logger.error('Could not create Deis remote') |
487 | | - sys.exit(1) |
| 479 | + remote_name = args.get('--remote') |
| 480 | + if not remote_name: |
| 481 | + remote_name = 'deis' |
| 482 | + self._git_remote_create(app_id, remote_name) |
488 | 483 |
|
489 | 484 | def apps_destroy(self, args): |
490 | 485 | """ |
@@ -1273,6 +1268,61 @@ def domains_list(self, args): |
1273 | 1268 | else: |
1274 | 1269 | raise ResponseError(response) |
1275 | 1270 |
|
| 1271 | + def git(self, args): |
| 1272 | + """ |
| 1273 | + Valid commands for git: |
| 1274 | +
|
| 1275 | + git:remote Adds git remote of application to repository |
| 1276 | +
|
| 1277 | + Use `deis help [command]` to learn more. |
| 1278 | + """ |
| 1279 | + raise DocoptExit('`deis git` is not a valid command, try `deis help git`') |
| 1280 | + |
| 1281 | + def git_remote(self, args): |
| 1282 | + """ |
| 1283 | + Adds git remote of application to repository |
| 1284 | +
|
| 1285 | + Usage: deis git:remote [options] |
| 1286 | +
|
| 1287 | + Options: |
| 1288 | + -a --app=<app> |
| 1289 | + the uniquely identifiable name for the application. |
| 1290 | +
|
| 1291 | + -r --remote REMOTE |
| 1292 | + name of remote to create, default 'deis' |
| 1293 | + """ |
| 1294 | + app = args.get('--app') |
| 1295 | + if not app: |
| 1296 | + app = self._session.app |
| 1297 | + response = self._dispatch( |
| 1298 | + 'get', "/v1/apps/{app}/domains".format(app=app)) |
| 1299 | + if response.status_code == requests.codes.ok: |
| 1300 | + remote_name = args.get('--remote') |
| 1301 | + if not remote_name: |
| 1302 | + remote_name = 'deis' |
| 1303 | + self._git_remote_create(app, remote_name) |
| 1304 | + else: |
| 1305 | + raise ResponseError(response) |
| 1306 | + |
| 1307 | + def _git_remote_create(self, app, remote_name): |
| 1308 | + """ |
| 1309 | + Adds a git_remote to the current repository. Sets up a git root if necessary. |
| 1310 | + """ |
| 1311 | + hostname = urlparse.urlparse(self._settings['controller']).netloc.split(':')[0] |
| 1312 | + git_remote = "ssh://git@{hostname}:2222/{app}.git".format(**locals()) |
| 1313 | + try: |
| 1314 | + self._session.git_root() |
| 1315 | + except EnvironmentError: |
| 1316 | + return |
| 1317 | + try: |
| 1318 | + subprocess.check_call( |
| 1319 | + ['git', 'remote', 'add', remote_name, git_remote], |
| 1320 | + stdout=subprocess.PIPE) |
| 1321 | + self._logger.info('Git remote {} added'.format(remote_name)) |
| 1322 | + except subprocess.CalledProcessError: |
| 1323 | + self._logger.error('Could not create Deis remote') |
| 1324 | + sys.exit(1) |
| 1325 | + |
1276 | 1326 | def limits(self, args): |
1277 | 1327 | """ |
1278 | 1328 | Valid commands for limits: |
|
0 commit comments