Skip to content

Commit

Permalink
cli: print a message about new and resolved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvonz committed Nov 20, 2023
1 parent 22ad4d7 commit 1deeb5d
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 5 deletions.
76 changes: 71 additions & 5 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::{iter, str};

use clap::builder::{NonEmptyStringValueParser, TypedValueParser, ValueParserFactory};
use clap::{Arg, ArgAction, ArgMatches, Command, FromArgMatches};
use indexmap::IndexSet;
use indexmap::{IndexMap, IndexSet};
use itertools::Itertools;
use jj_lib::backend::{BackendError, ChangeId, CommitId, MergedTreeId, ObjectId};
use jj_lib::commit::Commit;
Expand All @@ -52,8 +52,8 @@ use jj_lib::repo::{
use jj_lib::repo_path::{FsPathParseError, RepoPath};
use jj_lib::revset::{
DefaultSymbolResolver, Revset, RevsetAliasesMap, RevsetCommitRef, RevsetEvaluationError,
RevsetExpression, RevsetIteratorExt, RevsetParseContext, RevsetParseError,
RevsetParseErrorKind, RevsetResolutionError, RevsetWorkspaceContext,
RevsetExpression, RevsetFilterPredicate, RevsetIteratorExt, RevsetParseContext,
RevsetParseError, RevsetParseErrorKind, RevsetResolutionError, RevsetWorkspaceContext,
};
use jj_lib::rewrite::restore_tree;
use jj_lib::settings::{ConfigResultExt as _, UserSettings};
Expand Down Expand Up @@ -1440,8 +1440,9 @@ See https://github.com/martinvonz/jj/blob/main/docs/working-copy.md#stale-workin
writeln!(ui.stderr(), "Rebased {num_rebased} descendant commits")?;
}

let maybe_old_wc_commit = tx
.base_repo()
let old_repo = tx.base_repo().clone();

let maybe_old_wc_commit = old_repo
.view()
.get_wc_commit_id(self.workspace_id())
.map(|commit_id| tx.base_repo().store().get_commit(commit_id))
Expand All @@ -1461,6 +1462,7 @@ See https://github.com/martinvonz/jj/blob/main/docs/working-copy.md#stale-workin
print_failed_git_export(ui, &failed_branches)?;
}
self.user_repo = ReadonlyUserRepo::new(tx.commit());
self.report_repo_changes(ui, &old_repo)?;
if self.may_update_working_copy {
if let Some(new_commit) = &maybe_new_wc_commit {
self.update_working_copy(ui, maybe_old_wc_commit.as_ref(), new_commit)?;
Expand All @@ -1480,6 +1482,70 @@ See https://github.com/martinvonz/jj/blob/main/docs/working-copy.md#stale-workin
}
Ok(())
}

fn report_repo_changes(
&self,
ui: &mut Ui,
old_repo: &Arc<ReadonlyRepo>,
) -> Result<(), CommandError> {
let old_view = old_repo.view();
let repo = self.repo().as_ref();
let new_view = self.repo().view();
let added_heads = RevsetExpression::commits(
new_view
.heads()
.iter()
.filter(|id| !old_view.heads().contains(id))
.cloned()
.collect(),
);
let removed_heads = RevsetExpression::commits(
old_view
.heads()
.iter()
.filter(|id| !new_view.heads().contains(id))
.cloned()
.collect(),
);
let conflicts = RevsetExpression::filter(RevsetFilterPredicate::HasConflict);
let added_conflicts_expr = removed_heads.range(&added_heads).intersection(&conflicts);
let removed_conflicts_expr = added_heads.range(&removed_heads).intersection(&conflicts);
let added_conflicts_revset = added_conflicts_expr.resolve(repo)?.evaluate(repo)?;
let removed_conflicts_revset = removed_conflicts_expr.resolve(repo)?.evaluate(repo)?;
let added_conflicts_commits: Vec<Commit> = added_conflicts_revset
.iter()
.commits(repo.store())
.try_collect()?;
let removed_conflicts_commits: Vec<Commit> = removed_conflicts_revset
.iter()
.commits(repo.store())
.try_collect()?;
let mut added_conflict_by_change_id: IndexMap<&ChangeId, &Commit> = added_conflicts_commits
.iter()
.map(|commit| (commit.change_id(), commit))
.collect();
let removed_conflict_by_change_id: IndexMap<&ChangeId, &Commit> = removed_conflicts_commits
.iter()
.map(|commit| (commit.change_id(), commit))
.collect();
// TODO: Also report new divergence and maybe resolved divergence
let mut fmt = ui.stderr_formatter();
for (change_id, old_commit) in removed_conflict_by_change_id {
if added_conflict_by_change_id.remove(change_id).is_some() {
write!(fmt, "Resolved conflicts in: ")?;
self.write_commit_summary(fmt.as_mut(), old_commit)?;
writeln!(fmt, "")?;
}
}
// TODO: Hint about doing `jj new <first commit with conflicts>`.
for (_, new_commit) in added_conflict_by_change_id {
write!(fmt, "New conflicts in: ")?;
self.write_commit_summary(fmt.as_mut(), new_commit)?;
writeln!(fmt, "")?;
}

Ok(())
}
}

