Skip to content

Commit 19673b2

Browse files
author
Matthew Fisher
committed
Merge pull request #3195 from bacongobbler/3027-add-git-remote-command
feat(client): add discrete git:remote command
2 parents 374f3fa + e35c458 commit 19673b2

1 file changed

Lines changed: 59 additions & 15 deletions

File tree

client/deis.py

Lines changed: 59 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,12 @@ 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+
self._git_remote_create(app_id, args.get('--remote'))
488480

489481
def apps_destroy(self, args):
490482
"""
@@ -1273,6 +1265,58 @@ def domains_list(self, args):
12731265
else:
12741266
raise ResponseError(response)
12751267

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+
12761320
def limits(self, args):
12771321
"""
12781322
Valid commands for limits:

0 commit comments

Comments
 (0)