Skip to content

Commit

Permalink
cli: git: escape bookmark and remote names in trunk() config
Browse files Browse the repository at this point in the history
Closes #5359.
  • Loading branch information
martinvonz committed Jan 30, 2025
1 parent 2854131 commit bc8d8d9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions cli/src/commands/git/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()?;
Expand Down
30 changes: 30 additions & 0 deletions cli/tests/test_git_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit bc8d8d9

Please sign in to comment.