| Conditions | 7 |
| Total Lines | 24 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import git |
||
| 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 | |||
| 32 |