| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
""" |
| 18 |
Git commands |
| 19 |
~~~~~~~~~~~~ |
| 20 |
|
| 21 |
""" |
| 22 |
|
| 23 |
|
| 24 |
def current_branch(ctx): |
| 25 |
""" |
| 26 |
Find the current branch |
| 27 |
|
| 28 |
Returns: |
| 29 |
str: The current branch or None |
| 30 |
""" |
| 31 |
return ( |
| 32 |
command( |
| 33 |
ctx, ctx.s("branch --color=never --show-current"), hide=True |
| 34 |
).stdout.strip() |
| 35 |
or None |
| 36 |
) |
| 37 |
|
| 38 |
|
| 39 |
def sha(ctx): |
| 40 |
""" |
| 41 |
Find current sha |
| 42 |
|
| 43 |
Returns: |
| 44 |
str: The current commit ID |
| 45 |
""" |
| 46 |
return ( |
| 47 |
command(ctx, ctx.s("log -1 --format=%H"), hide=True).stdout.strip() |
| 48 |
or None |
| 49 |
) |
| 50 |
|
| 51 |
|
| 52 |
def command(ctx, cmd, **kwargs): |
| 53 |
""" |
| 54 |
Run git command |
| 55 |
|
| 56 |
Parameters: |
| 57 |
cmd (list): |
| 58 |
The command to run |
| 59 |
|
| 60 |
**kwargs: |
| 61 |
Extra arguments for ctx.run() |
| 62 |
|
| 63 |
Returns: |
| 64 |
The run result |
| 65 |
""" |
| 66 |
env = dict(LC_ALL="C") |
| 67 |
cmd = [ctx.which("git"), "--no-pager"] + cmd |
| 68 |
with ctx.shell.root_dir(): |
| 69 |
return ctx.run(ctx.c(cmd), env=env, **kwargs) |