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

Re: [PATCH] remote: unify main and subcommand usage strings

From
Jiang Xin <worldhello.net@gmail.com>
Date
Nov 3, 2013, 08:03 UTC
Message-ID
<CANYiYbGh-HR+hJcLg9AGbdXU=ypW8YwFqVcyVactJMYg4OOF7w@mail.gmail.com>
In-Reply-To
<CANYiYbGD=VJ64pESwxkMYy8HxESyW_2N0Q5M92rCJF2E1FD-bw@mail.gmail.com>
2013/11/3 Jiang Xin <worldhello.net@gmail.com>:
Show 55 quoted lines
> 2013/11/3 Thomas Rast <tr@thomasrast.ch>:
>> Note that this patch changes the usage strings for the following
>> subcommands:
>
> Differences of git-remote usages after applied your patch.
>
> diff -u before/git-remote-add-usage after/git-remote-add-usage
> --- before/git-remote-add-usage 2013-11-03 15:10:06.000000000 +0800
> +++ after/git-remote-add-usage 2013-11-03 15:11:32.000000000 +0800
> @@ -1,4 +1,4 @@
> -usage: git remote add [<options>] <name> <url>
> +usage: git remote add [-t <branch>] [-m <master>] [-f]
> [--tags|--no-tags] [--mirror=<fetch|push>] <name> <url>
>
>      -f, --fetch           fetch the remote branches
>      --tags                import all tags and associated objects when fetching
>
> diff -u before/git-remote-prune-usage after/git-remote-prune-usage
> --- before/git-remote-prune-usage 2013-11-03 15:10:06.000000000 +0800
> +++ after/git-remote-prune-usage 2013-11-03 15:11:32.000000000 +0800
> @@ -1,4 +1,4 @@
> -usage: git remote prune [<options>] <name>
> +usage: git remote prune [-n | --dry-run] <name>
>
>      -n, --dry-run         dry run
>
> diff -u before/git-remote-set-branches-usage after/git-remote-set-branches-usage
> --- before/git-remote-set-branches-usage 2013-11-03 15:10:06.000000000 +0800
> +++ after/git-remote-set-branches-usage 2013-11-03 15:11:32.000000000 +0800
> @@ -1,5 +1,4 @@
> -usage: git remote set-branches <name> <branch>...
> -   or: git remote set-branches --add <name> <branch>...
> +usage: git remote set-branches [--add] <name> <branch>...
>
>      --add                 add branch
>
> diff -u before/git-remote-show-usage after/git-remote-show-usage
> --- before/git-remote-show-usage 2013-11-03 15:10:06.000000000 +0800
> +++ after/git-remote-show-usage 2013-11-03 15:11:32.000000000 +0800
> @@ -1,4 +1,4 @@
> -usage: git remote show [<options>] <name>
> +usage: git remote [-v | --verbose] show [-n] <name>
>
>      -n                    do not query remotes
>
> diff -u before/git-remote-update-usage after/git-remote-update-usage
> --- before/git-remote-update-usage 2013-11-03 15:10:06.000000000 +0800
> +++ after/git-remote-update-usage 2013-11-03 15:11:32.000000000 +0800
> @@ -1,4 +1,4 @@
> -usage: git remote update [<options>] [<group> | <remote>]...
> +usage: git remote [-v | --verbose] update [-p | --prune] [(<group> |
> <remote>)...]
>
>      -p, --prune           prune remotes after fetching
>
In order to get the differences of git-remote usages, I write a script.
    # SCRIPT to save git remote usage in files.
    for cmd in add set-head show prune update set-branches set-url; do
            git remote $cmd -h > $DIR/git-remote-$cmd-usage
    done
    git remote -h > $DIR/git-remote-usage
    git remote remove  > $DIR/git-remote-remove-usage 2>&1
    git remote rename  > $DIR/git-remote-rename-usage  2>&1
Then I find two subcommands (remove and rename) are strange.
 * All other subcommands output usages to STDIN, but subcommands
    "remove" and "rename" send their usages to STDERR.
 * I can get the help message of all other subcommands using:
   "git remote <subcmd> -h", but not "git remote rm -h"
        $ git remote rm -h
        error: Could not remove config section 'remote.-h'

Later I know it's a side-effect that all other subcommands could print usages if provide a unkown "-h/--help" option.

What if add a parse_options call for both "rm" and "mv" functions in builtin/remote.c?

diff --git a/builtin/remote.c b/builtin/remote.c
index 2f6366a..171d1a8 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -651,6 +651,8 @@ static int mv(int argc, const char **argv)
        struct rename_info rename;
        int i, refspec_updated = 0;

+       argc = parse_options(argc, argv, NULL, options,
+                            builtin_remote_rename_usage, 0);
        if (argc != 3)
                usage_with_options(builtin_remote_rename_usage, options);

@@ -808,6 +810,8 @@ static int rm(int argc, const char **argv)
        cb_data.skipped = &skipped;
        cb_data.keep = &known_remotes;

+       argc = parse_options(argc, argv, NULL, options,
+                            builtin_remote_rm_usage,0);
        if (argc != 2)
                usage_with_options(builtin_remote_rm_usage, options);
-- 
Jiang Xin
Previous: Jiang Xin
Message 4 of 4 in “Re: [L10N] Kick off for Git 1.8.5 l10n round 1”
  1. Trần Ngọc QuânNov 2, 2013
  2. remote: unify main and subcommand usage stringsThomas Rast, Nov 2, 2013
  3. Jiang XinNov 3, 2013
  4. Jiang XinNov 3, 2013

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.