check_repo.check_repo_health()   B
last analyzed

Complexity

Conditions 7

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 24
rs 8
c 0
b 0
f 0
cc 7
nop 1
1
import git
2
3
4
def check_repo_health(repo_path):
5
    try:
6
        repo = git.Repo(repo_path)
7
8
        # Check if the repository is valid
9
        if repo.bare:
10
            return "Repository is bare, no issues detected."
11
12
        # Check for uncommitted changes
13
        if repo.is_dirty(untracked_files=True):
14
            return "Repository has uncommitted changes."
15
16
        # Check for merge conflicts
17
        if repo.index.unmerged_blobs():
18
            return "Repository has merge conflicts."
19
20
        # Verify repository integrity
21
        repo.git.fsck()
22
    except git.exc.InvalidGitRepositoryError:
23
        return "Invalid Git repository."
24
    except Exception as e:
25
        return f"An error occurred: {e}"
26
    else:
27
        return "Repository is healthy, no issues detected."
28
29
# Example usage
30
repo_path = r'C:\dev\erivlis\graphinate'
31
print(check_repo_health(repo_path))
32