Skip to content

Commit d2dfef3

Browse files
cliffhallclaude
andcommitted
fix(git): parse a partial clone's fetch line in git_remote
Copilot review on #5373: a promisor remote's fetch line ends with its filter (`(fetch) [blob:none]`), which the stricter line parser rejected, so the fetch URL came back as <redacted>. Accept the optional filter suffix and keep it in the output. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent 9a8da68 commit d2dfef3

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

‎src/git/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Please note that mcp-server-git is currently in early development. The functiona
104104
- Lists the repository's remotes with their fetch and push URLs, like `git remote -v`
105105
- Inputs:
106106
- `repo_path` (string): Path to the Git repository.
107-
- Returns: One line per remote and direction, `<name>\t<url> (fetch)` or `(push)`, or `No remotes configured`
107+
- Returns: One line per remote and direction, `<name>\t<url> (fetch)` or `(push)` (a partial clone's fetch line ends with its filter, such as ` [blob:none]`), or `No remotes configured`
108108
- A credential embedded in a URL is never returned: the whole userinfo of a URL such as `https://user:token@host/...` or `https://token@host/...` is shown as `<redacted>`. An SSH username (`ssh://git@host/...`) is kept, since it names an account rather than authenticating one; a password after it is redacted. A remote-helper address (`https::https://user:token@host/...`) has its inner URL redacted the same way. scp-style addresses (`git@host:path`) and local paths are shown as configured. A line that cannot be parsed is shown as `<redacted>`.
109109

110110
### Protocol versions

‎src/git/src/mcp_server_git/server.py‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -531,11 +531,13 @@ def git_branch(
531531
# after the `::` is a URL of its own, and is redacted as one.
532532
_REMOTE_HELPER = re.compile(r"^(?P<transport>[A-Za-z][A-Za-z0-9+.-]*)::")
533533

534-
# One line of `git remote -v`: `<name>\t<url> (fetch|push)`. `.` matches
535-
# everything but '\n', so a URL holding another line separator (U+2028, say)
536-
# stays whole.
534+
# One line of `git remote -v`: `<name>\t<url> (fetch|push)`, and on a
535+
# partial clone's fetch line the promisor filter after it (` [blob:none]`).
536+
# `.` matches everything but '\n', so a URL holding another line separator
537+
# (U+2028, say) stays whole.
537538
_REMOTE_LINE = re.compile(
538-
r"^(?P<name>[^\t]*)\t(?P<url>.*) \((?P<direction>fetch|push)\)$"
539+
r"^(?P<name>[^\t]*)\t(?P<url>.*) \((?P<direction>fetch|push)\)"
540+
r"(?P<filter> \[.*\])?$"
539541
)
540542

541543
# Schemes whose username is an account name rather than a secret, so it is kept
@@ -576,7 +578,8 @@ def redact_url(url: str) -> str:
576578
def git_remote(repo: git.Repo) -> str:
577579
"""The repository's remotes with their fetch and push URLs, as `git remote -v`.
578580
579-
Each line is `<name>\t<url> (fetch|push)`; the URL goes through
581+
Each line is `<name>\t<url> (fetch|push)`, a partial clone's fetch line
582+
followed by its promisor filter (` [blob:none]`); the URL goes through
580583
`redact_url` so no credential reaches the client. Lines are split on
581584
'\n' alone, the only separator git prints, not on every separator
582585
`str.splitlines` knows, which would cut a URL holding U+2028 in two.
@@ -593,7 +596,9 @@ def git_remote(repo: git.Repo) -> str:
593596
lines.append(REDACTED)
594597
continue
595598
url = redact_url(match["url"])
596-
lines.append(f"{match['name']}\t{url} ({match['direction']})")
599+
lines.append(
600+
f"{match['name']}\t{url} ({match['direction']}){match['filter'] or ''}"
601+
)
597602
return "\n".join(lines)
598603

599604

‎src/git/tests/test_remote.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,19 @@ async def test_line_separator_in_password_is_not_split(repo: git.Repo):
157157
assert "token" not in result["content"][0]["text"]
158158

159159

160+
async def test_partial_clone_filter_is_kept(repo: git.Repo):
161+
# A promisor remote's fetch line ends in its filter (Copilot review on
162+
# #5373); the line still parses, and only the URL is redacted.
163+
repo.create_remote("origin", "https://alice:[email protected]/r.git")
164+
with repo.config_writer() as config:
165+
config.set_value('remote "origin"', "promisor", "true")
166+
config.set_value('remote "origin"', "partialclonefilter", "blob:none")
167+
assert await call_remote(None, repo) == text_result(
168+
"origin\thttps://<redacted>@example.com/r.git (fetch) [blob:none]\n"
169+
"origin\thttps://<redacted>@example.com/r.git (push)"
170+
)
171+
172+
160173
async def test_remote_helper_url_is_redacted(repo: git.Repo):
161174
repo.git.remote("add", "origin", "https::https://alice:[email protected]/r.git")
162175
assert await call_remote(None, repo) == text_result(

0 commit comments

Comments
 (0)