mirror of
https://github.com/martinvonz/jj.git
synced 2025-05-30 11:31:13 +00:00
cli: make jj branch track show conflicts
This commit is contained in:
parent
69d44375dc
commit
0a48ac63cb
@ -29,6 +29,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
* `ui.color = "debug"` prints active labels alongside the regular colored output.
|
* `ui.color = "debug"` prints active labels alongside the regular colored output.
|
||||||
|
|
||||||
|
* `jj branch track` now show conflicts if there are some.
|
||||||
|
|
||||||
### Fixed bugs
|
### Fixed bugs
|
||||||
|
|
||||||
* When the working copy commit becomes immutable, a new one is automatically created on top of it
|
* When the working copy commit becomes immutable, a new one is automatically created on top of it
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io::Write as _;
|
use std::io::Write as _;
|
||||||
|
|
||||||
@ -569,6 +569,55 @@ fn cmd_branch_track(
|
|||||||
names.len()
|
names.len()
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//show conflicted branches if there are some
|
||||||
|
|
||||||
|
if let Some(mut formatter) = ui.status_formatter() {
|
||||||
|
let template = {
|
||||||
|
let language = workspace_command.commit_template_language()?;
|
||||||
|
let text = command
|
||||||
|
.settings()
|
||||||
|
.config()
|
||||||
|
.get::<String>("templates.branch_list")?;
|
||||||
|
workspace_command
|
||||||
|
.parse_template(&language, &text, CommitTemplateLanguage::wrap_ref_name)?
|
||||||
|
.labeled("branch_list")
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut remote_per_branch: HashMap<&str, Vec<&str>> = HashMap::new();
|
||||||
|
for n in names.iter() {
|
||||||
|
remote_per_branch
|
||||||
|
.entry(&n.branch)
|
||||||
|
.or_default()
|
||||||
|
.push(&n.remote);
|
||||||
|
}
|
||||||
|
let branches_to_list =
|
||||||
|
workspace_command
|
||||||
|
.repo()
|
||||||
|
.view()
|
||||||
|
.branches()
|
||||||
|
.filter(|(name, target)| {
|
||||||
|
remote_per_branch.contains_key(name) && target.local_target.has_conflict()
|
||||||
|
});
|
||||||
|
|
||||||
|
for (name, branch_target) in branches_to_list {
|
||||||
|
let local_target = branch_target.local_target;
|
||||||
|
let ref_name = RefName::local(
|
||||||
|
name,
|
||||||
|
local_target.clone(),
|
||||||
|
branch_target.remote_refs.iter().map(|x| x.1),
|
||||||
|
);
|
||||||
|
template.format(&ref_name, formatter.as_mut())?;
|
||||||
|
|
||||||
|
for (remote_name, remote_ref) in branch_target.remote_refs {
|
||||||
|
if remote_per_branch[name].contains(&remote_name) {
|
||||||
|
let ref_name =
|
||||||
|
RefName::remote(name, remote_name, remote_ref.clone(), local_target);
|
||||||
|
template.format(&ref_name, formatter.as_mut())?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -827,6 +827,35 @@ fn test_branch_track_untrack() {
|
|||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_branch_track_conflict() {
|
||||||
|
let test_env = TestEnvironment::default();
|
||||||
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
||||||
|
let repo_path = test_env.env_root().join("repo");
|
||||||
|
|
||||||
|
let git_repo_path = test_env.env_root().join("git-repo");
|
||||||
|
git2::Repository::init_bare(git_repo_path).unwrap();
|
||||||
|
test_env.jj_cmd_ok(
|
||||||
|
&repo_path,
|
||||||
|
&["git", "remote", "add", "origin", "../git-repo"],
|
||||||
|
);
|
||||||
|
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "main"]);
|
||||||
|
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "a"]);
|
||||||
|
test_env.jj_cmd_ok(&repo_path, &["git", "push", "-b", "main"]);
|
||||||
|
test_env.jj_cmd_ok(&repo_path, &["branch", "untrack", "main@origin"]);
|
||||||
|
test_env.jj_cmd_ok(
|
||||||
|
&repo_path,
|
||||||
|
&["describe", "-m", "b", "-r", "main", "--ignore-immutable"],
|
||||||
|
);
|
||||||
|
let (_, stderr) = test_env.jj_cmd_ok(&repo_path, &["branch", "track", "main@origin"]);
|
||||||
|
insta::assert_snapshot!(stderr, @r###"
|
||||||
|
main (conflicted):
|
||||||
|
+ qpvuntsm b4a6b8c5 (empty) b
|
||||||
|
+ qpvuntsm hidden 4bfd80cd (empty) a
|
||||||
|
@origin (behind by 1 commits): qpvuntsm hidden 4bfd80cd (empty) a
|
||||||
|
"###);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_branch_track_untrack_patterns() {
|
fn test_branch_track_untrack_patterns() {
|
||||||
let test_env = TestEnvironment::default();
|
let test_env = TestEnvironment::default();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user