1
0

pkgs/git-show-link: Normalize paths

This commit is contained in:
2025-05-25 20:21:51 +02:00
parent d334a1a73c
commit efad5a6cbb

View File

@@ -4,6 +4,7 @@ import argparse
from dataclasses import dataclass
import re
import subprocess
from pathlib import Path
REMOTE_TYPES = {
"github": {
@@ -37,9 +38,17 @@ def is_git_repo():
return s.returncode == 0
def get_git_dir():
s = subprocess.run(["git", "rev-parse", "--show-toplevel"], capture_output=True, text=True)
return Path(s.stdout.strip())
def get_remote_branch():
s = subprocess.run(["git", "status", "--porcelain", "-uno", "-b", "--no-ahead-behind"], capture_output=True, text=True)
if s.stdout.startswith("## HEAD (no branch)"):
print("Detached head, can't link")
exit(1)
git_status_branch_info = s.stdout.splitlines()[0][3:].split()[0]
branches = git_status_branch_info.split("...")
@@ -86,6 +95,8 @@ def main():
exit(1)
git_dir_path = get_git_dir()
r = get_remote_branch()
remote_url = get_remote_url(r["remote"])
@@ -108,7 +119,17 @@ def main():
remote_type_found = True
g = FormatArgs(**m.groupdict())
g.path = args.path
if args.path is not None:
path = Path(args.path).absolute()
path = path.relative_to(git_dir_path)
path = str(path)
if path == ".":
path = ""
g.path = path
if args.path is not None:
if args.display_branch: