def checkout_pull(clone_url, commit, out):
    build_dir = os.environ['BUILD_DIR']
    run('umount ${CHROOT_COPY}/proc', fail_hard=False)
    run('rsync --delete -apv ${CHROOT_MASTER}/ ${CHROOT_COPY}')
    run('rm -rf ${CHROOT_COPY}${SCRIPTS_DIR}')
    run('cp -a ${SCRIPTS_DIR} ${CHROOT_COPY}${SCRIPTS_DIR}')
    run('rm -rf ${BUILD_DIR}')
    run('mkdir -p ${BUILD_DIR}')
    run('git clone ${CLONE_URL} ${BUILD_DIR}')
    run(('git remote add pull ' + clone_url), cwd=build_dir, stdout=out, stderr=out)
    run('git fetch pull', cwd=build_dir, stdout=out, stderr=out)
    if (run(('git merge ' + commit), fail_hard=False, cwd=build_dir, stdout=out, stderr=out) != 0):
        return False
    run('chown -R ${BUILD_USER}:${BUILD_GROUP} ${BUILD_DIR}', stdout=out, stderr=out)
    run('mount --bind /proc ${CHROOT_COPY}/proc')
    return True
def checkout_pull(clone_url, commit, out):
    build_dir = os.environ['BUILD_DIR']
    run('umount ${CHROOT_COPY}/proc', fail_hard=False)
    run('rsync --delete -apv ${CHROOT_MASTER}/ ${CHROOT_COPY}')
    run('rm -rf ${CHROOT_COPY}${SCRIPTS_DIR}')
    run('cp -a ${SCRIPTS_DIR} ${CHROOT_COPY}${SCRIPTS_DIR}')
    run('rm -rf ${BUILD_DIR}')
    run('mkdir -p ${BUILD_DIR}')
    run('git clone ${CLONE_URL} ${BUILD_DIR}')
    run(('git remote add pull ' + clone_url), cwd=build_dir, stdout=out, stderr=out)
    run('git fetch pull', cwd=build_dir, stdout=out, stderr=out)
    if (run(('git merge ' + commit), fail_hard=False, cwd=build_dir, stdout=out, stderr=out) != 0):
        return False
    run('chown -R ${BUILD_USER}:${BUILD_GROUP} ${BUILD_DIR}', stdout=out, stderr=out)
    run('mount --bind /proc ${CHROOT_COPY}/proc')
    return True