mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-07 21:27:06 +00:00
parent
0e26ef7733
commit
35a596ff66
3 changed files with 47 additions and 0 deletions
|
@ -53,6 +53,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
* `jj git push` will now push all branches in the range `remote_branches()..@`
|
* `jj git push` will now push all branches in the range `remote_branches()..@`
|
||||||
instead of only branches pointing to `@` or `@-`.
|
instead of only branches pointing to `@` or `@-`.
|
||||||
|
|
||||||
|
* It's no longer allowed to create a Git remote named "git". Use `jj git remote
|
||||||
|
rename` to rename the existing remote.
|
||||||
|
[#1690](https://github.com/martinvonz/jj/issues/1690)
|
||||||
|
|
||||||
### New features
|
### New features
|
||||||
|
|
||||||
* Default template for `jj log` now does not show irrelevant information
|
* Default template for `jj log` now does not show irrelevant information
|
||||||
|
|
|
@ -74,6 +74,13 @@ fn test_git_remote_add() {
|
||||||
insta::assert_snapshot!(stderr, @r###"
|
insta::assert_snapshot!(stderr, @r###"
|
||||||
Error: Git remote named 'foo' already exists
|
Error: Git remote named 'foo' already exists
|
||||||
"###);
|
"###);
|
||||||
|
let stderr = test_env.jj_cmd_failure(
|
||||||
|
&repo_path,
|
||||||
|
&["git", "remote", "add", "git", "http://example.com/repo/git"],
|
||||||
|
);
|
||||||
|
insta::assert_snapshot!(stderr, @r###"
|
||||||
|
Error: Git remote named 'git' is reserved for local Git repository
|
||||||
|
"###);
|
||||||
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "remote", "list"]);
|
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "remote", "list"]);
|
||||||
insta::assert_snapshot!(stdout, @r###"
|
insta::assert_snapshot!(stdout, @r###"
|
||||||
foo http://example.com/repo/foo
|
foo http://example.com/repo/foo
|
||||||
|
@ -102,6 +109,10 @@ fn test_git_remote_rename() {
|
||||||
insta::assert_snapshot!(stderr, @r###"
|
insta::assert_snapshot!(stderr, @r###"
|
||||||
Error: Git remote named 'baz' already exists
|
Error: Git remote named 'baz' already exists
|
||||||
"###);
|
"###);
|
||||||
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["git", "remote", "rename", "foo", "git"]);
|
||||||
|
insta::assert_snapshot!(stderr, @r###"
|
||||||
|
Error: Git remote named 'git' is reserved for local Git repository
|
||||||
|
"###);
|
||||||
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "remote", "rename", "foo", "bar"]);
|
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "remote", "rename", "foo", "bar"]);
|
||||||
insta::assert_snapshot!(stdout, @"");
|
insta::assert_snapshot!(stdout, @"");
|
||||||
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "remote", "list"]);
|
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "remote", "list"]);
|
||||||
|
@ -110,3 +121,24 @@ fn test_git_remote_rename() {
|
||||||
baz http://example.com/repo/baz
|
baz http://example.com/repo/baz
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_git_remote_named_git() {
|
||||||
|
let test_env = TestEnvironment::default();
|
||||||
|
|
||||||
|
// Existing remote named 'git' shouldn't block the repo initialization.
|
||||||
|
let repo_path = test_env.env_root().join("repo");
|
||||||
|
let git_repo = git2::Repository::init(&repo_path).unwrap();
|
||||||
|
git_repo
|
||||||
|
.remote("git", "http://example.com/repo/repo")
|
||||||
|
.unwrap();
|
||||||
|
test_env.jj_cmd_success(&repo_path, &["init", "--git-repo=."]);
|
||||||
|
|
||||||
|
// The remote can be renamed.
|
||||||
|
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "remote", "rename", "git", "bar"]);
|
||||||
|
insta::assert_snapshot!(stdout, @"");
|
||||||
|
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "remote", "list"]);
|
||||||
|
insta::assert_snapshot!(stdout, @r###"
|
||||||
|
bar http://example.com/repo/repo
|
||||||
|
"###);
|
||||||
|
}
|
||||||
|
|
|
@ -561,6 +561,11 @@ pub enum GitRemoteManagementError {
|
||||||
NoSuchRemote(String),
|
NoSuchRemote(String),
|
||||||
#[error("Git remote named '{0}' already exists")]
|
#[error("Git remote named '{0}' already exists")]
|
||||||
RemoteAlreadyExists(String),
|
RemoteAlreadyExists(String),
|
||||||
|
#[error(
|
||||||
|
"Git remote named '{name}' is reserved for local Git repository",
|
||||||
|
name = REMOTE_NAME_FOR_LOCAL_GIT_REPO
|
||||||
|
)]
|
||||||
|
RemoteReservedForLocalGitRepo,
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
InternalGitError(git2::Error),
|
InternalGitError(git2::Error),
|
||||||
}
|
}
|
||||||
|
@ -587,6 +592,9 @@ pub fn add_remote(
|
||||||
remote_name: &str,
|
remote_name: &str,
|
||||||
url: &str,
|
url: &str,
|
||||||
) -> Result<(), GitRemoteManagementError> {
|
) -> Result<(), GitRemoteManagementError> {
|
||||||
|
if remote_name == REMOTE_NAME_FOR_LOCAL_GIT_REPO {
|
||||||
|
return Err(GitRemoteManagementError::RemoteReservedForLocalGitRepo);
|
||||||
|
}
|
||||||
git_repo.remote(remote_name, url).map_err(|err| {
|
git_repo.remote(remote_name, url).map_err(|err| {
|
||||||
if is_remote_exists_err(&err) {
|
if is_remote_exists_err(&err) {
|
||||||
GitRemoteManagementError::RemoteAlreadyExists(remote_name.to_owned())
|
GitRemoteManagementError::RemoteAlreadyExists(remote_name.to_owned())
|
||||||
|
@ -638,6 +646,9 @@ pub fn rename_remote(
|
||||||
old_remote_name: &str,
|
old_remote_name: &str,
|
||||||
new_remote_name: &str,
|
new_remote_name: &str,
|
||||||
) -> Result<(), GitRemoteManagementError> {
|
) -> Result<(), GitRemoteManagementError> {
|
||||||
|
if new_remote_name == REMOTE_NAME_FOR_LOCAL_GIT_REPO {
|
||||||
|
return Err(GitRemoteManagementError::RemoteReservedForLocalGitRepo);
|
||||||
|
}
|
||||||
git_repo
|
git_repo
|
||||||
.remote_rename(old_remote_name, new_remote_name)
|
.remote_rename(old_remote_name, new_remote_name)
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
|
|
Loading…
Reference in a new issue