diff --git a/ghstack/github_utils.py b/ghstack/github_utils.py index d055132..f8000ac 100644 --- a/ghstack/github_utils.py +++ b/ghstack/github_utils.py @@ -27,7 +27,7 @@ def get_github_repo_name_with_owner( # Grovel in remotes to figure it out remote_url = sh.git("remote", "get-url", remote_name) while True: - match = r"^git@{github_url}:([^/]+)/(.+?)(?:\.git)?$".format( + match = r"^git@{github_url}:/?([^/]+)/(.+?)(?:\.git)?$".format( github_url=github_url ) m = re.match(match, remote_url) diff --git a/test/github_utils/get_repo_name_with_owner.py.test b/test/github_utils/get_repo_name_with_owner.py.test index 93a6ed0..9f5e3ef 100644 --- a/test/github_utils/get_repo_name_with_owner.py.test +++ b/test/github_utils/get_repo_name_with_owner.py.test @@ -63,3 +63,10 @@ assert_eq( ), {"owner": "ezyang", "name": "ghstack.dotted"}, ) +git("remote", "add", "with-leading-slash", "git@github.com:/ezyang/ghstack.git") +assert_eq( + ghstack.github_utils.get_github_repo_name_with_owner( + sh=sh, github_url="github.com", remote_name="with-leading-slash" + ), + {"owner": "ezyang", "name": "ghstack"}, +)