mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-12 07:14:38 +00:00
git: on rename_remote(), check conflicts of new remote name
This commit is contained in:
parent
46dd6dd9c6
commit
61172b1c1e
2 changed files with 23 additions and 1 deletions
|
@ -61,12 +61,23 @@ fn test_git_remote_rename() {
|
|||
&repo_path,
|
||||
&["git", "remote", "add", "foo", "http://example.com/repo/foo"],
|
||||
);
|
||||
test_env.jj_cmd_success(
|
||||
&repo_path,
|
||||
&["git", "remote", "add", "baz", "http://example.com/repo/baz"],
|
||||
);
|
||||
let stderr = test_env.jj_cmd_failure(&repo_path, &["git", "remote", "rename", "bar", "foo"]);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Error: No git remote named 'bar'
|
||||
"###);
|
||||
let stderr = test_env.jj_cmd_failure(&repo_path, &["git", "remote", "rename", "foo", "baz"]);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Error: Git remote named 'baz' already exists
|
||||
"###);
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "remote", "rename", "foo", "bar"]);
|
||||
insta::assert_snapshot!(stdout, @"");
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "remote", "list"]);
|
||||
insta::assert_snapshot!(stdout, @"bar http://example.com/repo/foo");
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
bar http://example.com/repo/foo
|
||||
baz http://example.com/repo/baz
|
||||
"###);
|
||||
}
|
||||
|
|
|
@ -552,6 +552,8 @@ pub fn export_some_refs(
|
|||
pub enum GitRemoteManagementError {
|
||||
#[error("No git remote named '{0}'")]
|
||||
NoSuchRemote(String),
|
||||
#[error("Git remote named '{0}' already exists")]
|
||||
RemoteAlreadyExists(String),
|
||||
#[error(transparent)]
|
||||
InternalGitError(git2::Error),
|
||||
}
|
||||
|
@ -566,6 +568,13 @@ fn is_remote_not_found_err(err: &git2::Error) -> bool {
|
|||
)
|
||||
}
|
||||
|
||||
fn is_remote_exists_err(err: &git2::Error) -> bool {
|
||||
matches!(
|
||||
(err.class(), err.code()),
|
||||
(git2::ErrorClass::Config, git2::ErrorCode::Exists)
|
||||
)
|
||||
}
|
||||
|
||||
pub fn remove_remote(
|
||||
mut_repo: &mut MutableRepo,
|
||||
git_repo: &git2::Repository,
|
||||
|
@ -612,6 +621,8 @@ pub fn rename_remote(
|
|||
.map_err(|err| {
|
||||
if is_remote_not_found_err(&err) {
|
||||
GitRemoteManagementError::NoSuchRemote(old_remote_name.to_owned())
|
||||
} else if is_remote_exists_err(&err) {
|
||||
GitRemoteManagementError::RemoteAlreadyExists(new_remote_name.to_owned())
|
||||
} else {
|
||||
GitRemoteManagementError::InternalGitError(err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue