From 4e56adef58dffb6959c1e3e94c90c2910ebc99b2 Mon Sep 17 00:00:00 2001 From: clerie Date: Fri, 23 May 2025 14:28:03 +0200 Subject: [PATCH 1/3] pkgs/git-show-link: Display error message when not executed in a git repo --- pkgs/git-show-link/git-show-link.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkgs/git-show-link/git-show-link.py b/pkgs/git-show-link/git-show-link.py index 63647d0..aeb8c94 100755 --- a/pkgs/git-show-link/git-show-link.py +++ b/pkgs/git-show-link/git-show-link.py @@ -29,6 +29,11 @@ class FormatArgs: commit: str = None branch: str = None +def is_git_repo(): + s = subprocess.run(["git", "rev-parse"], capture_output=True, text=True) + + return s.returncode == 0 + def get_remote_branch(): s = subprocess.run(["git", "status", "--porcelain", "-uno", "-b", "--no-ahead-behind"], capture_output=True, text=True) @@ -71,6 +76,11 @@ def main(): args = parser.parse_args() + if not is_git_repo(): + print("Not a git repo") + + exit(1) + r = get_remote_branch() remote_url = get_remote_url(r["remote"]) From 46d23fb98a848a3cf61613d81fba3832de1aac38 Mon Sep 17 00:00:00 2001 From: clerie Date: Fri, 23 May 2025 14:51:20 +0200 Subject: [PATCH 2/3] pkgs/git-show-link: Specify URL format using --remote-type --- pkgs/git-show-link/git-show-link.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/pkgs/git-show-link/git-show-link.py b/pkgs/git-show-link/git-show-link.py index aeb8c94..e7e78e6 100755 --- a/pkgs/git-show-link/git-show-link.py +++ b/pkgs/git-show-link/git-show-link.py @@ -5,20 +5,18 @@ from dataclasses import dataclass import re import subprocess -REMOTE_TYPES = [ - { - # github +REMOTE_TYPES = { + "github": { "match": re.compile(r'git@github.com:(?P[\w\.-]+)/(?P[\w\.-]+).git'), "format-branch": lambda g: f"https://github.com/{g.username}/{g.project}/tree/{g.branch}/", "format-commit": lambda g: f"https://github.com/{g.username}/{g.project}/commit/{g.commit}/", }, - { - # gitea + "gitea": { "match": re.compile(r'(?P[\w\.-]+)@(?P[\w\.-]+):(?P[\w\.-]+)/(?P[\w\.-]+).git'), "format-branch": lambda g: f"https://{g.host}/{g.username}/{g.project}/src/branch/{g.branch}/", "format-commit": lambda g: f"https://{g.host}/{g.username}/{g.project}/commit/{g.commit}/", }, -] +} @dataclass class FormatArgs: @@ -73,6 +71,7 @@ def main(): ) parser.add_argument("--branch", dest="display_branch", action='store_true', help="Display link to branch, instead to commit") + parser.add_argument("--remote-type", dest="remote_type", choices=REMOTE_TYPES.keys(), help="Specify remote type") args = parser.parse_args() @@ -85,12 +84,23 @@ def main(): remote_url = get_remote_url(r["remote"]) - for remote_type in REMOTE_TYPES: + selected_remote_types = REMOTE_TYPES + + if args.remote_type is not None: + selected_remote_types = { + args.remote_type: REMOTE_TYPES[args.remote_type], + } + + remote_type_found = False + + for remote_type_name, remote_type in selected_remote_types.items(): m = remote_type["match"].match(remote_url) if m is None: continue + remote_type_found = True + g = FormatArgs(**m.groupdict()) if args.display_branch: @@ -102,6 +112,10 @@ def main(): print(remote_type["format-commit"](g)) break + if not remote_type_found: + print("No remote type matched") + exit(1) + if __name__ == "__main__": main() From 4e2e1e9cc9d7ec6f9845cee7b90c33ccb9ebe44c Mon Sep 17 00:00:00 2001 From: Flake Update Bot Date: Sat, 24 May 2025 03:03:06 +0200 Subject: [PATCH 3/3] Update nixpkgs 2025-05-24-01-03 --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index fb4be50..5197fba 100644 --- a/flake.lock +++ b/flake.lock @@ -551,11 +551,11 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1746328495, - "narHash": "sha256-uKCfuDs7ZM3QpCE/jnfubTg459CnKnJG/LwqEVEdEiw=", + "lastModified": 1747744144, + "narHash": "sha256-W7lqHp0qZiENCDwUZ5EX/lNhxjMdNapFnbErcbnP11Q=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "979daf34c8cacebcd917d540070b52a3c2b9b16e", + "rev": "2795c506fe8fb7b03c36ccb51f75b6df0ab2553f", "type": "github" }, "original": {