【发布时间】:2012-12-04 22:28:09
【问题描述】:
我想使用 Fabric 命令来设置本地开发环境,作为其中的一部分,我希望能够设置 git 远程。这工作正常:
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')
问题出现在第二次运行时 - 当本地命令因为远程已经存在而爆炸时。我想通过先检查遥控器是否存在来防止这种情况发生:
在伪代码中,我想执行以下操作:
if 'myremote' in local('git remote'):
print 'Remote \'myremote\' already exists.'
else:
local('git remote add myremote git@myremote.com:myrepo.git')
我该怎么做?
【问题讨论】: