File indexing completed on 2024-04-21 05:41:18

0001 """
0002 Module of the rewrite-remote subcommand
0003 """
0004 
0005 # SPDX-FileCopyrightText: 2020 Jonah BrĂ¼chert <jbb@kaidan.im>
0006 #
0007 # SPDX-License-Identifier: GPL-2.0-or-later
0008 
0009 import argparse
0010 from git import Repo
0011 
0012 from lab.utils import Utils
0013 
0014 
0015 def parser(
0016     subparsers: argparse._SubParsersAction,  # pylint: disable=protected-access
0017 ) -> argparse.ArgumentParser:
0018     """
0019     Subparser for the rewrite-remote command
0020     """
0021     rewrite_remote_parser: argparse.ArgumentParser = subparsers.add_parser(
0022         "rewrite-remote", help="Rewrite the remote url to ssh"
0023     )
0024     rewrite_remote_parser.add_argument(
0025         "remote",
0026         type=str,
0027         nargs=1,
0028         help="Name of the remote to rewrite",
0029     )
0030     return rewrite_remote_parser
0031 
0032 
0033 def run(args: argparse.Namespace) -> None:
0034     """
0035     :param args: parsed arguments
0036     """
0037     repo: Repo = Utils.get_cwd_repo()
0038     remote_url = repo.git.remote("get-url", args.remote)
0039     ssh_url = Utils.ssh_url_from_http(Utils.normalize_url(remote_url))
0040     repo.git.remote("set-url", args.remote, ssh_url)