MCPcopy Create free account
hub / github.com/idank/explainshell / git_metadata

Function git_metadata

explainshell/util.py:143–167  ·  view source on GitHub ↗

Capture git commit hash and working-tree state.

()

Source from the content-addressed store, hash-verified

141
142
143def 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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected