mercredi 9 août 2017

Fabric script: running git commands return fatal error (code 128)

I have a fabfile that is getting an error when trying to run git commands.

The fabfile output:

[localhost] local: git log -n 1 --format=%H
[abcd@website-staging.com] run: cd /home/abcd/sites/http://ift.tt/2wJNtFA && git reset --hard bf531d9a34e9ea2a531d28d7693f055b0b3bea8a
[abcd@website-staging.com] out: fatal: Could not parse object 'bf531d9a34e9ea2a531d28d7693f055b0b3bea8a'.
[abcd@website-staging.com] out:

Fatal error: run() received nonzero return code 128 while executing!

Requested: cd /home/abcd/sites/http://ift.tt/2wJNtFA && git reset --hard bf531d9a34e9ea2a531d28d7693f055b0b3bea8a
Executed: /bin/bash -l -c "cd /home/abcd/sites/http://ift.tt/2wJNtFA && git reset --hard bf531d9a34e9ea2a531d28d7693f055b0b3bea8a"

Aborting.
Disconnecting from abcd@website-staging.com... done.

Here is the fabfile:

from fabric.contrib.files import append, exists, sed
from fabric.api import env, local, run
import random

def deploy():
    site_folder = f'/home/{env.user}/sites/{env.host}'
    source_folder = site_folder + '/source'
    _get_latest_source(source_folder)

def _get_latest_source(source_folder):
    if exists(source_folder + '/.git'):
        run(f'cd {source_folder} && git fetch')
    else:
        run(f'git clone {REPO_URL} {source_folder}')
    current_commit = local("git log -n 1 --format=%H", capture=True)
    run('cd %s && git reset --hard %s' % (source_folder, current_commit))

Aucun commentaire:

Enregistrer un commentaire