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

I’m trying to setup a fabfile to deploy my Django app.

I can’t figure out why I’m getting this error:

  • Are there any tag values I should disallow for my deploy script?
  • git update/patch on remote host without internet
  • SSH key passphrase with git pull using Fabric
  • fabric script / bash: how to detect git file changed
  • set umask on remote server through fabric script
  • Python Fabric error when executing git archive command
  • 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''

    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's commented out
        local('git add settings.py')  
        local("git commit -m 'changed settings for prodserver'")  

    Is it possible to make a git commit from Fabric?

  • Git doesn't detect rename when file has been modified significantly after move
  • Git - How to split code in a feature branch in such a way that future merges/rebases from master don't remove the code from the feature branch
  • Git for windows paging
  • How to group output in command shell
  • Interconversion of gitignore and hgignore?
  • Git reports fatal: write error: invalid argument with git clone on git: protocol
  • 2 Solutions collect form web for “Fabric error: Fatal error: local() encountered an error (return code 2) while executing 'git commit -m 'message'”

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

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

    This allowed the error to be displayed more verbosely.

    Apparently, the maintainer of Fabric will to revert local‘s behavior back to not capturing by default, in 1.0.

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

    The main problem with this is that the stdout/stderr capturing is per-run/sudo invocation and not per-task.

    It would be wonderful if you could explain me how I could collect outputand error by only modifying the file called fabfile_runner.py.
    Idealy the fabric task itself could be unmodified, this would allow to upload the the factory the same file that you have tested manually.

    Check out the Fabric source and look in the ‘tests’ folder, specifically tests/utils.py. It contains a single decorator, @mock_streams, which is capable of wrapping a function (any function in any Python code — it’s not Fabric specific, as I mentioned) and redirecting sys.stdout and/or sys.stderr for capture/examination.

    It’s designed for use around functions, being a decorator, so you could use it directly by modifying your fabfile_runner.py like so:


    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
        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
    Git Baby is a git and github fan, let's start git clone.