From ae724d232496df7c5ed636d15922a2ca7de218b1 Mon Sep 17 00:00:00 2001 From: Neal Richardson Date: Mon, 6 Jul 2026 11:31:25 -0400 Subject: [PATCH] Fix git metadata detection for deploy with bare manifest filename dirname("manifest.json") yields "", which subprocess rejects as cwd, causing git metadata detection to be silently skipped. Fall back to the current directory in _run_git_command. Fixes #770 Co-Authored-By: Claude Opus 4.8 (1M context) --- docs/CHANGELOG.md | 4 ++++ rsconnect/git_metadata.py | 4 +++- tests/test_git_metadata.py | 13 +++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index eceb3fced..a82b7a443 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- Fixed a bug where `rsconnect deploy manifest manifest.json` (and other deploy + commands given a bare filename) failed to detect git metadata. The directory + passed to git detection was empty in that case, which caused detection to be + silently skipped; it now falls back to the current directory. - The `CONNECT_SERVER_VERSION` environment variable can now be set to tell rsconnect-python which Connect version to assume for feature-availability checks. Some servers can be configured to suppress their version, which makes diff --git a/rsconnect/git_metadata.py b/rsconnect/git_metadata.py index a5480e194..a0c315724 100644 --- a/rsconnect/git_metadata.py +++ b/rsconnect/git_metadata.py @@ -22,7 +22,9 @@ def _run_git_command(args: list[str], cwd: str) -> Optional[str]: try: result = subprocess.run( ["git"] + args, - cwd=cwd, + # dirname() of a bare filename (e.g. "manifest.json") yields "", + # which subprocess rejects; treat it as the current directory. + cwd=cwd or ".", capture_output=True, text=True, timeout=5, diff --git a/tests/test_git_metadata.py b/tests/test_git_metadata.py index c15e19fb3..19080782f 100644 --- a/tests/test_git_metadata.py +++ b/tests/test_git_metadata.py @@ -123,6 +123,19 @@ def test_detect_git_metadata_non_git_dir(self): metadata = detect_git_metadata(tmpdir) assert metadata == {} + def test_is_git_repo_empty_dir_uses_cwd(self, git_repo, monkeypatch): + # dirname("manifest.json") yields "", which subprocess rejects as cwd. + # An empty directory should be treated as the current directory so that + # `rsconnect deploy manifest manifest.json` still detects git metadata. + monkeypatch.chdir(git_repo) + assert is_git_repo("") is True + + def test_detect_git_metadata_empty_dir_uses_cwd(self, git_repo, monkeypatch): + monkeypatch.chdir(git_repo) + metadata = detect_git_metadata("") + assert metadata["source"] == "git" + assert metadata["source_repo"] == "https://github.com/user/repo.git" + class TestServerVersionSupport: def test_server_supports_git_metadata(self):