I would like to use a Fabric command to set up a local development environment, and as part of that I want to be able to set up a git remote. This works fine:
from fabric.api import local
def set_remote():
""" Set up git remote for pushing to dev."""
local('git remote add myremote git@myremote.com:myrepo.git')
The problem comes with running this a second time – when the local command bombs because the remote already exists. I’d like to prevent this by checking if the remote exists first:
In pseudocode, I’d like to do the following:
if 'myremote' in local('git remote'):
print 'Remote \'myremote\' already exists.'
else:
local('git remote add myremote git@myremote.com:myrepo.git')
How can I do this?
You can use the
settingscontext manager towarn_only:Alternately, you can set the
capturekeyword arg on thelocalcommand toTrue: