Skip to content

Commit 5d73642

Browse files
committed
kt: Add push-git command
Pushes the local branch for either the kernel-src-tree or the kernel-dist-tree for the kernel workspaces selected. Useful especially if the branch you try to push is long and the remote is not selected. Signed-off-by: Roxana Nicolescu <rnicolescu@ciq.com>
1 parent af0952d commit 5d73642

4 files changed

Lines changed: 95 additions & 0 deletions

File tree

bin/kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import logging
55
import click
66

77
from kt.commands.checkout.command import checkout
8+
from kt.commands.git_push.command import git_push
89
from kt.commands.list_kernels.command import list_kernels
910
from kt.commands.setup.command import setup
1011

@@ -26,6 +27,7 @@ def main():
2627
cli.add_command(list_kernels)
2728
cli.add_command(setup)
2829
cli.add_command(checkout)
30+
cli.add_command(git_push)
2931
cli()
3032

3133

kt/commands/git_push/command.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import click
2+
3+
from kt.commands.git_push.impl import main
4+
from kt.ktlib.shell_completion import ShellCompletion
5+
6+
epilog = """
7+
It pushes the branch to remote for the kernelworkspace selected.
8+
Since for every kernel we have two repos, one for the kernel source
9+
and one for dist-git, an extra param is needed to select the repo.
10+
The kernel workspace is created beforehead with kt checkout command.
11+
Therefore, for every kernel we would have the branch
12+
{USER}_<official_kernel_branch>_<feature>, where feature is optional.
13+
This command will push this branch to the origin.
14+
15+
Examples:
16+
17+
\b
18+
$ kt git-push lts9_4 -k
19+
Will push the branch {USER}_ciqlts9_4 from kernel-src-tree from lts9_4 kernel
20+
workspace.
21+
22+
\b
23+
$ kt git-push lts9_4 -k -f
24+
Same as above but it will force push
25+
26+
\b
27+
$ kt git-push lts9_4 -d
28+
Will push the branch {USER}_lts94-9 from kernel-dist-tree from lts9_4 kernel
29+
workspace.
30+
31+
"""
32+
33+
34+
@click.command(epilog=epilog)
35+
@click.option(
36+
"-k",
37+
"--kernel-source",
38+
is_flag=True,
39+
help="It selects the kernel source repo",
40+
)
41+
@click.option(
42+
"-d",
43+
"--dist-git",
44+
is_flag=True,
45+
help="It selects the dist-git repo",
46+
)
47+
@click.option(
48+
"-f",
49+
"--force",
50+
is_flag=True,
51+
help="It force pushes the branch",
52+
)
53+
@click.argument("kernel_workspace", required=False, shell_complete=ShellCompletion.show_kernel_workspaces)
54+
def git_push(kernel_workspace, kernel_source, dist_git, force):
55+
main(
56+
name=kernel_workspace,
57+
kernel_source=kernel_source,
58+
dist_git=dist_git,
59+
force=force,
60+
)

kt/commands/git_push/impl.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import logging
2+
3+
from kt.ktlib.config import Config
4+
from kt.ktlib.kernel_workspace import KernelWorkspace
5+
6+
7+
def main(name: str, kernel_source: bool, dist_git: bool, force: bool):
8+
config = Config.load()
9+
kernel_workpath = config.kernels_dir / name
10+
kernel_workspace = KernelWorkspace.load_from_filepath(folder=kernel_workpath)
11+
12+
if kernel_source:
13+
kernel_workspace.src_worktree.push(force=force)
14+
elif dist_git:
15+
kernel_workspace.dist_worktree.push(force)
16+
else:
17+
logging.error("You need to specify the repo you want to push")

kt/ktlib/shell_completion.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,19 @@ def show_kernels(cls, ctx, param, incomplete):
99
kernels = KernelsInfo.from_yaml(config=config).kernels
1010

1111
return [kernel for kernel in kernels if kernel.startswith(incomplete)]
12+
13+
@classmethod
14+
def show_kernel_workspaces(cls, ctx, param, incomplete):
15+
config = Config.load()
16+
17+
# Since the current tooling uses a bunch of relative paths, we may have other dirs in the kernels directory.
18+
# Therefore, an extra check is required to make sure the kernel workspaces are the one recommended
19+
kernels = KernelsInfo.from_yaml(config=config).kernels.keys()
20+
21+
kernel_workspaces = [
22+
kernel_workspace.name
23+
for kernel_workspace in config.kernels_dir.iterdir()
24+
if kernel_workspace.is_dir() and kernel_workspace.name.split("_")[0] in kernels
25+
]
26+
27+
return [kernel_workspace for kernel_workspace in kernel_workspaces if kernel_workspace.startswith(incomplete)]

0 commit comments

Comments
 (0)