mirror of
https://github.com/martinvonz/jj.git
synced 2025-05-28 10:31:14 +00:00
git: reject reserved remote name early in fetch() function
I'm going to make git::import_refs() not fail because of a real remote named "git", but fetching from such remote should be an error.
This commit is contained in:
parent
b2fd1a002e
commit
dfb10cab9b
@ -540,7 +540,7 @@ jj currently does not support partial clones. To use jj with this repository, tr
|
||||
}
|
||||
match err {
|
||||
GitFetchError::NoSuchRemote(_) => user_error(err),
|
||||
GitFetchError::RemoteWithSlash(_) => user_error_with_hint(
|
||||
GitFetchError::RemoteName(_) => user_error_with_hint(
|
||||
err,
|
||||
"Run `jj git remote rename` to give a different name.",
|
||||
),
|
||||
|
@ -531,14 +531,16 @@ fn test_git_fetch_from_remote_named_git(subprocess: bool) {
|
||||
insta::allow_duplicates! {
|
||||
insta::assert_snapshot!(output, @r"
|
||||
------- stderr -------
|
||||
Error: Failed to import refs from underlying Git repo
|
||||
Caused by: Git remote named 'git' is reserved for local Git repository
|
||||
Hint: Run `jj git remote rename` to give different name.
|
||||
Error: Git remote named 'git' is reserved for local Git repository
|
||||
Hint: Run `jj git remote rename` to give a different name.
|
||||
[EOF]
|
||||
[exit status: 1]
|
||||
");
|
||||
}
|
||||
|
||||
// Fetch remote refs by using the git CLI.
|
||||
git::fetch(&repo_path, "git");
|
||||
|
||||
// Implicit import shouldn't fail because of the remote ref.
|
||||
let output = test_env.run_jj_in(&repo_path, ["bookmark", "list", "--all-remotes"]);
|
||||
insta::allow_duplicates! {
|
||||
|
@ -1499,8 +1499,8 @@ pub enum GitFetchError {
|
||||
chars = INVALID_REFSPEC_CHARS.iter().join("`, `")
|
||||
)]
|
||||
InvalidBranchPattern(StringPattern),
|
||||
#[error("Git remotes with slashes are incompatible with jj: {0}")]
|
||||
RemoteWithSlash(String),
|
||||
#[error(transparent)]
|
||||
RemoteName(#[from] GitRemoteNameError),
|
||||
// TODO: I'm sure there are other errors possible, such as transport-level errors.
|
||||
#[error("Unexpected git error when fetching")]
|
||||
InternalGitError(#[from] git2::Error),
|
||||
@ -1581,9 +1581,7 @@ impl<'a> GitFetch<'a> {
|
||||
callbacks: RemoteCallbacks<'_>,
|
||||
depth: Option<NonZeroU32>,
|
||||
) -> Result<(), GitFetchError> {
|
||||
if remote_name.contains("/") {
|
||||
return Err(GitFetchError::RemoteWithSlash(remote_name.to_owned()));
|
||||
}
|
||||
validate_remote_name(remote_name)?;
|
||||
self.fetch_impl
|
||||
.fetch(remote_name, branch_names, callbacks, depth)?;
|
||||
self.fetched.push(FetchedBranches {
|
||||
|
Loading…
x
Reference in New Issue
Block a user