diff --git a/CHANGELOG.md b/CHANGELOG.md index 857eeaf7115..79d1034f3a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -163,6 +163,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). now materialized in a way that can be parsed correctly. [#3968](https://github.com/jj-vcs/jj/issues/3968) +* Bookmark and remote names written by `jj git clone` to + `revset-aliases.'trunk()'` are now escaped if necessary. + [#5359](https://github.com/jj-vcs/jj/issues/5359) + ## [0.25.0] - 2025-01-01 ### Release highlights diff --git a/cli/src/commands/git/mod.rs b/cli/src/commands/git/mod.rs index 215844abdeb..d7b95dcf9b6 100644 --- a/cli/src/commands/git/mod.rs +++ b/cli/src/commands/git/mod.rs @@ -26,6 +26,7 @@ use std::path::Path; use clap::Subcommand; use jj_lib::config::ConfigFile; use jj_lib::config::ConfigSource; +use jj_lib::revset; use self::clone::cmd_git_clone; use self::clone::GitCloneArgs; @@ -120,6 +121,8 @@ fn write_repository_level_trunk_alias( branch: &str, ) -> Result<(), CommandError> { let mut file = ConfigFile::load_or_empty(ConfigSource::Repo, repo_path.join("config.toml"))?; + let branch = revset::format_symbol(branch); + let remote = revset::format_symbol(remote); file.set_value(["revset-aliases", "trunk()"], format!("{branch}@{remote}")) .expect("initial repo config shouldn't have invalid values"); file.save()?; diff --git a/cli/tests/test_git_clone.rs b/cli/tests/test_git_clone.rs index 030a4cf39b3..d9384914f37 100644 --- a/cli/tests/test_git_clone.rs +++ b/cli/tests/test_git_clone.rs @@ -599,6 +599,36 @@ fn test_git_clone_remote_default_bookmark(subprocess: bool) { revset-aliases.'trunk()' = "feature1@origin" "###); } + + // A branch with a strange name gets escaped in the config. Windows doesn't like + // the strange name. + if cfg!(unix) { + git_repo.reference("refs/heads/\"", oid, false, "").unwrap(); + git_repo.set_head("refs/heads/\"").unwrap(); + let (_stdout, stderr) = + test_env.jj_cmd_ok(test_env.env_root(), &["git", "clone", "source", "clone4"]); + insta::allow_duplicates! { + insta::assert_snapshot!(stderr, @r#" + Fetching into new repo in "$TEST_ENV/clone4" + bookmark: "@origin [new] untracked + bookmark: feature1@origin [new] untracked + bookmark: main@origin [new] untracked + Setting the revset alias "trunk()" to ""\""@origin" + Working copy now at: wmwvqwsz abb7c50b (empty) (no description set) + Parent commit : mzyxwzks 9f01a0e0 " feature1@origin main@origin | message + Added 1 files, modified 0 files, removed 0 files + "#); + } + + // "trunk()" alias should be set to new default bookmark "\"" + let stdout = test_env.jj_cmd_success( + &test_env.env_root().join("clone4"), + &["config", "list", "--repo", "revset-aliases.'trunk()'"], + ); + insta::allow_duplicates! { + insta::assert_snapshot!(stdout, @r#"revset-aliases.'trunk()' = '"\""@origin'"#); + } + } } #[test_case(false; "use git2 for remote calls")]