#[must_use]
Expand Down
1 change: 1 addition & 0 deletions cli/tests/test_chmod_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ fn test_chmod_file_dir_deletion_conflicts() {
test_env.jj_cmd_ok(&repo_path, &["chmod", "x", "file", "-r=file_deletion"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
Resolved conflicts in: kmkuslsw hidden b53cf28c (conflict) (empty) file_deletion
Working copy now at: kmkuslsw 4cc432b5 file_deletion | (conflict) file_deletion
Parent commit : zsuskuln c51c9c55 file | file
Parent commit : royxmykx 6b18b3c1 deletion | deletion
Expand Down
2 changes: 2 additions & 0 deletions cli/tests/test_diffedit_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ fn test_diffedit_merge() {
insta::assert_snapshot!(stderr, @r###"
Created royxmykx 2b5202ae (conflict) merge
Rebased 1 descendant commits
Resolved conflicts in: yqosqzyt hidden 859c77cb (conflict) (empty) (no description set)
Resolved conflicts in: royxmykx hidden 77b14a4a (conflict) merge
Working copy now at: yqosqzyt 23b1fe1b (conflict) (empty) (no description set)
Parent commit : royxmykx 2b5202ae (conflict) merge
Added 0 files, modified 0 files, removed 1 files
Expand Down
3 changes: 3 additions & 0 deletions cli/tests/test_resolve_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ conflict
);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
Resolved conflicts in: vruxwmqv hidden 0196125d (conflict) (empty) conflict
Working copy now at: vruxwmqv ff4e8c6b conflict | (conflict) conflict
Parent commit : zsuskuln aa493daf a | a
Parent commit : royxmykx db6a4daf b | b
Expand Down Expand Up @@ -635,6 +636,7 @@ fn test_multiple_conflicts() {
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["resolve", "another_file"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
Resolved conflicts in: vruxwmqv hidden 76f01728 (conflict) (empty) conflict
Working copy now at: vruxwmqv c3c25bce conflict | (conflict) conflict
Parent commit : zsuskuln de7553ef a | a
Parent commit : royxmykx f68bc2f0 b | b
Expand Down Expand Up @@ -664,6 +666,7 @@ fn test_multiple_conflicts() {
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["resolve", "--quiet", "another_file"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
Resolved conflicts in: vruxwmqv hidden 76f01728 (conflict) (empty) conflict
Working copy now at: vruxwmqv fd3874cd conflict | (conflict) conflict
Parent commit : zsuskuln de7553ef a | a
Parent commit : royxmykx f68bc2f0 b | b
Expand Down
3 changes: 3 additions & 0 deletions cli/tests/test_restore_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ fn test_restore() {
insta::assert_snapshot!(stderr, @r###"
Created rlvkpnrz e25100af (empty) (no description set)
Rebased 1 descendant commits
New conflicts in: kkmpptxz e301deb3 (conflict) (no description set)
Working copy now at: kkmpptxz e301deb3 (conflict) (no description set)
Parent commit : rlvkpnrz e25100af (empty) (no description set)
Added 0 files, modified 1 files, removed 0 files
Expand Down Expand Up @@ -193,6 +194,7 @@ fn test_restore_conflicted_merge() {
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
Created vruxwmqv b2c9c888 conflict | (conflict) (empty) conflict
New conflicts in: vruxwmqv b2c9c888 conflict | (conflict) (empty) conflict
Working copy now at: vruxwmqv b2c9c888 conflict | (conflict) (empty) conflict
Parent commit : zsuskuln aa493daf a | a
Parent commit : royxmykx db6a4daf b | b
Expand Down Expand Up @@ -232,6 +234,7 @@ fn test_restore_conflicted_merge() {
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
Created vruxwmqv 4fc10820 conflict | (conflict) (empty) conflict
New conflicts in: vruxwmqv 4fc10820 conflict | (conflict) (empty) conflict
Working copy now at: vruxwmqv 4fc10820 conflict | (conflict) (empty) conflict
Parent commit : zsuskuln aa493daf a | a
Parent commit : royxmykx db6a4daf b | b
Expand Down

0 comments on commit 1deeb5d

Please sign in to comment.