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 0faf21b76..a4722a1e3 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):