1+ import os
12import re
23from subprocess import DEVNULL , PIPE , SubprocessError , check_output , run
34
2122def 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:
4350def 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
5164def 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
0 commit comments