/**
 * Removes userinfo from https/git remote URLs so tokens are not written to logs.
 * SSH remotes (`git@host:path`) are returned unchanged.
 */
export function redactGitRemoteUrl(remote: string): string {
  if (!remote || remote === "unknown") return remote;
  try {
    const u = new URL(remote);
    if (u.protocol === "https:" || u.protocol === "http:") {
      u.username = "";
      u.password = "";
      return u.href.replace(/\/$/, "");
    }
  } catch {
    // e.g. git@github.com:org/repo.git
  }
  return remote;
}
