git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] usage_with_options: omit double new line on empty option list

From
Stefan Beller <sbeller@google.com>
Date
Aug 25, 2017, 16:48 UTC
Message-ID
<20170825164837.30118-1-sbeller@google.com>

Currently the worktree command gives its usage, when no subcommand is given. However there are no general options, all options are related to the subcommands itself, such that:

    $ git worktree
    usage: git worktree add [<options>] <path> [<branch>]
       or: git worktree list [<options>]
       or: git worktree lock [<options>] <path>
       or: git worktree prune [<options>]
       or: git worktree unlock <path>
    $

Note the two empty lines at the end of the usage string. This is because the toplevel usage is printed with an empty options list.

Only print one new line after the usage string if the option list is empty.
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 parse-options.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/parse-options.c b/parse-options.c
index 0dd9fc6a0d..1307c82861 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -603,7 +603,7 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
 		usagestr++;
 	}
 
-	if (opts->type != OPTION_GROUP)
+	if (opts->type != OPTION_GROUP && opts->type != OPTION_END)
 		fputc('\n', outfile);
 
 	for (; opts->type != OPTION_END; opts++) {
-- 
2.14.0.rc0.3.g6c2e499285
Next: Junio C Hamano
Message 1 of 5 in “usage_with_options: omit double new line on empty option list”
  1. usage_with_options: omit double new line on empty option listStefan Beller, Aug 25, 2017
  2. Junio C HamanoAug 25, 2017
  3. Stefan BellerAug 25, 2017
  4. Junio C HamanoAug 25, 2017
  5. Junio C HamanoAug 25, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.