Skip to content

Commit

Permalink
cli git remote add/set-url: use sanitize_git_url_if_path
Browse files Browse the repository at this point in the history
It seems like an oversight that the algorithm from `jj git clone`
wasn't used in them before
  • Loading branch information
ilyagr committed Jul 31, 2024
1 parent 1d6dc32 commit bed1ca1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
8 changes: 6 additions & 2 deletions cli/src/commands/git/remote/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use jj_lib::git;
use jj_lib::git::{self, sanitize_git_url_if_path};
use jj_lib::repo::Repo;

use crate::cli_util::CommandHelper;
Expand All @@ -37,6 +37,10 @@ pub fn cmd_git_remote_add(
let workspace_command = command.workspace_helper(ui)?;
let repo = workspace_command.repo();
let git_repo = get_git_repo(repo.store())?;
git::add_remote(&git_repo, &args.remote, &args.url)?;
git::add_remote(
&git_repo,
&args.remote,
&sanitize_git_url_if_path(command.cwd(), &args.url),
)?;
Ok(())
}
2 changes: 1 addition & 1 deletion cli/src/commands/git/remote/set_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ pub fn cmd_git_remote_set_url(
let workspace_command = command.workspace_helper(ui)?;
let repo = workspace_command.repo();
let git_repo = get_git_repo(repo.store())?;
git::set_remote_url(&git_repo, &args.remote, &args.url)?;
git::set_remote_url(&git_repo, &args.remote, &args.url, command.cwd())?;
Ok(())
}
3 changes: 2 additions & 1 deletion lib/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,7 @@ pub fn set_remote_url(
git_repo: &git2::Repository,
remote_name: &str,
new_remote_url: &str,
cwd: &Path,
) -> Result<(), GitRemoteManagementError> {
if remote_name == REMOTE_NAME_FOR_LOCAL_GIT_REPO {
return Err(GitRemoteManagementError::RemoteReservedForLocalGitRepo);
Expand All @@ -1197,7 +1198,7 @@ pub fn set_remote_url(
})?;

git_repo
.remote_set_url(remote_name, new_remote_url)
.remote_set_url(remote_name, &sanitize_git_url_if_path(cwd, new_remote_url))
.map_err(GitRemoteManagementError::InternalGitError)?;
Ok(())
}
Expand Down

0 comments on commit bed1ca1

Please sign in to comment.