Skip to content

Commit

Permalink
cli: hint for conflicted branches
Browse files Browse the repository at this point in the history
  • Loading branch information
wmrmrx committed Sep 10, 2023
1 parent fc86d91 commit e9a5a3f
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ use jj_lib::repo::{
};
use jj_lib::repo_path::{FsPathParseError, RepoPath};
use jj_lib::revset::{
DefaultSymbolResolver, Revset, RevsetAliasesMap, RevsetEvaluationError, RevsetExpression,
RevsetIteratorExt, RevsetParseContext, RevsetParseError, RevsetParseErrorKind,
RevsetResolutionError, RevsetWorkspaceContext,
DefaultSymbolResolver, Revset, RevsetAliasesMap, RevsetCommitRef, RevsetEvaluationError,
RevsetExpression, RevsetIteratorExt, RevsetParseContext, RevsetParseError,
RevsetParseErrorKind, RevsetResolutionError, RevsetWorkspaceContext,
};
use jj_lib::settings::{ConfigResultExt as _, UserSettings};
use jj_lib::transaction::Transaction;
Expand Down Expand Up @@ -1006,6 +1006,14 @@ impl WorkspaceCommandHelper {
ui: &mut Ui,
) -> Result<Commit, CommandError> {
let revset_expression = self.parse_revset(revision_str, Some(ui))?;
let branch: Option<String> =
if let RevsetExpression::CommitRef(RevsetCommitRef::Symbol(ref branch_name)) =
*revset_expression
{
Some(branch_name.clone())
} else {
None
};
let revset = self.evaluate_revset(revset_expression)?;
let mut iter = revset.iter().commits(self.repo().store()).fuse();
match (iter.next(), iter.next()) {
Expand All @@ -1017,15 +1025,29 @@ impl WorkspaceCommandHelper {
let mut iter = [commit0, commit1].into_iter().chain(iter);
let commits: Vec<_> = iter.by_ref().take(5).try_collect()?;
let elided = iter.next().is_some();
let hint = format!(
r#"The revset "{revision_str}" resolved to these revisions:{eol}{commits}{ellipsis}"#,
eol = "\n",
commits = commits
.iter()
.map(|c| self.format_commit_summary(c))
.join("\n"),
ellipsis = elided.then_some("\n...").unwrap_or_default()
);
// Separate hint if the conflict is due to a branch conflict
let hint = if let Some(branch_name) = branch {
format!(
r#"The revset "{revision_str}" resolved to these revisions:{eol}{commits}{ellipsis}
This error is due to a conflicted branch. To resolve this, try setting to which revision the branch points to with "jj branch set {branch_name} --revision <REVISION>""#,
eol = "\n",
commits = commits
.iter()
.map(|c| self.format_commit_summary(c))
.join("\n"),
ellipsis = elided.then_some("\n...").unwrap_or_default()
)
} else {
format!(
r#"The revset "{revision_str}" resolved to these revisions:{eol}{commits}{ellipsis}"#,
eol = "\n",
commits = commits
.iter()
.map(|c| self.format_commit_summary(c))
.join("\n"),
ellipsis = elided.then_some("\n...").unwrap_or_default()
)
};
Err(user_error_with_hint(
format!(r#"Revset "{revision_str}" resolved to more than one revision"#),
hint,
Expand Down

0 comments on commit e9a5a3f

Please sign in to comment.