Skip to content

Commit efa0120

Browse files
committed
feat(delete): --all -A -U -H options
1 parent 89d4eb4 commit efa0120

File tree

3 files changed

+99
-14
lines changed

3 files changed

+99
-14
lines changed

completion/stgit.zsh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,12 @@ _stg-delete() {
410410
__stg_add_args_push_conflicts
411411
subcmd_args+=(
412412
'--spill[spill patch contents to worktree and index]'
413+
- group-ahu
414+
'(-A --applied)'{-A,--applied}'[delete applied patches]'
415+
'(-H --hidden)'{-H,--hidden}'[delete hidden patches]'
416+
'(-U --unapplied)'{-U,--unapplied}'[delete unapplied patches]'
417+
- group-all
418+
'--all[delete all patches]'
413419
- group-top
414420
'(-t --top)'{-t,--top}'[delete top patch]'
415421
- group-patchnames

src/cmd/delete.rs

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ fn make() -> clap::Command {
2727
.about("Delete patches")
2828
.override_usage(super::make_usage(
2929
"stg delete",
30-
&["[OPTIONS] <patch>...", "[OPTIONS] --top"],
30+
&[
31+
"[OPTIONS] [<patch>...]",
32+
"[OPTIONS] [-A] [-U] [-H]",
33+
"[OPTIONS] --all",
34+
"[OPTIONS] --top",
35+
],
3136
))
3237
.arg(
3338
Arg::new("patchranges-all")
@@ -36,8 +41,51 @@ fn make() -> clap::Command {
3641
.num_args(1..)
3742
.allow_hyphen_values(true)
3843
.value_parser(clap::value_parser!(PatchRange))
39-
.conflicts_with("top")
40-
.required_unless_present("top"),
44+
.conflicts_with_all(["top", "all", "A-U-H"])
45+
.required_unless_present_any(["all", "top", "A-U-H"]),
46+
)
47+
.arg(
48+
Arg::new("all")
49+
.long("all")
50+
.short('a')
51+
.help("Delete all patches")
52+
.action(clap::ArgAction::SetTrue)
53+
.conflicts_with_all(["top", "A-U-H", "patchranges-all"]),
54+
)
55+
.arg(
56+
Arg::new("applied")
57+
.long("applied")
58+
.short('A')
59+
.help("Delete the applied patches")
60+
.action(clap::ArgAction::SetTrue),
61+
)
62+
.arg(
63+
Arg::new("unapplied")
64+
.long("unapplied")
65+
.short('U')
66+
.help("Delete the unapplied patches")
67+
.action(clap::ArgAction::SetTrue),
68+
)
69+
.arg(
70+
Arg::new("hidden")
71+
.long("hidden")
72+
.short('H')
73+
.help("Delete the hidden patches")
74+
.action(clap::ArgAction::SetTrue),
75+
)
76+
.group(
77+
clap::ArgGroup::new("A-U-H")
78+
.multiple(true)
79+
.args(["applied", "unapplied", "hidden"])
80+
.conflicts_with_all(["top", "all", "patchranges-all"]),
81+
)
82+
.arg(
83+
Arg::new("top")
84+
.long("top")
85+
.short('t')
86+
.help("Delete topmost patch")
87+
.action(clap::ArgAction::SetTrue)
88+
.conflicts_with_all(["all", "A-U-H", "patchranges-all"]),
4189
)
4290
.arg(
4391
Arg::new("spill")
@@ -53,13 +101,6 @@ fn make() -> clap::Command {
53101
)
54102
.action(clap::ArgAction::SetTrue),
55103
)
56-
.arg(
57-
Arg::new("top")
58-
.long("top")
59-
.short('t')
60-
.help("Delete topmost patch")
61-
.action(clap::ArgAction::SetTrue),
62-
)
63104
.arg(argset::branch_arg())
64105
.arg(argset::push_conflicts_arg())
65106
}
@@ -79,11 +120,22 @@ fn run(matches: &ArgMatches) -> Result<()> {
79120
} else {
80121
return Err(super::Error::NoAppliedPatches.into());
81122
}
82-
} else {
83-
let range_specs = matches
84-
.get_many::<PatchRange>("patchranges-all")
85-
.expect("clap will ensure either patches or --top");
123+
} else if let Some(range_specs) = matches.get_many::<PatchRange>("patchranges-all") {
86124
patchrange::resolve_names(&stack, range_specs, RangeConstraint::AllWithAppliedBoundary)?
125+
} else if matches.get_flag("all") {
126+
stack.all_patches().cloned().collect::<Vec<_>>()
127+
} else {
128+
let mut patches = Vec::new();
129+
if matches.get_flag("applied") {
130+
patches.extend(stack.applied().iter().cloned())
131+
}
132+
if matches.get_flag("unapplied") {
133+
patches.extend(stack.unapplied().iter().cloned())
134+
}
135+
if matches.get_flag("hidden") {
136+
patches.extend(stack.hidden().iter().cloned())
137+
}
138+
patches
87139
};
88140

89141
if spill_flag

t/t1601-delete-many.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,33 @@ test_expect_success 'Delete a range of patches' '
4343
[ "$(echo $(stg series --unapplied --noprefix))" = "p9" ]
4444
'
4545

46+
test_expect_success 'Delete -U' '
47+
stg undo --hard &&
48+
[ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2" ] &&
49+
[ "$(echo $(stg series --unapplied --noprefix))" = "p5 p8 p9" ] &&
50+
stg delete -U &&
51+
[ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2" ] &&
52+
[ "$(echo $(stg series --unapplied --noprefix))" = "" ]
53+
'
54+
55+
test_expect_success 'Delete -A' '
56+
stg undo --hard &&
57+
[ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2" ] &&
58+
[ "$(echo $(stg series --unapplied --noprefix))" = "p5 p8 p9" ] &&
59+
stg delete -A &&
60+
[ "$(echo $(stg series --applied --noprefix))" = "" ] &&
61+
[ "$(echo $(stg series --unapplied --noprefix))" = "p5 p8 p9" ]
62+
'
63+
64+
test_expect_success 'Delete --all' '
65+
stg undo --hard &&
66+
[ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2" ] &&
67+
[ "$(echo $(stg series --unapplied --noprefix))" = "p5 p8 p9" ] &&
68+
stg delete --all &&
69+
[ "$(echo $(stg series --all --noprefix))" = "" ] &&
70+
stg undo --hard
71+
'
72+
4673
test_expect_success 'Delete leading to conflict when re-pushing' '
4774
echo "stuff" >foo.txt &&
4875
stg new -m p-stuff &&

0 commit comments

Comments
 (0)