import subprocess


class GitInfo:
    def __init__(self, repo_path):
        self.repo_path = repo_path

    def execute_git_command(self, command):
        git_command = ['sudo', 'git', '-C', self.repo_path] + command.split()
        result = subprocess.check_output(git_command).strip().decode('utf-8')
        return result

    def get_commit_hash(self):
        commit_hash = self.execute_git_command('rev-parse --short HEAD')
        return commit_hash

    def get_branch_or_tag(self):
        try:
            branch = self.execute_git_command('symbolic-ref --short HEAD')
            return branch
        except subprocess.CalledProcessError:
            try:
                detached_head = self.execute_git_command('describe --tags --exact-match HEAD')
                return detached_head
            except:
                return "none"


