Skip to content

Commit 29590cf

Browse files
committed
Strip trailing newline from get_remote_url
git remote get-url emits the URL with a trailing newline. The decoded result was returned verbatim, leaving the newline embedded in the URL string used by submodule URL resolution and downstream string operations. https://claude.ai/code/session_01KKvrvnVvsBChohuxbRRmzA
1 parent 265943f commit 29590cf

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Release 0.14.1 (unreleased)
55
* Fix ``Version`` comparison raising ``AttributeError`` when compared against a non-``Version`` object
66
* Fix ``dfetch add`` matching a remote whose base URL is only a string prefix (not a path prefix) of the project URL
77
* Fix git ref resolution spuriously matching the first reference for an empty revision
8+
* Strip the trailing newline from the git origin URL returned by ``get_remote_url``
89

910
Release 0.14.0 (released 2026-06-14)
1011
===========================

dfetch/vcs/git.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ def get_remote_url() -> str:
682682
"""Get the url of the remote origin."""
683683
try:
684684
result = run_on_cmdline(logger, ["git", "remote", "get-url", "origin"])
685-
decoded_result = str(result.stdout.decode())
685+
decoded_result = str(result.stdout.decode()).strip()
686686
except SubprocessCommandError:
687687
decoded_result = ""
688688

tests/test_git_vcs.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,13 @@ def test_ls_remote():
318318
assert info == expected
319319

320320

321+
def test_get_remote_url_strips_trailing_newline():
322+
"""git remote get-url appends a newline that must not leak into the URL."""
323+
with patch("dfetch.vcs.git.run_on_cmdline") as run_on_cmdline_mock:
324+
run_on_cmdline_mock.return_value.stdout = b"https://github.com/org/repo.git\n"
325+
assert GitLocalRepo.get_remote_url() == "https://github.com/org/repo.git"
326+
327+
321328
def test_find_branch_tip_or_tag_from_sha_empty_rev_matches_nothing():
322329
"""An empty revision must not spuriously match the first reference."""
323330
info = {

0 commit comments

Comments
 (0)