Skip to contentSkip to conversation

worktree: accept -f as short for --force for removal

PATCH In review Stefan Beller 3 participants 6 messages Apr 16, 2018 – Apr 18, 2018 Documentation

lore
Share & tools
lore
#0 lore raw

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
index 40a438ed6c..d734874d58 100644
@@ -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
#1 lore raw

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

---

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 -0
                OPT_END()
        };
#2 lore raw

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 than OPT_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
index e7eb24ab85..99b713c849 100644
@@ -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
index 40a438ed6c..30647b30c5 100644
@@ -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
Reviewed-by on v1 1/1
#3 lore raw
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__FORCE instead of a self cooked OPT_BOOL for 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_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.

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

The patch itself looks good. Thanks. With or without the above rewrite or minor adjustment, this patch is:

#4 lore raw
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__FORCE instead of a self cooked OPT_BOOL for 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_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.

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_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

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:

#5 lore raw
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_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 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.)