forked from mirrors/jj
git: consistently ignore unrelated refs on fetch()
Since "jj git fetch --branch '*'" doesn't import unrelated remote and local refs, "jj git fetch" shouldn't do either.
This commit is contained in:
parent
564506a7c7
commit
a934547720
2 changed files with 16 additions and 8 deletions
|
@ -41,6 +41,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
* `jj` will no longer parse `br` as a git_ref `refs/heads/br` when a branch `br`
|
||||
does not exist but the git_ref does (this is rare). Use `br@git` instead.
|
||||
|
||||
* `jj git fetch` will no longer import unrelated branches from the underlying
|
||||
Git repo.
|
||||
|
||||
### New features
|
||||
|
||||
* `jj git push --deleted` will remove all locally deleted branches from the remote.
|
||||
|
|
|
@ -64,6 +64,13 @@ fn to_git_ref_name(parsed_ref: &RefName) -> String {
|
|||
}
|
||||
}
|
||||
|
||||
fn to_remote_branch<'a>(parsed_ref: &'a RefName, remote_name: &str) -> Option<&'a str> {
|
||||
match parsed_ref {
|
||||
RefName::RemoteBranch { branch, remote } => (remote == remote_name).then_some(branch),
|
||||
RefName::LocalBranch(..) | RefName::Tag(..) | RefName::GitRef(..) => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if `git_ref` points to a Git commit object, and returns its id.
|
||||
///
|
||||
/// If the ref points to the previously `known_target` (i.e. unchanged), this
|
||||
|
@ -570,15 +577,13 @@ pub fn fetch(
|
|||
None
|
||||
};
|
||||
let git_ref_filter = |ref_name: &RefName| -> bool {
|
||||
if let Some(branch_regex) = &branch_regex {
|
||||
match ref_name {
|
||||
RefName::RemoteBranch { branch, remote } => {
|
||||
remote == remote_name && branch_regex.is_match(branch)
|
||||
}
|
||||
RefName::LocalBranch(..) | RefName::Tag(..) | RefName::GitRef(..) => false,
|
||||
}
|
||||
if let Some(branch) = to_remote_branch(ref_name, remote_name) {
|
||||
branch_regex
|
||||
.as_ref()
|
||||
.map(|r| r.is_match(branch))
|
||||
.unwrap_or(true)
|
||||
} else {
|
||||
true
|
||||
false
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue