ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: drop support for ui.enable-open-commits config

This commit is contained in:
Martin von Zweigbergk 2022-11-04 18:24:20 -07:00 committed by Martin von Zweigbergk
parent f02d92a3fe
commit 21cda3431c
6 changed files with 28 additions and 141 deletions

View file

@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`committer(needle)`, `merges()` revsets. Use `x & description(needle)`
instead.
* Support for open commits has been dropped. The `ui.enable-open-commits` config
that was added in 0.5.0 is no longer respected.
* `jj commit` is now a separate command from `jj close` (which is deprecated).
The behavior has changed slightly. It now always asks for a description, even
if there already was a description set. It now also only works on the

View file

@ -20,26 +20,6 @@ the working copy, first make sure it's [ignored](#ignored-files) and then run
`jj untrack <path>`.
## Open/closed revisions
This section only applies if you have set `ui.enable-open-commits = true`
in your config.
As described in the introduction, Jujutsu automatically rewrites the current
working-copy commit with any changes from the working copy. That works well
while you're developing that revision. On the other hand, if you check out some
existing revision, you generally don't want changes to the working copy to
automatically rewrite that revision. Jujutsu has a concept of "open" and
"closed" revisions to solve this. When you check out a closed revision, Jujutsu
will actually create a new, *open* revision on top of it and check that out. The
working-copy commit is thus always open. When you are done making changes to
the current working-copy commit, you close it by running `jj close`. That
command then updates to the rewritten revision (as most `jj` commands do), and
since the rewritten revision is now closed, it creates a new open revision on
top. If you check out a closed revision and make changes on top of it that you
want to go into the revision, use `jj squash`.
## Conflicts
When you check out a commit with conflicts, those conflicts need to be

View file

