forked from mirrors/jj
cli: disallow gc run from non-head operation
It doesn't make sense to do gc from a non-head operation because that means either the head operation would be corrupted or the --at-op argument is ignored.
This commit is contained in:
parent
5894f3dfba
commit
7cfd32bac1
2 changed files with 24 additions and 0 deletions
|
@ -108,6 +108,11 @@ fn cmd_util_gc(
|
|||
command: &CommandHelper,
|
||||
_args: &UtilGcArgs,
|
||||
) -> Result<(), CommandError> {
|
||||
if command.global_args().at_operation != "@" {
|
||||
return Err(user_error(
|
||||
"Cannot garbage collect from a non-head operation",
|
||||
));
|
||||
}
|
||||
let workspace_command = command.workspace_helper(ui)?;
|
||||
let store = workspace_command.repo().store();
|
||||
store.gc().map_err(|err| user_error(err.to_string()))?;
|
||||
|
|
|
@ -37,3 +37,22 @@ fn test_util_config_schema() {
|
|||
"###)
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_gc_args() {
|
||||
let test_env = TestEnvironment::default();
|
||||
// Use the local backend because GitBackend::gc() depends on the git CLI.
|
||||
test_env.jj_cmd_ok(
|
||||
test_env.env_root(),
|
||||
&["init", "repo", "--config-toml=ui.allow-init-native=true"],
|
||||
);
|
||||
let repo_path = test_env.env_root().join("repo");
|
||||
|
||||
let (_stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["util", "gc"]);
|
||||
insta::assert_snapshot!(stderr, @"");
|
||||
|
||||
let stderr = test_env.jj_cmd_failure(&repo_path, &["util", "gc", "--at-op=@-"]);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Error: Cannot garbage collect from a non-head operation
|
||||
"###);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue