Skip to content

Commit ec173fc

Browse files
genevievehelselmeta-codesync[bot]
authored andcommitted
worktree: remove --keep option from remove subcmd
Summary: I previously added this as I found it useful, but it's annoying to code around (see D99632807) and it looks like I am the only user besides AI agents using it incorrectly https://fburl.com/scuba/dev_command_timers/n0ltcql9 We can add something back if folks ask for it, perhaps even just as its own subcommand so its not used incorrectly by agents Reviewed By: muirdm Differential Revision: D100056485 fbshipit-source-id: f438ce47eeb52519db915221428d519da44309f7
1 parent 429e5cf commit ec173fc

File tree

3 files changed

+19
-58
lines changed

3 files changed

+19
-58
lines changed

eden/scm/lib/commands/commands/cmdworktree/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ define_flags! {
3030
/// create a snapshot of the current working copy, then restore it in the new worktree (for 'add')
3131
snapshot: bool,
3232

33-
/// only unlink from group, keep the checkout on disk (for 'remove')
34-
keep: bool,
35-
3633
/// remove all linked worktrees (for 'remove')
3734
all: bool,
3835

@@ -102,7 +99,7 @@ pub fn doc() -> &'static str {
10299
103100
list [-Tjson] List all worktrees in the group
104101
add [PATH] [--label TEXT] [--snapshot] Create a new linked worktree
105-
remove PATH [--all] [--keep] [-y] Remove linked worktree(s)
102+
remove PATH [--all] [-y] Remove linked worktree(s)
106103
label [PATH] TEXT [--remove] Set or remove a worktree label
107104
108105
If PATH is omitted from `add`, `worktree.path-generator` is used to

eden/scm/lib/commands/commands/cmdworktree/src/remove.rs

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,13 @@ pub(crate) fn run(ctx: &ReqCtx<WorktreeOpts>, repo: &Repo) -> Result<u8> {
7272
pre_hooks.run_hooks(
7373
Some(repo),
7474
true,
75-
Some(&HashMap::from([
76-
("path".to_string(), target.display().to_string()),
77-
(
78-
"keep".to_string(),
79-
if ctx.opts.keep {
80-
"true".to_string()
81-
} else {
82-
String::new()
83-
},
84-
),
85-
])),
75+
Some(&HashMap::from([(
76+
"path".to_string(),
77+
target.display().to_string(),
78+
)])),
8679
)?;
8780

88-
if !ctx.opts.keep {
89-
edenfs_client::run_eden_remove(repo.config().as_ref(), &target)?;
90-
}
81+
edenfs_client::run_eden_remove(repo.config().as_ref(), &target)?;
9182

9283
Ok(())
9384
})?;
@@ -108,8 +99,7 @@ pub(crate) fn run(ctx: &ReqCtx<WorktreeOpts>, repo: &Repo) -> Result<u8> {
10899
Ok(())
109100
})?;
110101

111-
let action = if ctx.opts.keep { "unlinked" } else { "removed" };
112-
logger.info(format!("{} {}", action, target.display()));
102+
logger.info(format!("removed {}", target.display()));
113103

114104
// NOTE: Add post-worktree-remove hook if the need arises. Note that the
115105
// hook's cwd (repo.path()) may not exist if the user removed the worktree
@@ -149,24 +139,15 @@ fn run_remove_all(
149139
pre_hooks.run_hooks(
150140
Some(repo),
151141
true,
152-
Some(&HashMap::from([
153-
("path".to_string(), path.display().to_string()),
154-
(
155-
"keep".to_string(),
156-
if ctx.opts.keep {
157-
"true".to_string()
158-
} else {
159-
String::new()
160-
},
161-
),
162-
])),
142+
Some(&HashMap::from([(
143+
"path".to_string(),
144+
path.display().to_string(),
145+
)])),
163146
)?;
164147
}
165148