@ -96,12 +96,6 @@ impl UserSettings {
}
}
pub fn enable_open_commits(&self) -> bool {
self.config
.get_bool("ui.enable-open-commits")
.unwrap_or(false)
}
pub fn allow_native_backend(&self) -> bool {
self.config
.get_bool("ui.allow-init-native")

View file

@ -1102,15 +1102,7 @@ pub fn write_commit_summary(
let template_string = settings
.config()
.get_string("template.commit_summary")
.unwrap_or_else(|_| {
if settings.enable_open_commits() {
String::from(
r#"label(if(open, "open"), commit_id.short() " " description.first_line())"#,
)
} else {
String::from(r#"commit_id.short() " " description.first_line()"#)
}
});
.unwrap_or_else(|_| String::from(r#"commit_id.short() " " description.first_line()"#));
let template =
crate::template_parser::parse_commit_template(repo, workspace_id, &template_string);
let mut template_writer = TemplateFormatter::new(template, formatter);

View file

@ -1155,45 +1155,17 @@ fn cmd_checkout(
let mut workspace_command = command.workspace_helper(ui)?;
let target = workspace_command.resolve_single_rev(&args.revision)?;
let workspace_id = workspace_command.workspace_id();
if ui.settings().enable_open_commits() {
if workspace_command
.repo()
.view()
.get_wc_commit_id(&workspace_id)
== Some(target.id())
{
ui.write("Already on that commit\n")?;
} else {
let mut tx = workspace_command
.start_transaction(&format!("check out commit {}", target.id().hex()));
if target.is_open() {
// Root is never open
tx.mut_repo().edit(workspace_id, &target).unwrap();
} else {
let commit_builder = CommitBuilder::for_open_commit(
ui.settings(),
target.id().clone(),
target.tree_id().clone(),
)
.set_description(args.message.clone());
let new_commit = commit_builder.write_to_repo(tx.mut_repo());
tx.mut_repo().edit(workspace_id, &new_commit).unwrap();
}
workspace_command.finish_transaction(ui, tx)?;
}
} else {
let mut tx =
workspace_command.start_transaction(&format!("check out commit {}", target.id().hex()));
let commit_builder = CommitBuilder::for_open_commit(
ui.settings(),
target.id().clone(),
target.tree_id().clone(),
)
.set_description(args.message.clone());
let new_commit = commit_builder.write_to_repo(tx.mut_repo());
tx.mut_repo().edit(workspace_id, &new_commit).unwrap();
workspace_command.finish_transaction(ui, tx)?;
}
let mut tx =
workspace_command.start_transaction(&format!("check out commit {}", target.id().hex()));
let commit_builder = CommitBuilder::for_open_commit(
ui.settings(),
target.id().clone(),
target.tree_id().clone(),
)
.set_description(args.message.clone());
let new_commit = commit_builder.write_to_repo(tx.mut_repo());
tx.mut_repo().edit(workspace_id, &new_commit).unwrap();
workspace_command.finish_transaction(ui, tx)?;
Ok(())
}
@ -1440,18 +1412,10 @@ fn cmd_show(ui: &mut Ui, command: &CommandHelper, args: &ShowArgs) -> Result<(),
"\n"
description
"\n""#;
let template_string = if ui.settings().enable_open_commits() {
format!(
r#"
label(if(open, "open"), {template_string})"#
)
} else {
String::from(template_string)
};
let template = crate::template_parser::parse_commit_template(
workspace_command.repo().as_repo_ref(),
&workspace_command.workspace_id(),
&template_string,
template_string,
);
let mut formatter = ui.stdout_formatter();
let formatter = formatter.as_mut();
@ -2070,18 +2034,10 @@ fn log_template(settings: &UserSettings) -> String {
"\n"
description.first_line()
"\n""#;
let default_template = if settings.enable_open_commits() {
format!(
r#"
label(if(open, "open"), {default_template})"#
)
} else {
String::from(default_template)
};
settings
.config()
.get_string("template.log.graph")
.unwrap_or(default_template)
.unwrap_or_else(|_| default_template.to_string())
}
fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), CommandError> {

View file

@ -24,66 +24,28 @@ fn test_checkout() {
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
test_env.add_config(
br#"[ui]
enable-open-commits = true
"#,
);
test_env.jj_cmd_success(&repo_path, &["close", "-m", "closed"]);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "open"]);
test_env.jj_cmd_success(&repo_path, &["branch", "create", "open"]);
test_env.jj_cmd_success(&repo_path, &["commit", "-m", "first"]);
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "second"]);
// Check out current commit
let stdout = test_env.jj_cmd_success(&repo_path, &["checkout", "@"]);
insta::assert_snapshot!(stdout, @r###"
Already on that commit
Working copy now at: 66f7f3f8235b (no description set)
"###);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 169fa76981bcf302d1a96952bdf32a8da79ab084 open
o b4c967d9c9a9e8b523b0a9b52879b3337a3e67a9 closed
o 0000000000000000000000000000000000000000 (no description set)
"###);
// When checking out a closed commit, a new commit is created on top of it
test_env.jj_cmd_success(&repo_path, &["checkout", "@-"]);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 5a38be51f15b107b7c7e89c06c0ab626f1457128 (no description set)
| o 169fa76981bcf302d1a96952bdf32a8da79ab084 open
|/
o b4c967d9c9a9e8b523b0a9b52879b3337a3e67a9 closed
o 0000000000000000000000000000000000000000 (no description set)
"###);
// When checking out an open commit, the specified commit is edited directly
test_env.jj_cmd_success(&repo_path, &["checkout", "open"]);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 169fa76981bcf302d1a96952bdf32a8da79ab084 open
o b4c967d9c9a9e8b523b0a9b52879b3337a3e67a9 closed
o 0000000000000000000000000000000000000000 (no description set)
"###);
// With ui.enable-open-commits=false, checking out an open commit also results
// in a commit on top
test_env.add_config(
br#"[ui]
enable-open-commits = false
"#,
);
test_env.jj_cmd_success(&repo_path, &["checkout", "open"]);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 37b7bc83cf288eef68564044a9ac0ec6c5df34f0 (no description set)
o 169fa76981bcf302d1a96952bdf32a8da79ab084 open
o b4c967d9c9a9e8b523b0a9b52879b3337a3e67a9 closed
@ 66f7f3f8235beaed90345fe93c5a86c30f4f026f (no description set)
o 91043abe9d0385a279102350df38807f4aa053b7 second
o 85a1e2839620cf0b354d1ccb970927d040c2a4a7 first
o 0000000000000000000000000000000000000000 (no description set)
"###);
// Can provide a description
test_env.jj_cmd_success(&repo_path, &["checkout", "@-", "-m", "my message"]);
test_env.jj_cmd_success(&repo_path, &["checkout", "@--", "-m", "my message"]);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ 14a7f0fd8f8a8235efdf4b20635567ebcf5c9776 my message
o 169fa76981bcf302d1a96952bdf32a8da79ab084 open
o b4c967d9c9a9e8b523b0a9b52879b3337a3e67a9 closed
@ 44f21384b2b12735d9477ec8b406bd4e48047c41 my message
| o 91043abe9d0385a279102350df38807f4aa053b7 second
|/
o 85a1e2839620cf0b354d1ccb970927d040c2a4a7 first
o 0000000000000000000000000000000000000000 (no description set)
"###);
}