case PARSE_OPT_UNKNOWN:
break;
case PARSE_OPT_HELP:
+ exit(0);
case PARSE_OPT_HELP_ERROR:
case PARSE_OPT_ERROR:
case PARSE_OPT_SUBCOMMAND:
case PARSE_OPT_UNKNOWN:
break;
case PARSE_OPT_HELP:
+ exit(0);
case PARSE_OPT_HELP_ERROR:
case PARSE_OPT_ERROR:
case PARSE_OPT_SUBCOMMAND:
break;
switch (parseopt_state) {
case PARSE_OPT_HELP:
+ exit(0);
case PARSE_OPT_HELP_ERROR:
case PARSE_OPT_ERROR:
exit(129);
}
test_expect_success 'shows short help text for -h' '
- test_expect_code 129 git subtree -h >out 2>err &&
+ git subtree -h >out 2>err &&
test_must_be_empty err &&
grep -e "^ *or: git subtree pull" out &&
grep -F -e "--[no-]annotate" out
case PARSE_OPT_UNKNOWN:
goto unknown;
case PARSE_OPT_HELP:
- case PARSE_OPT_HELP_ERROR:
goto show_usage;
+ case PARSE_OPT_HELP_ERROR:
+ goto show_usage_stderr;
case PARSE_OPT_NON_OPTION:
case PARSE_OPT_SUBCOMMAND:
case PARSE_OPT_COMPLETE:
show_usage:
return usage_with_options_internal(ctx, usagestr, options,
USAGE_NORMAL, USAGE_TO_STDOUT);
+ show_usage_stderr:
+ return usage_with_options_internal(ctx, usagestr, options,
+ USAGE_NORMAL, USAGE_TO_STDERR);
}
int parse_options_end(struct parse_opt_ctx_t *ctx)
parse_options_start_1(&ctx, argc, argv, prefix, options, flags);
switch (parse_options_step(&ctx, options, usagestr)) {
case PARSE_OPT_HELP:
+ exit(0);
case PARSE_OPT_HELP_ERROR:
case PARSE_OPT_ERROR:
exit(129);
if (!strcmp(av[1], "-h")) {
usage_with_options_internal(NULL, usagestr, opts,
USAGE_NORMAL, USAGE_TO_STDOUT);
- exit(129);
+ exit(0);
} else if (!strcmp(av[1], "--help-all")) {
usage_with_options_internal(NULL, usagestr, opts,
USAGE_FULL, USAGE_TO_STDOUT);
- exit(129);
+ exit(0);
}
}
}
'
test_expect_success 'Give help even with invalid sort atoms' '
- test_expect_code 129 ${git_for_each_ref} --sort=bogus -h >actual 2>&1 &&
+ ${git_for_each_ref} --sort=bogus -h >actual 2>&1 &&
grep "^usage: ${git_for_each_ref}" actual
'
(
GIT_CEILING_DIRECTORIES=$(pwd) &&
export GIT_CEILING_DIRECTORIES &&
- test_expect_code 129 git -C sub $builtin -h >output 2>err
+ git -C sub $builtin -h >output 2>err
) &&
test_must_be_empty err &&
test_grep usage output
EOF
test_expect_success 'test help' '
- test_must_fail test-tool parse-options -h >output 2>output.err &&
+ test-tool parse-options -h >output 2>output.err &&
test_must_be_empty output.err &&
test_cmp expect output
'
return 0
fi &&
mkdir -p "$out_dir" &&
- test_expect_code 129 git $builtin -h >"$out.raw" 2>&1 &&
+ test_might_fail git $builtin -h >"$out.raw" 2>&1 &&
sed -n \
-e '1,/^$/ {
/^$/d;
INVALID_OID=$(test_oid 001)
test_expect_success 'pack-refs does not crash with -h' '
- test_expect_code 129 git pack-refs -h >usage &&
+ git pack-refs -h >usage &&
test_grep "[Uu]sage: git pack-refs " usage &&
- test_expect_code 129 nongit git pack-refs -h >usage &&
+ nongit git pack-refs -h >usage &&
test_grep "[Uu]sage: git pack-refs " usage
'
'
test_expect_success 'show-ref --heads is deprecated and hidden' '
- test_expect_code 129 git show-ref -h >short-help &&
+ git show-ref -h >short-help &&
test_grep ! -e --heads short-help &&
git show-ref --heads >actual 2>warning &&
test_grep ! deprecated warning &&
'
test_expect_success 'correct usage on sub-command -h' '
- test_expect_code 129 git reflog expire -h >err &&
+ git reflog expire -h >err &&
grep "git reflog expire" err
'
test_expect_success 'correct usage on "git reflog show -h"' '
- test_expect_code 129 git reflog show -h >err &&
+ git reflog show -h >err &&
grep -F "git reflog [show]" err
'
test_expect_success 'usage' '
test_expect_code 129 git reflog exists &&
- test_expect_code 129 git reflog exists -h
+ git reflog exists -h
'
test_expect_success 'usage: unknown option' '
'
test_expect_success 'test --parseopt help output' '
- test_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec &&
+ git rev-parse --parseopt -- -h > output < optionspec &&
test_cmp "$TEST_DIRECTORY/t1502/optionspec.help" output
'
|EOF
|exit 0
END_EXPECT
- test_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec_no_switches &&
+ git rev-parse --parseopt -- -h > output < optionspec_no_switches &&
test_cmp expect output
'
|EOF
|exit 0
END_EXPECT
- test_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec_only_hidden_switches &&
+ git rev-parse --parseopt -- -h > output < optionspec_only_hidden_switches &&
test_cmp expect output
'
|EOF
|exit 0
END_EXPECT
- test_expect_code 129 git rev-parse --parseopt -- --help-all > output < optionspec_only_hidden_switches &&
+ git rev-parse --parseopt -- --help-all > output < optionspec_only_hidden_switches &&
test_cmp expect output
'
|exit 0
END_EXPECT
- test_must_fail git rev-parse --parseopt -- -h <spec >actual &&
+ git rev-parse --parseopt -- -h <spec >actual &&
test_cmp expect actual
'
|exit 0
END_EXPECT
- test_must_fail git rev-parse --parseopt -- -h <spec >actual &&
+ git rev-parse --parseopt -- -h <spec >actual &&
test_cmp expect actual
'
test_expect_success 'test --parseopt help output for optionspec-neg' '
- test_expect_code 129 git rev-parse --parseopt -- \
+ git rev-parse --parseopt -- \
-h >output <"$TEST_DIRECTORY/t1502/optionspec-neg" &&
test_cmp "$TEST_DIRECTORY/t1502/optionspec-neg.help" output
'
archimport | citool | credential-netrc | credential-libsecret | \
credential-osxkeychain | cvsexportcommit | cvsimport | cvsserver | \
daemon | \
- difftool--helper | filter-branch | format-rev | fsck-objects | \
- get-tar-commit-id | \
+ difftool--helper | format-rev | fsck-objects | get-tar-commit-id | \
gui | gui--askpass | \
- http-backend | http-fetch | http-push | init-db | instaweb | \
- merge-octopus | merge-one-file | merge-resolve | mergetool | \
- mktag | p4 | p4.py | pickaxe | quiltimport | remote-ftp | remote-ftps | \
- remote-http | remote-https | replay | request-pull | send-email | \
- sh-i18n--envsubst | shell | show | stage | submodule | svn | \
- upload-archive--writer | upload-pack | web--browse | whatchanged)
- expect_outcome=expect_failure ;;
+ http-backend | http-fetch | http-push | init-db | \
+ mktag | p4 | p4.py | pickaxe | remote-ftp | remote-ftps | \
+ remote-http | remote-https | replay | send-email | \
+ sh-i18n--envsubst | shell | show | stage | \
+ upload-archive--writer | upload-pack | whatchanged)
+ h_expect_outcome=expect_failure
+ all_expect_outcome=expect_failure
+ ;;
+ filter-branch | merge-octopus | merge-one-file | merge-resolve | \
+ mergetool | submodule | svn | web--browse)
+ h_expect_outcome=expect_success
+ all_expect_outcome=expect_failure
+ ;;
*)
- expect_outcome=expect_success ;;
+ h_expect_outcome=expect_success
+ all_expect_outcome=expect_success
+ ;;
esac
case "$cmd" in
instaweb)
*)
prereq= ;;
esac
- test_$expect_outcome $prereq "'git $cmd -h' outside a repository" '
- test_expect_code 129 nongit git $cmd -h >usage &&
+ test_$h_expect_outcome $prereq "'git $cmd -h' outside a repository" '
+ nongit git $cmd -h >usage &&
test_grep "[Uu]sage: git $cmd " usage
'
- test_$expect_outcome $prereq "'git $cmd --help-all' outside a repository" '
- test_expect_code 129 nongit git $cmd --help-all >usage &&
+ test_$all_expect_outcome $prereq "'git $cmd --help-all' outside a repository" '
+ nongit git $cmd --help-all >usage &&
test_grep "[Uu]sage: git $cmd " usage
'
done
test_expect_success 'fmt-merge-msg does not crash with -h' '
- test_expect_code 129 git fmt-merge-msg -h >usage &&
+ git fmt-merge-msg -h >usage &&
test_grep "[Uu]sage: git fmt-merge-msg " usage &&
- test_expect_code 129 nongit git fmt-merge-msg -h >usage &&
+ nongit git fmt-merge-msg -h >usage &&
test_grep "[Uu]sage: git fmt-merge-msg " usage
'
test_expect_success 'git hook usage' '
test_expect_code 129 git hook &&
test_expect_code 129 git hook run &&
- test_expect_code 129 git hook run -h &&
+ git hook run -h &&
test_expect_code 129 git hook run --unknown 2>err &&
test_expect_code 129 git hook list &&
- test_expect_code 129 git hook list -h &&
+ git hook list -h &&
grep "unknown option" err
'
'
test_expect_success 'git repo info -h shows only repo info usage' '
- test_must_fail git repo info -h >actual &&
+ git repo info -h >actual &&
test_grep "git repo info" actual &&
test_grep ! "git repo structure" actual
'
'
test_expect_success 'git repo structure -h shows only repo structure usage' '
- test_must_fail git repo structure -h >actual &&
+ git repo structure -h >actual &&
test_grep "git repo structure" actual &&
test_grep ! "git repo info" actual
'
cd broken &&
git init &&
>.git/index &&
- test_expect_code 129 git checkout-index -h >usage 2>&1
+ git checkout-index -h >usage 2>&1
) &&
test_grep "[Uu]sage" broken/usage
'
test_expect_success 'checkout-index does not crash with -h' '
- test_expect_code 129 git checkout-index -h >usage &&
+ git checkout-index -h >usage &&
test_grep "[Uu]sage: git checkout-index " usage &&
- test_expect_code 129 nongit git checkout-index -h >usage &&
+ nongit git checkout-index -h >usage &&
test_grep "[Uu]sage: git checkout-index " usage
'
cd broken &&
git init &&
>.git/index &&
- test_expect_code 129 git update-index -h >usage 2>&1
+ git update-index -h >usage 2>&1
) &&
test_grep "[Uu]sage: git update-index" broken/usage
'
cd broken &&
git init &&
>.git/index &&
- test_expect_code 129 git ls-files -h >usage 2>&1
+ git ls-files -h >usage 2>&1
) &&
test_grep "[Uu]sage: git ls-files " broken/usage
'
test_expect_success 'ls-files does not crash with -h' '
- test_expect_code 129 git ls-files -h >usage &&
+ git ls-files -h >usage &&
test_grep "[Uu]sage: git ls-files " usage &&
- test_expect_code 129 nongit git ls-files -h >usage &&
+ nongit git ls-files -h >usage &&
test_grep "[Uu]sage: git ls-files " usage
'
cd broken &&
git init -b main &&
>.git/refs/heads/main &&
- test_expect_code 129 git branch -h >usage 2>&1
+ git branch -h >usage 2>&1
) &&
test_grep "[Uu]sage" broken/usage
'
'
test_expect_success 'usage on main command -h emits a summary of subcommands' '
- test_expect_code 129 git stash -h >usage &&
+ git stash -h >usage &&
grep -F "usage: git stash list" usage &&
grep -F "or: git stash show" usage
'
test_expect_success 'usage for subcommands should emit subcommand usage' '
- test_expect_code 129 git stash push -h >usage &&
+ git stash push -h >usage &&
grep -F "usage: git stash [push" usage
'
'
test_expect_success 'rerere -h' '
- test_must_fail git rerere -h >help &&
+ git rerere -h >help &&
test_grep [Uu]sage help
'
'
test_expect_success 'update-server-info does not crash with -h' '
- test_expect_code 129 git update-server-info -h >usage &&
+ git update-server-info -h >usage &&
test_grep "[Uu]sage: git update-server-info " usage
'
'
test_expect_success 'prune does not crash with -h' '
- test_expect_code 129 git prune -h >usage &&
+ git prune -h >usage &&
test_grep "[Uu]sage: git prune " usage
'
git log'
test_expect_success 'send-pack does not crash with -h' '
- test_expect_code 129 git send-pack -h >usage &&
+ git send-pack -h >usage &&
test_grep "[Uu]sage: git send-pack " usage &&
- test_expect_code 129 nongit git send-pack -h >usage &&
+ nongit git send-pack -h >usage &&
test_grep "[Uu]sage: git send-pack " usage
'
'
test_expect_success 'ls-remote --heads is deprecated and hidden w/o warning' '
- test_expect_code 129 git ls-remote -h >short-help &&
+ git ls-remote -h >short-help &&
test_grep ! -e --head short-help &&
git ls-remote --heads self >actual 2>warning &&
test_cmp expected.branches actual &&
. ./test-lib.sh
test_expect_success "for-each-ref does not crash with -h" '
- test_expect_code 129 git for-each-ref -h >usage &&
+ git for-each-ref -h >usage &&
test_grep "[Uu]sage: git for-each-ref " usage &&
- test_expect_code 129 nongit git for-each-ref -h >usage &&
+ nongit git for-each-ref -h >usage &&
test_grep "[Uu]sage: git for-each-ref " usage
'
cd broken &&
git init &&
echo "[gc] pruneexpire = CORRUPT" >>.git/config &&
- test_expect_code 129 git gc -h >usage 2>&1
+ git gc -h >usage 2>&1
) &&
test_grep "[Uu]sage" broken/usage
'
. "$TEST_DIRECTORY/lib-gpg.sh"
test_expect_success GPG 'verify-tag does not crash with -h' '
- test_expect_code 129 git verify-tag -h >usage &&
+ git verify-tag -h >usage &&
test_grep "[Uu]sage: git verify-tag " usage &&
- test_expect_code 129 nongit git verify-tag -h >usage &&
+ nongit git verify-tag -h >usage &&
test_grep "[Uu]sage: git verify-tag " usage
'
cd broken &&
git init &&
echo "[status] showuntrackedfiles = CORRUPT" >>.git/config &&
- test_expect_code 129 git status -h >usage 2>&1
+ git status -h >usage 2>&1
) &&
test_grep "[Uu]sage" broken/usage
'
cd broken &&
git init &&
echo "[status] showuntrackedfiles = CORRUPT" >>.git/config &&
- test_expect_code 129 git commit -h >usage 2>&1
+ git commit -h >usage 2>&1
) &&
test_grep "[Uu]sage" broken/usage
'
. "$TEST_DIRECTORY/lib-gpg.sh"
test_expect_success GPG 'verify-commit does not crash with -h' '
- test_expect_code 129 git verify-commit -h >usage &&
+ git verify-commit -h >usage &&
test_grep "[Uu]sage: git verify-commit " usage &&
- test_expect_code 129 nongit git verify-commit -h >usage &&
+ nongit git verify-commit -h >usage &&
test_grep "[Uu]sage: git verify-commit " usage
'
cd broken &&
git init &&
>.git/index &&
- test_expect_code 129 git merge -h >usage
+ git merge -h >usage
) &&
test_grep "[Uu]sage: git merge" broken/usage
'
}
test_expect_success 'basic usage requires no repo' '
- test_expect_code 129 git difftool -h >output &&
+ git difftool -h >output &&
test_grep ^usage: output &&
# create a ceiling directory to prevent Git from finding a repo
mkdir -p not/repo &&
test_when_finished rm -r not &&
- test_expect_code 129 \
env GIT_CEILING_DIRECTORIES="$(pwd)/not" \
git -C not/repo difftool -h >output &&
test_grep ^usage: output
}
test_expect_success 'help text' '
- test_expect_code 129 git maintenance -h >actual &&
+ git maintenance -h >actual &&
test_grep "usage: git maintenance <subcommand>" actual &&
test_expect_code 129 git maintenance barf 2>err &&
test_grep "unknown subcommand: \`barf'\''" err &&
va_start(params, err);
vfreportf(stdout, _("usage: "), err, params);
va_end(params);
- exit(129);
+ exit(0);
}
void show_usage_if_asked(int ac, const char **av, const char *err)