Capture git commit hash and working-tree state.
()
| 141 | |
| 142 | |
| 143 | def git_metadata() -> dict: |
| 144 | """Capture git commit hash and working-tree state.""" |
| 145 | meta: dict = {} |
| 146 | try: |
| 147 | meta["commit"] = subprocess.check_output( |
| 148 | ["git", "rev-parse", "HEAD"], text=True, stderr=subprocess.DEVNULL |
| 149 | ).strip() |
| 150 | meta["commit_short"] = subprocess.check_output( |
| 151 | ["git", "rev-parse", "--short", "HEAD"], |
| 152 | text=True, |
| 153 | stderr=subprocess.DEVNULL, |
| 154 | ).strip() |
| 155 | except Exception: |
| 156 | meta["commit"] = None |
| 157 | meta["commit_short"] = None |
| 158 | |
| 159 | try: |
| 160 | status = subprocess.check_output( |
| 161 | ["git", "status", "--porcelain"], text=True, stderr=subprocess.DEVNULL |
| 162 | ).strip() |
| 163 | meta["dirty"] = bool(status) |
| 164 | except Exception: |
| 165 | meta["dirty"] = None |
| 166 | |
| 167 | return meta |
nothing calls this directly
no outgoing calls
no test coverage detected