diff --git a/cli/src/git_util.rs b/cli/src/git_util.rs index 74ebe2d2fa..1edb7a6216 100644 --- a/cli/src/git_util.rs +++ b/cli/src/git_util.rs @@ -484,7 +484,7 @@ pub fn git_fetch( .any(|pattern| pattern.as_exact().is_some_and(|s| s.contains('*'))) { user_error_with_hint( - err, + "Branch names may not include `*`.", "Prefix the pattern with `glob:` to expand `*` as a glob", ) } else { diff --git a/cli/tests/test_git_fetch.rs b/cli/tests/test_git_fetch.rs index e6c2f96acc..232ddae660 100644 --- a/cli/tests/test_git_fetch.rs +++ b/cli/tests/test_git_fetch.rs @@ -612,14 +612,12 @@ fn test_git_fetch_some_of_many_bookmarks() { &target_jj_repo_path, &["git", "fetch", "--branch", "glob:^:a*"], ); - insta::assert_snapshot!(stderr, @r###" - Error: Invalid branch pattern provided. Patterns may not contain the characters `:`, `^`, `?`, `[`, `]` - "###); + insta::assert_snapshot!(stderr, @"Error: Invalid branch pattern provided. When fetching, branch names and globs may not contain the characters `:`, `^`, `?`, `[`, `]`"); let stderr = test_env.jj_cmd_failure(&target_jj_repo_path, &["git", "fetch", "--branch", "a*"]); - insta::assert_snapshot!(stderr, @r###" - Error: Invalid branch pattern provided. Patterns may not contain the characters `:`, `^`, `?`, `[`, `]` + insta::assert_snapshot!(stderr, @r" + Error: Branch names may not include `*`. Hint: Prefix the pattern with `glob:` to expand `*` as a glob - "###); + "); // Nothing in our repo before the fetch insta::assert_snapshot!(get_log_output(&test_env, &target_jj_repo_path), @r###" diff --git a/lib/src/git.rs b/lib/src/git.rs index 3bc7ef2970..6bff6faac8 100644 --- a/lib/src/git.rs +++ b/lib/src/git.rs @@ -1218,7 +1218,7 @@ pub enum GitFetchError { #[error("No git remote named '{0}'")] NoSuchRemote(String), #[error( - "Invalid branch pattern provided. Patterns may not contain the characters `{chars}`", + "Invalid branch pattern provided. When fetching, branch names and globs may not contain the characters `{chars}`", chars = INVALID_REFSPEC_CHARS.iter().join("`, `") )] InvalidBranchPattern, @@ -1273,7 +1273,11 @@ pub fn fetch( .map(|pattern| { pattern .to_glob() - .filter(|glob| !glob.contains(INVALID_REFSPEC_CHARS)) + .filter( + /* This triggered by non-glob `*`s in addition to INVALID_REFSPEC_CHARS + * because `to_glob()` escapes such `*`s as `[*]`. */ + |glob| !glob.contains(INVALID_REFSPEC_CHARS), + ) .map(|glob| format!("+refs/heads/{glob}:refs/remotes/{remote_name}/{glob}")) }) .collect::>()