mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-01 00:50:57 +00:00
sparse: extract "set --reset" to subcommand
Since --reset conflicts with the other flags, "set --reset" seems odd.
This commit is contained in:
parent
db94848341
commit
dcf75788e0
4 changed files with 36 additions and 18 deletions
|
@ -16,7 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
* The `git_head` template keyword now returns an optional value instead of a
|
* The `git_head` template keyword now returns an optional value instead of a
|
||||||
list of 0 or 1 element.
|
list of 0 or 1 element.
|
||||||
|
|
||||||
* The `jj sparse set --edit` was split up into `jj sparse edit`.
|
* The `jj sparse set --edit`/`--reset` flags were split up into `jj sparse
|
||||||
|
edit`/`reset` subcommands respectively.
|
||||||
|
|
||||||
* The `jj sparse` subcommands now parse and print patterns as workspace-relative
|
* The `jj sparse` subcommands now parse and print patterns as workspace-relative
|
||||||
paths.
|
paths.
|
||||||
|
|
|
@ -37,6 +37,7 @@ use crate::ui::Ui;
|
||||||
pub(crate) enum SparseArgs {
|
pub(crate) enum SparseArgs {
|
||||||
List(SparseListArgs),
|
List(SparseListArgs),
|
||||||
Set(SparseSetArgs),
|
Set(SparseSetArgs),
|
||||||
|
Reset(SparseResetArgs),
|
||||||
Edit(SparseEditArgs),
|
Edit(SparseEditArgs),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,11 +74,12 @@ pub(crate) struct SparseSetArgs {
|
||||||
/// Include no files in the working copy (combine with --add)
|
/// Include no files in the working copy (combine with --add)
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
clear: bool,
|
clear: bool,
|
||||||
/// Include all files in the working copy
|
|
||||||
#[arg(long, conflicts_with_all = &["add", "remove", "clear"])]
|
|
||||||
reset: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Reset the patterns to include all files in the working copy
|
||||||
|
#[derive(clap::Args, Clone, Debug)]
|
||||||
|
pub(crate) struct SparseResetArgs {}
|
||||||
|
|
||||||
/// Start an editor to update the patterns that are present in the working copy
|
/// Start an editor to update the patterns that are present in the working copy
|
||||||
#[derive(clap::Args, Clone, Debug)]
|
#[derive(clap::Args, Clone, Debug)]
|
||||||
pub(crate) struct SparseEditArgs {}
|
pub(crate) struct SparseEditArgs {}
|
||||||
|
@ -91,6 +93,7 @@ pub(crate) fn cmd_sparse(
|
||||||
match args {
|
match args {
|
||||||
SparseArgs::List(sub_args) => cmd_sparse_list(ui, command, sub_args),
|
SparseArgs::List(sub_args) => cmd_sparse_list(ui, command, sub_args),
|
||||||
SparseArgs::Set(sub_args) => cmd_sparse_set(ui, command, sub_args),
|
SparseArgs::Set(sub_args) => cmd_sparse_set(ui, command, sub_args),
|
||||||
|
SparseArgs::Reset(sub_args) => cmd_sparse_reset(ui, command, sub_args),
|
||||||
SparseArgs::Edit(sub_args) => cmd_sparse_edit(ui, command, sub_args),
|
SparseArgs::Edit(sub_args) => cmd_sparse_edit(ui, command, sub_args),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,23 +120,31 @@ fn cmd_sparse_set(
|
||||||
let mut workspace_command = command.workspace_helper(ui)?;
|
let mut workspace_command = command.workspace_helper(ui)?;
|
||||||
update_sparse_patterns_with(ui, &mut workspace_command, |_ui, old_patterns| {
|
update_sparse_patterns_with(ui, &mut workspace_command, |_ui, old_patterns| {
|
||||||
let mut new_patterns = HashSet::new();
|
let mut new_patterns = HashSet::new();
|
||||||
if args.reset {
|
if !args.clear {
|
||||||
new_patterns.insert(RepoPathBuf::root());
|
new_patterns.extend(old_patterns.iter().cloned());
|
||||||
} else {
|
for path in &args.remove {
|
||||||
if !args.clear {
|
new_patterns.remove(path);
|
||||||
new_patterns.extend(old_patterns.iter().cloned());
|
|
||||||
for path in &args.remove {
|
|
||||||
new_patterns.remove(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for path in &args.add {
|
|
||||||
new_patterns.insert(path.to_owned());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for path in &args.add {
|
||||||
|
new_patterns.insert(path.to_owned());
|
||||||
|
}
|
||||||
Ok(new_patterns.into_iter().sorted_unstable().collect())
|
Ok(new_patterns.into_iter().sorted_unstable().collect())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(skip_all)]
|
||||||
|
fn cmd_sparse_reset(
|
||||||
|
ui: &mut Ui,
|
||||||
|
command: &CommandHelper,
|
||||||
|
_args: &SparseResetArgs,
|
||||||
|
) -> Result<(), CommandError> {
|
||||||
|
let mut workspace_command = command.workspace_helper(ui)?;
|
||||||
|
update_sparse_patterns_with(ui, &mut workspace_command, |_ui, _old_patterns| {
|
||||||
|
Ok(vec![RepoPathBuf::root()])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
#[instrument(skip_all)]
|
#[instrument(skip_all)]
|
||||||
fn cmd_sparse_edit(
|
fn cmd_sparse_edit(
|
||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
|
|
|
@ -70,6 +70,7 @@ This document contains the help content for the `jj` command-line program.
|
||||||
* [`jj sparse`↴](#jj-sparse)
|
* [`jj sparse`↴](#jj-sparse)
|
||||||
* [`jj sparse list`↴](#jj-sparse-list)
|
* [`jj sparse list`↴](#jj-sparse-list)
|
||||||
* [`jj sparse set`↴](#jj-sparse-set)
|
* [`jj sparse set`↴](#jj-sparse-set)
|
||||||
|
* [`jj sparse reset`↴](#jj-sparse-reset)
|
||||||
* [`jj sparse edit`↴](#jj-sparse-edit)
|
* [`jj sparse edit`↴](#jj-sparse-edit)
|
||||||
* [`jj split`↴](#jj-split)
|
* [`jj split`↴](#jj-split)
|
||||||
* [`jj squash`↴](#jj-squash)
|
* [`jj squash`↴](#jj-squash)
|
||||||
|
@ -1615,6 +1616,7 @@ Manage which paths from the working-copy commit are present in the working copy
|
||||||
|
|
||||||
* `list` — List the patterns that are currently present in the working copy
|
* `list` — List the patterns that are currently present in the working copy
|
||||||
* `set` — Update the patterns that are present in the working copy
|
* `set` — Update the patterns that are present in the working copy
|
||||||
|
* `reset` — Reset the patterns to include all files in the working copy
|
||||||
* `edit` — Start an editor to update the patterns that are present in the working copy
|
* `edit` — Start an editor to update the patterns that are present in the working copy
|
||||||
|
|
||||||
|
|
||||||
|
@ -1645,11 +1647,15 @@ For example, if all you need is the `README.md` and the `lib/` directory, use `j
|
||||||
|
|
||||||
Possible values: `true`, `false`
|
Possible values: `true`, `false`
|
||||||
|
|
||||||
* `--reset` — Include all files in the working copy
|
|
||||||
|
|
||||||
Possible values: `true`, `false`
|
|
||||||
|
|
||||||
|
|
||||||
|
## `jj sparse reset`
|
||||||
|
|
||||||
|
Reset the patterns to include all files in the working copy
|
||||||
|
|
||||||
|
**Usage:** `jj sparse reset`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## `jj sparse edit`
|
## `jj sparse edit`
|
||||||
|
|
|
@ -122,7 +122,7 @@ fn test_sparse_manage_patterns() {
|
||||||
assert!(!repo_path.join("file3").exists());
|
assert!(!repo_path.join("file3").exists());
|
||||||
|
|
||||||
// Can reset back to all files
|
// Can reset back to all files
|
||||||
let (stdout, stderr) = test_env.jj_cmd_ok(&sub_dir, &["sparse", "set", "--reset"]);
|
let (stdout, stderr) = test_env.jj_cmd_ok(&sub_dir, &["sparse", "reset"]);
|
||||||
insta::assert_snapshot!(stdout, @"");
|
insta::assert_snapshot!(stdout, @"");
|
||||||
insta::assert_snapshot!(stderr, @r###"
|
insta::assert_snapshot!(stderr, @r###"
|
||||||
Added 2 files, modified 0 files, removed 0 files
|
Added 2 files, modified 0 files, removed 0 files
|
||||||
|
|
Loading…
Reference in a new issue