166149
for path in &linked_paths {
167-
if !ctx.opts.keep {
168-
edenfs_client::run_eden_remove(repo.config().as_ref(), path)?;
169-
}
150+
edenfs_client::run_eden_remove(repo.config().as_ref(), path)?;
170151
grp.worktrees.remove(path);
171152
}
172153

@@ -177,9 +158,8 @@ fn run_remove_all(
177158
logger.info("no linked worktrees to remove");
178159
return Ok(0);
179160
}
180-
let action = if ctx.opts.keep { "unlinked" } else { "removed" };
181161
for path in &removed_paths {
182-
logger.info(format!("{} {}", action, path.display()));
162+
logger.info(format!("removed {}", path.display()));
183163
}
184164

185165
// NOTE: Add post-worktree-remove hook if the need arises. See single-remove
@@ -198,13 +178,12 @@ fn confirm_remove(ctx: &ReqCtx<WorktreeOpts>, paths: &[&Path]) -> Result<()> {
198178
abort!("running non-interactively, use -y instead");
199179
}
200180

201-
let action = if ctx.opts.keep { "unlink" } else { "remove" };
202181
if paths.len() == 1 {
203182
ctx.io()
204-
.write(format!("will {} {}\n", action, paths[0].display()))?;
183+
.write(format!("will remove {}\n", paths[0].display()))?;
205184
} else {
206185
ctx.io()
207-
.write(format!("will {} {} worktrees:\n", action, paths.len()))?;
186+
.write(format!("will remove {} worktrees:\n", paths.len()))?;
208187
for p in paths {
209188
ctx.io().write(format!(" {}\n", p.display()))?;
210189
}

eden/scm/tests/test-eden-worktree-remove.t

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,6 @@ test worktree remove - list after remove shows fewer entries
5151
linked $TESTTMP/linked2 feature-x
5252
* main $TESTTMP/myrepo
5353

54-
test worktree remove - with --keep
55-
56-
$ sl worktree add $TESTTMP/keep_me
57-
created linked worktree at $TESTTMP/keep_me
58-
$ sl worktree remove $TESTTMP/keep_me --keep -y
59-
unlinked $TESTTMP/keep_me
60-
$ test -d $TESTTMP/keep_me
61-
$ sl worktree list
62-
linked $TESTTMP/linked1
63-
linked $TESTTMP/linked2 feature-x
64-
* main $TESTTMP/myrepo
65-
66-
clean up kept checkout
67-
$ EDENFSCTL_ONLY_RUST=true eden rm -y $TESTTMP/keep_me > /dev/null 2>&1
68-
6954
test worktree remove --all
7055

7156
$ sl worktree remove --all -y
@@ -87,14 +72,14 @@ test worktree remove - pre-worktree-remove hook fires with correct env vars
8772
$ sl worktree add $TESTTMP/pre_hook_rm1
8873
created linked worktree at $TESTTMP/pre_hook_rm1
8974
#if windows
90-
$ setconfig hooks.pre-worktree-remove="echo PATH:%HG_PATH% KEEP:%HG_KEEP%"
75+
$ setconfig hooks.pre-worktree-remove="echo PATH:%HG_PATH%"
9176
$ sl worktree remove $TESTTMP/pre_hook_rm1 -y
92-
PATH:$TESTTMP?pre_hook_rm1 KEEP:\r (esc) (glob)
77+
PATH:$TESTTMP?pre_hook_rm1\r (esc) (glob)
9378
removed $TESTTMP/pre_hook_rm1
9479
#else
95-
$ setconfig hooks.pre-worktree-remove="echo PATH:\$HG_PATH KEEP:\$HG_KEEP"
80+
$ setconfig hooks.pre-worktree-remove="echo PATH:\$HG_PATH"
9681
$ sl worktree remove $TESTTMP/pre_hook_rm1 -y
97-
PATH:$TESTTMP/pre_hook_rm1 KEEP:
82+
PATH:$TESTTMP/pre_hook_rm1
9883
removed $TESTTMP/pre_hook_rm1
9984
#endif
10085

0 commit comments

Comments
 (0)