grip_hook.git¶
grip_hook.git ¶
Thin wrapper around the git CLI: repository discovery and diff collection.
LS_REMOTE_TIMEOUT
module-attribute
¶
Seconds to wait for git ls-remote before trusting the local remote-tracking refs.
PushedRef
dataclass
¶
One line of the pre-push hook's stdin.
Source code in src/grip_hook/git.py
parse
classmethod
¶
Parse <local ref> <local sha> <remote ref> <remote sha>; None if malformed.
Diff
dataclass
¶
A collected diff, ready to be sent to a provider.
Source code in src/grip_hook/git.py
description
instance-attribute
¶
Human-readable description of what is being diffed, e.g. staged changes.
context
class-attribute
instance-attribute
¶
Optional text about the task the diff solves, shown to the model as data.
digest
property
¶
Stable fingerprint of the patch content, used to remember passed quizzes.
Git ¶
Run git commands inside one repository.
Source code in src/grip_hook/git.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
run ¶
Run git <args> and return stdout, raising :class:GitError on failure.
Source code in src/grip_hook/git.py
ok ¶
Return True when git <args> exits successfully.
root ¶
git_dir ¶
hooks_dir ¶
Where hooks live, honouring core.hooksPath.
Source code in src/grip_hook/git.py
rev_exists ¶
empty_tree ¶
unpushed_base ¶
Find a base to diff local_sha against that covers every unpushed commit.
That is the parent of the oldest commit reachable from local_sha but not from
any remote (or from remote only, when given). When that oldest commit is a root
commit the empty tree is returned so the whole history is covered. Returns None
when every commit is already on a remote.
Source code in src/grip_hook/git.py
unpushed_base_live ¶
:meth:unpushed_base against the refs remote has now, not the local copies.
Remote-tracking refs go stale: a branch deleted upstream after its pull request
merged stays in refs/remotes until git fetch --prune, so its commits look
pushed when the remote no longer has them. This asks the remote with
git ls-remote. Returns None when every commit is on the remote, or when the
remote cannot be reached (then the local refs are all there is to go on).
Source code in src/grip_hook/git.py
default_branch ¶
The branch pull requests here merge into, as a revision (origin/main).
That is what <remote>/HEAD points at, for the current branch's remote (else
origin, else the first remote), then <remote>/main or <remote>/master,
then a local main or master. None when none of them exists.
Source code in src/grip_hook/git.py
branch_base ¶
(default branch, merge base) for head: where its pull request starts.
None when there is no default branch or it shares no history with head.
Source code in src/grip_hook/git.py
staged_diff ¶
range_diff ¶
range_diff(base: str, head: str, exclude: tuple[str, ...] = (), max_bytes: int = 200000, description: str | None = None) -> Diff
Changes between two revisions (base may be the empty tree).
Source code in src/grip_hook/git.py
worktree_diff ¶
Everything since base: commits plus staged and unstaged changes.
Source code in src/grip_hook/git.py
push_diff ¶
push_diff(refs: list[PushedRef], remote: str | None = None, exclude: tuple[str, ...] = (), max_bytes: int = 200000) -> Diff
Combined diff of everything a git push would send upstream.