worktree: accept -f as short for --force for removal
PATCH 1/1 worktree: accept -f as short for --force for removal
The force flag is very common in many commands and is commonly abbreviated with '-f', so add that to worktree removal, too
---
As a side note:
$ git worktree add ../test HEAD^ $ cd ../test $ make $ git worktree remove test fatal: working trees containing submodules cannot be moved or removed
(This is on git.git, which does have submodules, but they should not be relevant here? Instead we rather want to point out files left over. Not sure. I also plan on having worktrees and submodules to work well together eventually)
builtin/worktree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/worktree.c +1 -1
@@ -783,7 +783,7 @@ static int remove_worktree(int ac, const char **av, const char *prefix) {int force =0 ;struct option options[] = { -OPT_BOOL (0 ,"force" , &force, +OPT_BOOL ('f' ,"force" , &force,N_ ("force removing even if the worktree is dirty" )),OPT_END () };
Signature · 1 line
2.17.0.484.g0c8726318c-goog
builtin/worktree.c static int remove_worktree(int ac, const char **av, const char *prefix) · line 787
Quoted 13 lines · Stefan Beller
The force flag is very common in many commands and is commonly abbreviated with '-f', so add that to worktree removal, too
Signed-off-by Stefan Beller <[email protected]>---
builtin/worktree.c +1
-1@@ -783,7 +783,7 @@ static int remove_worktree(int ac, const char **av, const char *prefix) {int force =0 ;struct option options[] = { -OPT_BOOL (0 ,"force" , &force, +OPT_BOOL ('f' ,"force" , &force,N_ ("force removing even if the worktree is dirty" )),
Should this be using OPT__FORCE, rather than OPT_BOOL, to be consistent with worktree.c:add()?
Also, can you amend the commit message to mention that "git worktree remove -f" was already documented, and that it was only the implementation which was lacking? Thanks.
Quoted 2 lines
builtin/worktree.c +0
-0OPT_END() };
PATCH 1/1 worktree: accept -f as short for --force for removal
The force flag is very common in many commands and is commonly abbreviated with '-f', so add that to worktree removal, too by using OPT__FORCE instead of a self cooked OPT_BOOL for force. While at it, add the PARSE_OPT_NOCOMPLETE flag to the force command line option as forcing a removal may lose files.
The short form of "-f" is already documented in the man page, so we do not have to adjust the docs.
---
Quoted 2 lines
Should this be using
OPT__FORCE, rather thanOPT_BOOL, to be consistent with worktree.c:add()?
yes it should.
Quoted 3 lines
Also, can you amend the commit message to mention that "git worktree remove -f" was already documented, and that it was only the implementation which was lacking? Thanks.
done.
I tried to clear up the docs, but after reading them a couple times, it looks good as-is.
Documentation/git-worktree.txt | 2 +- builtin/worktree.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-)
Documentation/git-worktree.txt +1 -1
@@ -14,7 +14,7 @@ SYNOPSIS 'git worktree lock' [--reason <string>] <worktree> 'git worktree move' <worktree> <new-path> 'git worktree prune' [-n] [-v] [--expire <expire>] -'git worktree remove' [--force] <worktree> +'git worktree remove' [-f] <worktree> 'git worktree unlock' <worktree> DESCRIPTION
builtin/worktree.c +3 -2
@@ -783,8 +783,9 @@ static int remove_worktree(int ac, const char **av, const char *prefix) {int force =0 ;struct option options[] = { -OPT_BOOL (0 ,"force" , &force, -N_ ("force removing even if the worktree is dirty" )), +OPT__FORCE (&force, +N_ ("force removing even if the worktree is dirty" ), +PARSE_OPT_NOCOMPLETE ),OPT_END () };struct worktree **worktrees, *wt;
Signature · 1 line
2.17.0.255.g8bfb7c0704
Quoted 3 lines · Stefan Beller
The force flag is very common in many commands and is commonly abbreviated with '-f', so add that to worktree removal, too by using
OPT__FORCEinstead of a self cookedOPT_BOOLfor force.
The missing bit of this sentence:
...self cooked OPT_BOOL for force which forgets '-f'.
Quoted 5 lines
While at it, add the
PARSE_OPT_NOCOMPLETEflag to the force command line option as forcing a removal may lose files.The short form of "-f" is already documented in the man page, so we do not have to adjust the docs.
Makes sense. A possible rewrite (of the entire commit message):
worktree: remove: recognize -f as short for --force
Many commands support a --force option, frequently abbreviated as -f, however, "git worktree remove"'s hand-rolled OPT_BOOL forgets to recognize the short form, despite git-worktree.txt documenting -f as supported. Replace OPT_BOOL with OPT__FORCE, which provides -f for free, and makes 'remove' consistent with 'add' option parsing (which also specifies the PARSE_OPT_NOCOMPLETE flag).
Quoted 2 lines
Helped-by Eric Sunshine <[email protected]>Signed-off-by Stefan Beller <[email protected]>
The patch itself looks good. Thanks. With or without the above rewrite or minor adjustment, this patch is:
Quoted 17 lines · Eric Sunshine
Quoted 3 lines · Stefan Beller
The force flag is very common in many commands and is commonly abbreviated with '-f', so add that to worktree removal, too by using
OPT__FORCEinstead of a self cookedOPT_BOOLfor force.The missing bit of this sentence:
...self cooked
OPT_BOOLfor force which forgets '-f'.Quoted 5 lines
While at it, add the
PARSE_OPT_NOCOMPLETEflag to the force command line option as forcing a removal may lose files.The short form of "-f" is already documented in the man page, so we do not have to adjust the docs.
Makes sense. A possible rewrite (of the entire commit message):
Quoted 11 lines
worktree: remove: recognize -f as short for --force
Many commands support a --force option, frequently abbreviated as -f, however, "git worktree remove"'s hand-rolled
OPT_BOOLforgets to recognize the short form, despite git-worktree.txt documenting -f as supported. ReplaceOPT_BOOLwithOPT__FORCE, which provides -f for free, and makes 'remove' consistent with 'add' option parsing (which also specifies thePARSE_OPT_NOCOMPLETEflag).Quoted 2 lines
Helped-by Eric Sunshine <[email protected]>Signed-off-by Stefan Beller <[email protected]>
Looks better. I am not sure if s/--force/-f/ in the synopsis section is warranted, but '-f' is commonly understood as '--force' (and that is the point of this patch after all), so it is probably an improvement to be briefer.
Thanks, both.
Quoted 5 lines
The patch itself looks good. Thanks. With or without the above rewrite or minor adjustment, this patch is:
Reviewed-by Eric Sunshine <[email protected]>
Quoted 12 lines · Junio C Hamano
Quoted 11 lines · Eric Sunshine
Makes sense. A possible rewrite (of the entire commit message):
worktree: remove: recognize -f as short for --force
Many commands support a --force option, frequently abbreviated as -f, however, "git worktree remove"'s hand-rolled
OPT_BOOLforgets to recognize the short form, despite git-worktree.txt documenting -f as supported. ReplaceOPT_BOOLwithOPT__FORCE, which provides -f for free, and makes 'remove' consistent with 'add' option parsing (which also specifies thePARSE_OPT_NOCOMPLETEflag).
Quoted 4 lines
Looks better. I am not sure if s/--force/-f/ in the synopsis section is warranted, but '-f' is commonly understood as '--force' (and that is the point of this patch after all), so it is probably an improvement to be briefer.
I meant to mention the synopsis change in the rewritten commit message. The s/--force/-f/ for 'remove' makes it consistent with the how it's shown for 'add' in the synopsis. (Changing it the other way, so 'add' shows --force would also work.)