Debian Codegraph @

tasks/util/git.py

raw symbols SCIP
1 # -*- coding: ascii -*-
2 #
3 # Copyright 2018 - 2025
4 # Andr\xe9 Malo or his licensors, as applicable
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
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)