Returns `(sha, comment, diff, branch)`, all items are str or None if not available. directory: Root of git checkout.
( directory)
| 366 | |
| 367 | |
| 368 | def git_info( directory): |
| 369 | ''' |
| 370 | Returns `(sha, comment, diff, branch)`, all items are str or None if not |
| 371 | available. |
| 372 | |
| 373 | directory: |
| 374 | Root of git checkout. |
| 375 | ''' |
| 376 | sha, comment, diff, branch = '', '', '', '' |
| 377 | cp = subprocess.run( |
| 378 | f'cd {directory} && (PAGER= git show --pretty=oneline|head -n 1 && git diff)', |
| 379 | capture_output=1, |
| 380 | shell=1, |
| 381 | text=1, |
| 382 | ) |
| 383 | if cp.returncode == 0: |
| 384 | sha, _ = cp.stdout.split(' ', 1) |
| 385 | comment, diff = _.split('\n', 1) |
| 386 | cp = subprocess.run( |
| 387 | f'cd {directory} && git rev-parse --abbrev-ref HEAD', |
| 388 | capture_output=1, |
| 389 | shell=1, |
| 390 | text=1, |
| 391 | ) |
| 392 | if cp.returncode == 0: |
| 393 | branch = cp.stdout.strip() |
| 394 | log(f'git_info(): directory={directory!r} returning branch={branch!r} sha={sha!r} comment={comment!r}') |
| 395 | return sha, comment, diff, branch |
| 396 | |
| 397 | |
| 398 | def git_patch(directory, patch, hard=False): |