mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-20 03:20:08 +00:00
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`
|
* `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.
|
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
|
### New features
|
||||||
|
|
||||||
* `jj git push --deleted` will remove all locally deleted branches from the remote.
|
* `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.
|
/// 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
|
/// If the ref points to the previously `known_target` (i.e. unchanged), this
|
||||||
|
@ -570,15 +577,13 @@ pub fn fetch(
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let git_ref_filter = |ref_name: &RefName| -> bool {
|
let git_ref_filter = |ref_name: &RefName| -> bool {
|
||||||
if let Some(branch_regex) = &branch_regex {
|
if let Some(branch) = to_remote_branch(ref_name, remote_name) {
|
||||||
match ref_name {
|
branch_regex
|
||||||
RefName::RemoteBranch { branch, remote } => {
|
.as_ref()
|
||||||
remote == remote_name && branch_regex.is_match(branch)
|
.map(|r| r.is_match(branch))
|
||||||
}
|
.unwrap_or(true)
|
||||||
RefName::LocalBranch(..) | RefName::Tag(..) | RefName::GitRef(..) => false,
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
true
|
false
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue