Skip to content

Commit 61c8755

Browse files
kevinbluettMatthew Fisher
authored andcommitted
feat(client): add discrete git:remote command
1 parent a716eed commit 61c8755

1 file changed

Lines changed: 65 additions & 15 deletions

File tree

client/deis.py

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
2424
keys manage ssh keys used for `git push` deployments
2525
perms manage permissions for applications
26+
git manage git for applications
2627
2728
Shortcut commands, use ``deis shortcuts`` to see all::
2829
@@ -436,6 +437,9 @@ def apps_create(self, args):
436437
437438
-b --buildpack BUILDPACK
438439
a buildpack url to use for this app
440+
441+
-r --remote REMOTE
442+
name of remote to create, default 'deis'
439443
"""
440444
body = {}
441445
app_name = None
@@ -467,24 +471,15 @@ def apps_create(self, args):
467471
if buildpack:
468472
self._config_set(app_id, {'BUILDPACK_URL': buildpack})
469473

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())
477474
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())
478477
self._logger.info('remote available at {}'.format(git_remote))
479478
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)
488483

489484
def apps_destroy(self, args):
490485
"""
@@ -1273,6 +1268,61 @@ def domains_list(self, args):
12731268
else:
12741269
raise ResponseError(response)
12751270

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+
12761326
def limits(self, args):
12771327
"""
12781328
Valid commands for limits:

0 commit comments

Comments
 (0)