Error Fabric: Fatal error: local () encountered an error (return code 2) while executing 'git commit -m' message '

I am trying to configure fabfile to deploy my Django application.

I cannot understand why I am getting this error:

Fatal error: local () encountered an error (return code 2) while executing 'git commit -m' changed settings for prodserver '

$ fab create_branch_deploy_to_prodserver [localhost] run: git checkout prodserver_server [localhost] run: git merge master [localhost] run: cp settings_prodserver.py settings.py [localhost] run: git add settings.py [localhost] run: git commit -m 'changed settings for prodserver' Fatal error: local() encountered an error (return code 1) while executing 'git commit -m 'changed settings for prodserver'' Aborting. 

Here, if the Fabric function:

 def create_branch_deploy_to_prodserver(): local("git checkout prodserver_server") local("git merge master") local('cp settings_prodserver.py settings.py') # #local('git rm fabfile.py') #This is also creating error so it commented out local('git add settings.py') local("git commit -m 'changed settings for prodserver'") 

Is it possible to make git commit from Fabric?

+6
git python fabric
source share
2 answers

I was able to diagnose the problem when I added capture = False to the declaration:

 local('git rm fabfile.py', capture=False) local('git add settings.py', capture=False) 

This allowed us to display the error in more detail.

Apparently, the Fabric developer will return the local behavior back so as not to capture by default, in 1.0.

+6
source share

Is this a python related issue like the one described in this thread ?

The main problem is that the stdout / stderr capture is for launching a / sudo call, not for every task.

It would be great if you could explain to me how I could collect the result and the error by only modifying the file called fabfile_runner.py .
The idea of ​​the fabric task itself could be unmodified, this would allow the factory to load the same file that you checked manually.

Check the source of the fabric and look in the "tests" folder, in particular tests / utils.py. It contains one decorator, @mock_streams , which is capable of wrapping a function (any function in any Python code is not a fabric specificity as I mentioned) and redirecting sys.stdout and / or sys.stderr for capture / examination.

It is intended to be used around functions, being a decorator, so you can use it directly by changing your fabfile_runner.py like this:

fabfile_runner.py

 from StringIO import StringIO import sys from test_fabfile import hello_world def execute(task): output = StringIO() error = StringIO() sys.stdout = output sys.stderr = error task() sys.stdout = sys.__stdout__ sys.stderr = sys.__stderr__ return (output.getvalue(), error.getvalue()) output, error = execute(hello_world) print "output : %s" %output print "error : %s" %error 
+1
source share

All Articles