Skip to content

Commit 0ccb43c

Browse files
committed
Attempt at fixing gh-lazy current repo handling
1 parent 9ef488a commit 0ccb43c

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

gh-lazy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
set -e
33

4+
export LAZY_GITHUB_ORIGINAL_PWD="$PWD"
45
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
5-
cd "$SCRIPT_DIR"
6-
exec "${SCRIPT_DIR}/start.sh"
6+
exec "${SCRIPT_DIR}/start.sh" "$@"

lazy_github/lib/git_cli.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import re
23
from subprocess import DEVNULL, PIPE, SubprocessError, check_output, run
34

@@ -21,7 +22,13 @@
2122
def current_local_repo_full_name(remote: str = "origin") -> str | None:
2223
"""Returns the owner/name associated with the remote of the git repo in the current working directory."""
2324
try:
24-
output = check_output(["git", "remote", "get-url", remote], stderr=DEVNULL).decode().strip()
25+
# Check if we have an original working directory from GitHub CLI extension
26+
original_pwd = os.environ.get("LAZY_GITHUB_ORIGINAL_PWD")
27+
cmd = ["git", "remote", "get-url", remote]
28+
if original_pwd:
29+
cmd = ["git", "-C", original_pwd, "remote", "get-url", remote]
30+
31+
output = check_output(cmd, stderr=DEVNULL).decode().strip()
2532
except SubprocessError:
2633
return None
2734

@@ -43,15 +50,27 @@ def current_local_repo_matches_selected_repo(remote: str = "origin") -> bool:
4350
def current_local_branch_name() -> str | None:
4451
"""Returns the name of the current branch for the git repo in the current working directory."""
4552
try:
46-
return check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"], stderr=DEVNULL).decode().strip()
53+
# Check if we have an original working directory from GitHub CLI extension
54+
original_pwd = os.environ.get("LAZY_GITHUB_ORIGINAL_PWD")
55+
cmd = ["git", "rev-parse", "--abbrev-ref", "HEAD"]
56+
if original_pwd:
57+
cmd = ["git", "-C", original_pwd, "rev-parse", "--abbrev-ref", "HEAD"]
58+
59+
return check_output(cmd, stderr=DEVNULL).decode().strip()
4760
except SubprocessError:
4861
return None
4962

5063

5164
def current_local_commit() -> str | None:
5265
"""Returns the commit sha for the git repo in the current working directory"""
5366
try:
54-
return check_output(["git", "rev-parse", "HEAD"], stderr=DEVNULL).decode().strip()
67+
# Check if we have an original working directory from GitHub CLI extension
68+
original_pwd = os.environ.get("LAZY_GITHUB_ORIGINAL_PWD")
69+
cmd = ["git", "rev-parse", "HEAD"]
70+
if original_pwd:
71+
cmd = ["git", "-C", original_pwd, "rev-parse", "HEAD"]
72+
73+
return check_output(cmd, stderr=DEVNULL).decode().strip()
5574
except SubprocessError:
5675
return None
5776

start.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env bash
22

3+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
4+
cd "$SCRIPT_DIR"
35
uv sync --quiet --frozen
4-
TERM=xterm-256color .venv/bin/python -m lazy_github -- "$@"
6+
TERM=xterm-256color .venv/bin/python -m lazy_github "$@"

0 commit comments

Comments
 (0)