From 1224781d6080b8b69a81526ee23b22a1587920ea Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Fri, 9 Feb 2018 18:01:42 +0700 Subject: parse-options: let OPT__FORCE take optional flags argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --force option is most likely hidden from command line completion for safety reasons. This is done by adding an extra flag PARSE_OPT_NOCOMPLETE. Update OPT__FORCE() to accept additional flags. Actual flag change comes later depending on individual commands. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/add.c | 2 +- builtin/branch.c | 2 +- builtin/checkout-index.c | 2 +- builtin/checkout.c | 2 +- builtin/clean.c | 2 +- builtin/fetch.c | 2 +- builtin/mv.c | 2 +- builtin/notes.c | 4 ++-- builtin/pull.c | 2 +- builtin/rm.c | 2 +- builtin/tag.c | 2 +- builtin/update-server-info.c | 2 +- builtin/worktree.c | 4 +++- 13 files changed, 16 insertions(+), 14 deletions(-) (limited to 'builtin') diff --git a/builtin/add.c b/builtin/add.c index bf01d89e28..ac7c1c3277 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -294,7 +294,7 @@ static struct option builtin_add_options[] = { OPT_BOOL('i', "interactive", &add_interactive, N_("interactive picking")), OPT_BOOL('p', "patch", &patch_interactive, N_("select hunks interactively")), OPT_BOOL('e', "edit", &edit_interactive, N_("edit current diff and apply")), - OPT__FORCE(&ignored_too, N_("allow adding otherwise ignored files")), + OPT__FORCE(&ignored_too, N_("allow adding otherwise ignored files"), 0), OPT_BOOL('u', "update", &take_worktree_changes, N_("update tracked files")), OPT_BOOL(0, "renormalize", &add_renormalize, N_("renormalize EOL of tracked files (implies -u)")), OPT_BOOL('N', "intent-to-add", &intent_to_add, N_("record only the fact that the path will be added later")), diff --git a/builtin/branch.c b/builtin/branch.c index 8dcc2ed058..b5b62c08ba 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -615,7 +615,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) OPT_BOOL('l', "create-reflog", &reflog, N_("create the branch's reflog")), OPT_BOOL(0, "edit-description", &edit_description, N_("edit the description for the branch")), - OPT__FORCE(&force, N_("force creation, move/rename, deletion")), + OPT__FORCE(&force, N_("force creation, move/rename, deletion"), 0), OPT_MERGED(&filter, N_("print only branches that are merged")), OPT_NO_MERGED(&filter, N_("print only branches that are not merged")), OPT_COLUMN(0, "column", &colopts, N_("list branches in columns")), diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c index b0e78b819d..a730f6a1aa 100644 --- a/builtin/checkout-index.c +++ b/builtin/checkout-index.c @@ -157,7 +157,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix) struct option builtin_checkout_index_options[] = { OPT_BOOL('a', "all", &all, N_("check out all files in the index")), - OPT__FORCE(&force, N_("force overwrite of existing files")), + OPT__FORCE(&force, N_("force overwrite of existing files"), 0), OPT__QUIET(&quiet, N_("no warning for existing files and files not in index")), OPT_BOOL('n', "no-create", ¬_new, diff --git a/builtin/checkout.c b/builtin/checkout.c index c54c78df54..2a96358eb7 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -1118,7 +1118,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) 2), OPT_SET_INT('3', "theirs", &opts.writeout_stage, N_("checkout their version for unmerged files"), 3), - OPT__FORCE(&opts.force, N_("force checkout (throw away local modifications)")), + OPT__FORCE(&opts.force, N_("force checkout (throw away local modifications)"), 0), OPT_BOOL('m', "merge", &opts.merge, N_("perform a 3-way merge with the new branch")), OPT_BOOL(0, "overwrite-ignore", &opts.overwrite_ignore, N_("update ignored files (default)")), OPT_STRING(0, "conflict", &conflict_style, N_("style"), diff --git a/builtin/clean.c b/builtin/clean.c index 189e20628c..3c4ca9a2ff 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -909,7 +909,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix) struct option options[] = { OPT__QUIET(&quiet, N_("do not print names of files removed")), OPT__DRY_RUN(&dry_run, N_("dry run")), - OPT__FORCE(&force, N_("force")), + OPT__FORCE(&force, N_("force"), 0), OPT_BOOL('i', "interactive", &interactive, N_("interactive cleaning")), OPT_BOOL('d', NULL, &remove_directories, N_("remove whole directories")), diff --git a/builtin/fetch.c b/builtin/fetch.c index 7bbcd26faf..6a603174fb 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -115,7 +115,7 @@ static struct option builtin_fetch_options[] = { N_("append to .git/FETCH_HEAD instead of overwriting")), OPT_STRING(0, "upload-pack", &upload_pack, N_("path"), N_("path to upload pack on remote end")), - OPT__FORCE(&force, N_("force overwrite of local branch")), + OPT__FORCE(&force, N_("force overwrite of local branch"), 0), OPT_BOOL('m', "multiple", &multiple, N_("fetch from multiple remotes")), OPT_SET_INT('t', "tags", &tags, diff --git a/builtin/mv.c b/builtin/mv.c index cf3684d907..b88023a733 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -122,7 +122,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) struct option builtin_mv_options[] = { OPT__VERBOSE(&verbose, N_("be verbose")), OPT__DRY_RUN(&show_only, N_("dry run")), - OPT__FORCE(&force, N_("force move/rename even if target exists")), + OPT__FORCE(&force, N_("force move/rename even if target exists"), 0), OPT_BOOL('k', NULL, &ignore_errors, N_("skip move/rename errors")), OPT_END(), }; diff --git a/builtin/notes.c b/builtin/notes.c index 7c81761645..b52e71c73e 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -413,7 +413,7 @@ static int add(int argc, const char **argv, const char *prefix) parse_reuse_arg}, OPT_BOOL(0, "allow-empty", &allow_empty, N_("allow storing empty note")), - OPT__FORCE(&force, N_("replace existing notes")), + OPT__FORCE(&force, N_("replace existing notes"), 0), OPT_END() }; @@ -484,7 +484,7 @@ static int copy(int argc, const char **argv, const char *prefix) struct notes_tree *t; const char *rewrite_cmd = NULL; struct option options[] = { - OPT__FORCE(&force, N_("replace existing notes")), + OPT__FORCE(&force, N_("replace existing notes"), 0), OPT_BOOL(0, "stdin", &from_stdin, N_("read objects from stdin")), OPT_STRING(0, "for-rewrite", &rewrite_cmd, N_("command"), N_("load rewriting config for (implies " diff --git a/builtin/pull.c b/builtin/pull.c index 511dbbe0f6..652239aae9 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -193,7 +193,7 @@ static struct option pull_options[] = { OPT_PASSTHRU(0, "upload-pack", &opt_upload_pack, N_("path"), N_("path to upload pack on remote end"), 0), - OPT__FORCE(&opt_force, N_("force overwrite of local branch")), + OPT__FORCE(&opt_force, N_("force overwrite of local branch"), 0), OPT_PASSTHRU('t', "tags", &opt_tags, NULL, N_("fetch all tags and associated objects"), PARSE_OPT_NOARG), diff --git a/builtin/rm.c b/builtin/rm.c index 4a2fcca27b..6e0c7f5ac6 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -242,7 +242,7 @@ static struct option builtin_rm_options[] = { OPT__DRY_RUN(&show_only, N_("dry run")), OPT__QUIET(&quiet, N_("do not list removed files")), OPT_BOOL( 0 , "cached", &index_only, N_("only remove from the index")), - OPT__FORCE(&force, N_("override the up-to-date check")), + OPT__FORCE(&force, N_("override the up-to-date check"), 0), OPT_BOOL('r', NULL, &recursive, N_("allow recursive removal")), OPT_BOOL( 0 , "ignore-unmatch", &ignore_unmatch, N_("exit with a zero status even if nothing matched")), diff --git a/builtin/tag.c b/builtin/tag.c index a7e6a5b0f2..98d3956bbe 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -391,7 +391,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix) N_("how to strip spaces and #comments from message")), OPT_STRING('u', "local-user", &keyid, N_("key-id"), N_("use another key to sign the tag")), - OPT__FORCE(&force, N_("replace the tag if exists")), + OPT__FORCE(&force, N_("replace the tag if exists"), 0), OPT_BOOL(0, "create-reflog", &create_reflog, N_("create a reflog")), OPT_GROUP(N_("Tag listing options")), diff --git a/builtin/update-server-info.c b/builtin/update-server-info.c index 873070e517..4321a34456 100644 --- a/builtin/update-server-info.c +++ b/builtin/update-server-info.c @@ -12,7 +12,7 @@ int cmd_update_server_info(int argc, const char **argv, const char *prefix) { int force = 0; struct option options[] = { - OPT__FORCE(&force, N_("update the info files from scratch")), + OPT__FORCE(&force, N_("update the info files from scratch"), 0), OPT_END() }; diff --git a/builtin/worktree.c b/builtin/worktree.c index 7cef5b120b..4d3422f62e 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -365,7 +365,9 @@ static int add(int ac, const char **av, const char *prefix) const char *branch; const char *opt_track = NULL; struct option options[] = { - OPT__FORCE(&opts.force, N_("checkout even if already checked out in other worktree")), + OPT__FORCE(&opts.force, + N_("checkout even if already checked out in other worktree"), + 0), OPT_STRING('b', NULL, &opts.new_branch, N_("branch"), N_("create a new branch")), OPT_STRING('B', NULL, &new_branch_force, N_("branch"), -- cgit v1.3 From c01b56a3a8a375e5473b2548fec55fa408f098e0 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Fri, 9 Feb 2018 18:01:47 +0700 Subject: completion: use __gitcomp_builtin in _git_branch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new completable options are: --all --create-reflog --format= --ignore-case --quiet Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/branch.c | 2 +- contrib/completion/git-completion.bash | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) (limited to 'builtin') diff --git a/builtin/branch.c b/builtin/branch.c index b5b62c08ba..6d0cea9d4b 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -615,7 +615,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) OPT_BOOL('l', "create-reflog", &reflog, N_("create the branch's reflog")), OPT_BOOL(0, "edit-description", &edit_description, N_("edit the description for the branch")), - OPT__FORCE(&force, N_("force creation, move/rename, deletion"), 0), + OPT__FORCE(&force, N_("force creation, move/rename, deletion"), PARSE_OPT_NOCOMPLETE), OPT_MERGED(&filter, N_("print only branches that are merged")), OPT_NO_MERGED(&filter, N_("print only branches that are not merged")), OPT_COLUMN(0, "column", &colopts, N_("list branches in columns")), diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 2fd3fc999e..d926518fb7 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1220,12 +1220,8 @@ _git_branch () __git_complete_refs --cur="${cur##--set-upstream-to=}" ;; --*) - __gitcomp " - --color --no-color --verbose --abbrev= --no-abbrev - --track --no-track --contains --no-contains --merged --no-merged - --set-upstream-to= --edit-description --list - --unset-upstream --delete --move --copy --remotes - --column --no-column --sort= --points-at + __gitcomp_builtin branch "--no-color --no-abbrev + --no-track --no-column " ;; *) -- cgit v1.3 From 77afafb2e3c09323d434c1f8a193a17684b8f109 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Fri, 9 Feb 2018 18:01:48 +0700 Subject: completion: use __gitcomp_builtin in _git_checkout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new completable options are: --ignore-other-worktrees --progress Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/checkout.c | 7 +++++-- contrib/completion/git-completion.bash | 6 +----- t/t9902-completion.sh | 12 +++++++----- 3 files changed, 13 insertions(+), 12 deletions(-) (limited to 'builtin') diff --git a/builtin/checkout.c b/builtin/checkout.c index 2a96358eb7..a6218024a6 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -1118,9 +1118,12 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) 2), OPT_SET_INT('3', "theirs", &opts.writeout_stage, N_("checkout their version for unmerged files"), 3), - OPT__FORCE(&opts.force, N_("force checkout (throw away local modifications)"), 0), + OPT__FORCE(&opts.force, N_("force checkout (throw away local modifications)"), + PARSE_OPT_NOCOMPLETE), OPT_BOOL('m', "merge", &opts.merge, N_("perform a 3-way merge with the new branch")), - OPT_BOOL(0, "overwrite-ignore", &opts.overwrite_ignore, N_("update ignored files (default)")), + OPT_BOOL_F(0, "overwrite-ignore", &opts.overwrite_ignore, + N_("update ignored files (default)"), + PARSE_OPT_NOCOMPLETE), OPT_STRING(0, "conflict", &conflict_style, N_("style"), N_("conflict style (merge or diff3)")), OPT_BOOL('p', "patch", &opts.patch_mode, N_("select hunks interactively")), diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index d926518fb7..7e312f95e9 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1263,11 +1263,7 @@ _git_checkout () __gitcomp "diff3 merge" "" "${cur##--conflict=}" ;; --*) - __gitcomp " - --quiet --ours --theirs --track --no-track --merge - --conflict= --orphan --patch --detach --ignore-skip-worktree-bits - --recurse-submodules --no-recurse-submodules - " + __gitcomp_builtin checkout "--no-track --no-recurse-submodules" ;; *) # check if --track, --no-track, or --no-guess was specified diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index fc614dcbfa..e6485feb0a 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -1237,17 +1237,19 @@ test_expect_success 'double dash "git" itself' ' test_expect_success 'double dash "git checkout"' ' test_completion "git checkout --" <<-\EOF --quiet Z + --detach Z + --track Z + --orphan=Z --ours Z --theirs Z - --track Z - --no-track Z --merge Z - --conflict= - --orphan Z + --conflict=Z --patch Z - --detach Z --ignore-skip-worktree-bits Z + --ignore-other-worktrees Z --recurse-submodules Z + --progress Z + --no-track Z --no-recurse-submodules Z EOF ' -- cgit v1.3 From 26e90958e9f2561d88e01b379f143e5c03f5e764 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Fri, 9 Feb 2018 18:01:50 +0700 Subject: completion: use __gitcomp_builtin in _git_clean MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new completable options are --exclude and --interactive Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/clean.c | 2 +- contrib/completion/git-completion.bash | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'builtin') diff --git a/builtin/clean.c b/builtin/clean.c index 3c4ca9a2ff..fad533a0a7 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -909,7 +909,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix) struct option options[] = { OPT__QUIET(&quiet, N_("do not print names of files removed")), OPT__DRY_RUN(&dry_run, N_("dry run")), - OPT__FORCE(&force, N_("force"), 0), + OPT__FORCE(&force, N_("force"), PARSE_OPT_NOCOMPLETE), OPT_BOOL('i', "interactive", &interactive, N_("interactive cleaning")), OPT_BOOL('d', NULL, &remove_directories, N_("remove whole directories")), diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 068def9f6b..b7de381876 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1307,7 +1307,7 @@ _git_clean () { case "$cur" in --*) - __gitcomp "--dry-run --quiet" + __gitcomp_builtin clean return ;; esac -- cgit v1.3 From 7e1eeaa431047d7f71bcaad53f579a405bca41c8 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Fri, 9 Feb 2018 18:01:58 +0700 Subject: completion: use __gitcomp_builtin in _git_gc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new completable option is --quiet. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/gc.c | 7 +++++-- contrib/completion/git-completion.bash | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'builtin') diff --git a/builtin/gc.c b/builtin/gc.c index 3c5eae0edf..7fc5c16254 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -360,8 +360,11 @@ int cmd_gc(int argc, const char **argv, const char *prefix) N_("prune unreferenced objects"), PARSE_OPT_OPTARG, NULL, (intptr_t)prune_expire }, OPT_BOOL(0, "aggressive", &aggressive, N_("be more thorough (increased runtime)")), - OPT_BOOL(0, "auto", &auto_gc, N_("enable auto-gc mode")), - OPT_BOOL(0, "force", &force, N_("force running gc even if there may be another gc running")), + OPT_BOOL_F(0, "auto", &auto_gc, N_("enable auto-gc mode"), + PARSE_OPT_NOCOMPLETE), + OPT_BOOL_F(0, "force", &force, + N_("force running gc even if there may be another gc running"), + PARSE_OPT_NOCOMPLETE), OPT_END() }; diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 340e2414ff..79e9f69d52 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1509,7 +1509,7 @@ _git_gc () { case "$cur" in --*) - __gitcomp "--prune --aggressive" + __gitcomp_builtin gc return ;; esac -- cgit v1.3 From caf2de33905b74a52a0df26214ee9ab555b32bd9 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Fri, 9 Feb 2018 18:01:59 +0700 Subject: completion: use __gitcomp_builtin in _git_grep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new completable options are: --after-context= --before-context= --color --context --exclude-standard --quiet --recurse-submodules --textconv Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/grep.c | 13 ++++++++----- contrib/completion/git-completion.bash | 16 +--------------- 2 files changed, 9 insertions(+), 20 deletions(-) (limited to 'builtin') diff --git a/builtin/grep.c b/builtin/grep.c index 3ca4ac80d8..496f33336e 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -832,8 +832,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix) OPT_BOOL('L', "files-without-match", &opt.unmatch_name_only, N_("show only the names of files without match")), - OPT_BOOL('z', "null", &opt.null_following_name, - N_("print NUL after filenames")), + OPT_BOOL_F('z', "null", &opt.null_following_name, + N_("print NUL after filenames"), + PARSE_OPT_NOCOMPLETE), OPT_BOOL('c', "count", &opt.count, N_("show the number of matches instead of matching lines")), OPT__COLOR(&opt.color, N_("highlight matches")), @@ -884,9 +885,11 @@ int cmd_grep(int argc, const char **argv, const char *prefix) OPT_GROUP(""), { OPTION_STRING, 'O', "open-files-in-pager", &show_in_pager, N_("pager"), N_("show matching files in the pager"), - PARSE_OPT_OPTARG, NULL, (intptr_t)default_pager }, - OPT_BOOL(0, "ext-grep", &external_grep_allowed__ignored, - N_("allow calling of grep(1) (ignored by this build)")), + PARSE_OPT_OPTARG | PARSE_OPT_NOCOMPLETE, + NULL, (intptr_t)default_pager }, + OPT_BOOL_F(0, "ext-grep", &external_grep_allowed__ignored, + N_("allow calling of grep(1) (ignored by this build)"), + PARSE_OPT_NOCOMPLETE), OPT_END() }; diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 79e9f69d52..60d27253ee 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1565,21 +1565,7 @@ _git_grep () case "$cur" in --*) - __gitcomp " - --cached - --text --ignore-case --word-regexp --invert-match - --full-name --line-number - --extended-regexp --basic-regexp --fixed-strings - --perl-regexp - --threads - --files-with-matches --name-only - --files-without-match - --max-depth - --count - --and --or --not --all-match - --break --heading --show-function --function-context - --untracked --no-index - " + __gitcomp_builtin grep return ;; esac -- cgit v1.3 From cdc71c1c5dabc2da7fd8c5c64dc4a3802720fe74 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Fri, 9 Feb 2018 18:02:03 +0700 Subject: completion: use __gitcomp_builtin in _git_ls_remote MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new completable options are --quiet and --upload-pack=. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/ls-remote.c | 5 +++-- contrib/completion/git-completion.bash | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'builtin') diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c index c4be98ab9e..540d56429f 100644 --- a/builtin/ls-remote.c +++ b/builtin/ls-remote.c @@ -60,8 +60,9 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) OPT_BIT(0, "refs", &flags, N_("do not show peeled tags"), REF_NORMAL), OPT_BOOL(0, "get-url", &get_url, N_("take url..insteadOf into account")), - OPT_SET_INT(0, "exit-code", &status, - N_("exit with exit code 2 if no matching refs are found"), 2), + OPT_SET_INT_F(0, "exit-code", &status, + N_("exit with exit code 2 if no matching refs are found"), + 2, PARSE_OPT_NOCOMPLETE), OPT_BOOL(0, "symref", &show_symref_target, N_("show underlying ref in addition to the object pointed by it")), OPT_END() diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 1ea06b6e17..e22ea60bc8 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1630,7 +1630,7 @@ _git_ls_remote () { case "$cur" in --*) - __gitcomp "--heads --tags --refs --get-url --symref" + __gitcomp_builtin ls-remote return ;; esac -- cgit v1.3 From 61d15cd63cf74bbe746b0c62df5da2784d95f3db Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Fri, 9 Feb 2018 18:02:06 +0700 Subject: completion: use __gitcomp_builtin in _git_mv MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new completable option is --verbose. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/mv.c | 3 ++- contrib/completion/git-completion.bash | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'builtin') diff --git a/builtin/mv.c b/builtin/mv.c index b88023a733..e3e308d282 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -122,7 +122,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix) struct option builtin_mv_options[] = { OPT__VERBOSE(&verbose, N_("be verbose")), OPT__DRY_RUN(&show_only, N_("dry run")), - OPT__FORCE(&force, N_("force move/rename even if target exists"), 0), + OPT__FORCE(&force, N_("force move/rename even if target exists"), + PARSE_OPT_NOCOMPLETE), OPT_BOOL('k', NULL, &ignore_errors, N_("skip move/rename errors")), OPT_END(), }; diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index b192a5c0a1..bbf8623e3a 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1809,7 +1809,7 @@ _git_mv () { case "$cur" in --*) - __gitcomp "--dry-run" + __gitcomp_builtin mv return ;; esac -- cgit v1.3 From 7a60e3bb830a7e07be23316035a095b7ca36ae27 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Fri, 9 Feb 2018 18:02:08 +0700 Subject: completion: use __gitcomp_builtin in _git_notes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new completable options are: --allow-empty (notes add and notes append) --for-rewrite= (notes copy) Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/notes.c | 4 ++-- contrib/completion/git-completion.bash | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'builtin') diff --git a/builtin/notes.c b/builtin/notes.c index b52e71c73e..6990683bd4 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -413,7 +413,7 @@ static int add(int argc, const char **argv, const char *prefix) parse_reuse_arg}, OPT_BOOL(0, "allow-empty", &allow_empty, N_("allow storing empty note")), - OPT__FORCE(&force, N_("replace existing notes"), 0), + OPT__FORCE(&force, N_("replace existing notes"), PARSE_OPT_NOCOMPLETE), OPT_END() }; @@ -484,7 +484,7 @@ static int copy(int argc, const char **argv, const char *prefix) struct notes_tree *t; const char *rewrite_cmd = NULL; struct option options[] = { - OPT__FORCE(&force, N_("replace existing notes"), 0), + OPT__FORCE(&force, N_("replace existing notes"), PARSE_OPT_NOCOMPLETE), OPT_BOOL(0, "stdin", &from_stdin, N_("read objects from stdin")), OPT_STRING(0, "for-rewrite", &rewrite_cmd, N_("command"), N_("load rewriting config for (implies " diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index c7b8b37f19..60127daebf 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1835,7 +1835,7 @@ _git_notes () case "$subcommand,$cur" in ,--*) - __gitcomp '--ref' + __gitcomp_builtin notes ;; ,*) case "$prev" in @@ -1851,15 +1851,17 @@ _git_notes () add,--reedit-message=*|append,--reedit-message=*) __git_complete_refs --cur="${cur#*=}" ;; - add,--*|append,--*) - __gitcomp '--file= --message= --reedit-message= - --reuse-message=' + add,--*) + __gitcomp_builtin notes_add + ;; + append,--*) + __gitcomp_builtin notes_append ;; copy,--*) - __gitcomp '--stdin' + __gitcomp_builtin notes_copy ;; prune,--*) - __gitcomp '--dry-run --verbose' + __gitcomp_builtin notes_prune ;; prune,*) ;; -- cgit v1.3 From f1e1bdd6bd9615b2372a5c682f8a3459a037a27c Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Fri, 9 Feb 2018 18:02:10 +0700 Subject: completion: use __gitcomp_builtin in _git_push MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new completable options are: --atomic --exec= --ipv4 --ipv6 --no-verify --porcelain --progress --push-option --signed Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/push.c | 2 +- contrib/completion/git-completion.bash | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) (limited to 'builtin') diff --git a/builtin/push.c b/builtin/push.c index 1c28427d82..013c20d616 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -548,7 +548,7 @@ int cmd_push(int argc, const char **argv, const char *prefix) { OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules, "check|on-demand|no", N_("control recursive pushing of submodules"), PARSE_OPT_OPTARG, option_parse_recurse_submodules }, - OPT_BOOL( 0 , "thin", &thin, N_("use thin pack")), + OPT_BOOL_F( 0 , "thin", &thin, N_("use thin pack"), PARSE_OPT_NOCOMPLETE), OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", N_("receive pack program")), OPT_STRING( 0 , "exec", &receivepack, "receive-pack", N_("receive pack program")), OPT_BIT('u', "set-upstream", &flags, N_("set upstream for git pull/status"), diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 697fca0c4b..d8d9e8f0de 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1928,12 +1928,7 @@ _git_push () return ;; --*) - __gitcomp " - --all --mirror --tags --dry-run --force --verbose - --quiet --prune --delete --follow-tags - --receive-pack= --repo= --set-upstream - --force-with-lease --force-with-lease= --recurse-submodules= - " + __gitcomp_builtin push return ;; esac -- cgit v1.3 From ebc4a04e8437e704e40a1d35aea030dc03ec8e56 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Fri, 9 Feb 2018 18:02:12 +0700 Subject: remote: force completing --mirror= instead of --mirror MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "git remote --mirror" is a special case. Technically it is possible to specify --mirror without any argument. But we will get a "dangerous, deprecated!" warning in that case. This new parse-opt flag allows --git-completion-helper to always complete --mirror=, ignoring the dangerous use case. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/remote.c | 2 +- parse-options.c | 2 ++ parse-options.h | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) (limited to 'builtin') diff --git a/builtin/remote.c b/builtin/remote.c index d95bf904c3..fce9e5c0f6 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -168,7 +168,7 @@ static int add(int argc, const char **argv) OPT_STRING('m', "master", &master, N_("branch"), N_("master branch")), { OPTION_CALLBACK, 0, "mirror", &mirror, N_("push|fetch"), N_("set up remote as a mirror to push to or fetch from"), - PARSE_OPT_OPTARG, parse_mirror_opt }, + PARSE_OPT_OPTARG | PARSE_OPT_COMP_ARG, parse_mirror_opt }, OPT_END() }; diff --git a/parse-options.c b/parse-options.c index 29f4defdd6..979577ba2c 100644 --- a/parse-options.c +++ b/parse-options.c @@ -459,6 +459,8 @@ static int show_gitcomp(struct parse_opt_ctx_t *ctx, default: break; } + if (opts->flags & PARSE_OPT_COMP_ARG) + suffix = "="; printf(" --%s%s", opts->long_name, suffix); } fputc('\n', stdout); diff --git a/parse-options.h b/parse-options.h index 009cd863e5..0ba08691e6 100644 --- a/parse-options.h +++ b/parse-options.h @@ -39,7 +39,8 @@ enum parse_opt_option_flags { PARSE_OPT_NODASH = 32, PARSE_OPT_LITERAL_ARGHELP = 64, PARSE_OPT_SHELL_EVAL = 256, - PARSE_OPT_NOCOMPLETE = 512 + PARSE_OPT_NOCOMPLETE = 512, + PARSE_OPT_COMP_ARG = 1024 }; struct option; @@ -92,6 +93,9 @@ typedef int parse_opt_ll_cb(struct parse_opt_ctx_t *ctx, * Useful for options with multiple parameters. * PARSE_OPT_NOCOMPLETE: by default all visible options are completable * by git-completion.bash. This option suppresses that. + * PARSE_OPT_COMP_ARG: this option forces to git-completion.bash to + * complete an option as --name= not --name even if + * the option takes optional argument. * * `callback`:: * pointer to the callback to use for OPTION_CALLBACK or -- cgit v1.3 From 1b35475546995edfdb4c56bbbef9a5dac7974ffb Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Fri, 9 Feb 2018 18:02:13 +0700 Subject: completion: use __gitcomp_builtin in _git_replace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new completable option is --raw. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/replace.c | 3 ++- contrib/completion/git-completion.bash | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'builtin') diff --git a/builtin/replace.c b/builtin/replace.c index 10078ae371..0c1d8e1b08 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -439,7 +439,8 @@ int cmd_replace(int argc, const char **argv, const char *prefix) OPT_CMDMODE('d', "delete", &cmdmode, N_("delete replace refs"), MODE_DELETE), OPT_CMDMODE('e', "edit", &cmdmode, N_("edit existing object"), MODE_EDIT), OPT_CMDMODE('g', "graft", &cmdmode, N_("change a commit's parents"), MODE_GRAFT), - OPT_BOOL('f', "force", &force, N_("replace the ref if it exists")), + OPT_BOOL_F('f', "force", &force, N_("replace the ref if it exists"), + PARSE_OPT_NOCOMPLETE), OPT_BOOL(0, "raw", &raw, N_("do not pretty-print contents for --edit")), OPT_STRING(0, "format", &format, N_("format"), N_("use this format")), OPT_END() diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 6e600b7aa3..18c2ccece9 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2661,7 +2661,7 @@ _git_replace () { case "$cur" in --*) - __gitcomp "--edit --graft --format= --list --delete" + __gitcomp_builtin replace return ;; esac -- cgit v1.3 From 44c9a6d2699134d19d5b78503633615fe1bdfa31 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Fri, 9 Feb 2018 18:02:16 +0700 Subject: completion: use __gitcomp_builtin in _git_rm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No new completable options! Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/rm.c | 2 +- contrib/completion/git-completion.bash | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'builtin') diff --git a/builtin/rm.c b/builtin/rm.c index 6e0c7f5ac6..a818efe230 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -242,7 +242,7 @@ static struct option builtin_rm_options[] = { OPT__DRY_RUN(&show_only, N_("dry run")), OPT__QUIET(&quiet, N_("do not list removed files")), OPT_BOOL( 0 , "cached", &index_only, N_("only remove from the index")), - OPT__FORCE(&force, N_("override the up-to-date check"), 0), + OPT__FORCE(&force, N_("override the up-to-date check"), PARSE_OPT_NOCOMPLETE), OPT_BOOL('r', NULL, &recursive, N_("allow recursive removal")), OPT_BOOL( 0 , "ignore-unmatch", &ignore_unmatch, N_("exit with a zero status even if nothing matched")), diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index e63f2f2741..30a51c5015 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2715,7 +2715,7 @@ _git_rm () { case "$cur" in --*) - __gitcomp "--cached --dry-run --ignore-unmatch --quiet" + __gitcomp_builtin rm return ;; esac -- cgit v1.3 From fc3d4e0cbe65639509c765726fe01a16575e9ae8 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Fri, 9 Feb 2018 18:02:20 +0700 Subject: completion: use __gitcomp_builtin in _git_worktree MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new completable options for "worktree add" are: --checkout --guess-remote --lock --track Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/worktree.c | 2 +- contrib/completion/git-completion.bash | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'builtin') diff --git a/builtin/worktree.c b/builtin/worktree.c index 4d3422f62e..76dc6b8cb5 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -367,7 +367,7 @@ static int add(int ac, const char **av, const char *prefix) struct option options[] = { OPT__FORCE(&opts.force, N_("checkout even if already checked out in other worktree"), - 0), + PARSE_OPT_NOCOMPLETE), OPT_STRING('b', NULL, &opts.new_branch, N_("branch"), N_("create a new branch")), OPT_STRING('B', NULL, &new_branch_force, N_("branch"), diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index e76b2f0356..0ddf40063b 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -3021,16 +3021,16 @@ _git_worktree () else case "$subcommand,$cur" in add,--*) - __gitcomp "--detach" + __gitcomp_builtin worktree_add ;; list,--*) - __gitcomp "--porcelain" + __gitcomp_builtin worktree_list ;; lock,--*) - __gitcomp "--reason" + __gitcomp_builtin worktree_lock ;; prune,--*) - __gitcomp "--dry-run --expire --verbose" + __gitcomp_builtin worktree_prune ;; *) ;; -- cgit v1.3