import subprocess
import logging
import os

# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

def git_commit(message: str) -> bool:
    """
    Commits changes to the git repository with the given message.

    Args:
        message: The commit message.

    Returns:
        True if the commit was successful, False otherwise.
    """
    try:
        result = subprocess.run(['git', 'commit', '-m', message], capture_output=True, text=True, check=True)
        logging.info(f"Git commit successful: {result.stdout}")
        return True
    except subprocess.CalledProcessError as e:
        logging.error(f"Git commit failed: {e.stderr}")
        return False
    except Exception as e:
        logging.error(f"An unexpected error occurred: {e}")
        return False


def git_push() -> bool:
    """
    Pushes changes to the remote git repository.

    Returns:
        True if the push was successful, False otherwise.
    """
    try:
        result = subprocess.run(['git', 'push'], capture_output=True, text=True, check=True)
        logging.info(f"Git push successful: {result.stdout}")
        return True
    except subprocess.CalledProcessError as e:
        logging.error(f"Git push failed: {e.stderr}")
        return False
    except Exception as e:
        logging.error(f"An unexpected error occurred: {e}")
        return False


def git_pull() -> bool:
    """
    Pulls changes from the remote git repository.

    Returns:
        True if the pull was successful, False otherwise.
    """
    try:
        result = subprocess.run(['git', 'pull'], capture_output=True, text=True, check=True)
        logging.info(f"Git pull successful: {result.stdout}")
        return True
    except subprocess.CalledProcessError as e:
        logging.error(f"Git pull failed: {e.stderr}")
        return False
    except Exception as e:
        logging.error(f"An unexpected error occurred: {e}")
        return False


if __name__ == '__main__':
    # Example usage
    if git_commit("Automated commit"):
        print("Commit successful")
        if git_push():
            print("Push successful")
        else:
            print("Push failed")
    else:
        print("Commit failed")

    if git_pull():
        print("Pull successful")
    else:
        print("Pull failed")