|
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,12 @@ 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 | + self._git_remote_create(app_id, args.get('--remote')) |
488 | 480 |
|
489 | 481 | def apps_destroy(self, args): |
490 | 482 | """ |
@@ -1273,6 +1265,58 @@ def domains_list(self, args): |
1273 | 1265 | else: |
1274 | 1266 | raise ResponseError(response) |
1275 | 1267 |
|
| 1268 | + def git(self, args): |
| 1269 | + """ |
| 1270 | + Valid commands for git: |
| 1271 | +
|
| 1272 | + git:remote Adds git remote of application to repository |
| 1273 | +
|
| 1274 | + Use `deis help [command]` to learn more. |
| 1275 | + """ |
| 1276 | + raise DocoptExit('`deis git` is not a valid command, try `deis help git`') |
| 1277 | + |
| 1278 | + def git_remote(self, args): |
| 1279 | + """ |
| 1280 | + Adds git remote of application to repository |
| 1281 | +
|
| 1282 | + Usage: deis git:remote [options] |
| 1283 | +
|
| 1284 | + Options: |
| 1285 | + -a --app=<app> |
| 1286 | + the uniquely identifiable name for the application. |
| 1287 | +
|
| 1288 | + -r --remote REMOTE |
| 1289 | + name of remote to create. [default: deis] |
| 1290 | + """ |
| 1291 | + app = args.get('--app') |
| 1292 | + if not app: |
| 1293 | + app = self._session.app |
| 1294 | + response = self._dispatch( |
| 1295 | + 'get', "/v1/apps/{app}/domains".format(app=app)) |
| 1296 | + if response.status_code == requests.codes.ok: |
| 1297 | + self._git_remote_create(app, args.get('--remote')) |
| 1298 | + else: |
| 1299 | + raise ResponseError(response) |
| 1300 | + |
| 1301 | + def _git_remote_create(self, app, remote_name): |
| 1302 | + """ |
| 1303 | + Adds a git_remote to the current repository. Sets up a git root if necessary. |
| 1304 | + """ |
| 1305 | + hostname = urlparse.urlparse(self._settings['controller']).netloc.split(':')[0] |
| 1306 | + git_remote = "ssh://git@{hostname}:2222/{app}.git".format(**locals()) |
| 1307 | + try: |
| 1308 | + self._session.git_root() |
| 1309 | + except EnvironmentError: |
| 1310 | + return |
| 1311 | + try: |
| 1312 | + subprocess.check_call( |
| 1313 | + ['git', 'remote', 'add', remote_name, git_remote], |
| 1314 | + stdout=subprocess.PIPE) |
| 1315 | + self._logger.info('Git remote {} added'.format(remote_name)) |
| 1316 | + except subprocess.CalledProcessError: |
| 1317 | + self._logger.error('Could not create Deis remote') |
| 1318 | + sys.exit(1) |
| 1319 | + |
1276 | 1320 | def limits(self, args): |
1277 | 1321 | """ |
1278 | 1322 | Valid commands for limits: |
|
0 commit comments