Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: make jj branch track show conflicts #3690

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

* `jj branch track` now show conflicts if there are some.

### Fixed bugs

* When the working copy commit becomes immutable, a new one is automatically created on top of it
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ indexmap = "2.2.5"
indoc = "2.0.4"
insta = { version = "1.39.0", features = ["filters"] }
itertools = "0.12.1"
libc = { version = "0.2.154" }
libc = { version = "0.2.153" }
maplit = "1.0.2"
minus = { version = "5.6.1", features = ["dynamic_output", "search"] }
num_cpus = "1.16.0"
Expand Down
51 changes: 50 additions & 1 deletion cli/src/commands/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::HashSet;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::io::Write as _;

Expand Down Expand Up @@ -569,6 +569,55 @@ fn cmd_branch_track(
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(())
}

Expand Down
29 changes: 29 additions & 0 deletions cli/tests/test_branch_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,35 @@ fn test_branch_track_untrack() {
"###);
}

#[test]
tdaron marked this conversation as resolved.
Show resolved Hide resolved
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
"###);
}
tdaron marked this conversation as resolved.
Show resolved Hide resolved

#[test]
fn test_branch_track_untrack_patterns() {
let test_env = TestEnvironment::default();
Expand Down