Skip to content

Commit

Permalink
add usage-strings ci check and amend remaining usage strings
Browse files Browse the repository at this point in the history
Usage strings for git (sub)command flags has a style guide that
suggests - first letter should not capitalized (unless requied)
and it should skip full-stop at the end of line. But there are
some files where usage-strings do not follow the above mentioned
guide. Moreover, there are no checks to verify if all usage strings
are following the guide/convention or not.

Amend the usage strings that don't follow the convention/guide and
add a `CI` check for checking the usage strings (whether the first
letter is capital or it ends with full-stop). If the `check` find
such strings then print those strings and return a non-zero status.

Also provide a script that takes an optional argument (a valid <tree>
string), to check the usage strings in the given <tree> (`HEAD` is
the default argument).

Signed-off-by: Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>
  • Loading branch information
Abhra303 committed Feb 16, 2022
1 parent b801210 commit 573d95e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 6 deletions.
5 changes: 5 additions & 0 deletions Makefile
Expand Up @@ -3416,6 +3416,11 @@ check-docs::
check-builtins::
./check-builtins.sh

### Make sure all the usage strings follow usage string style guide
#
check-usage-strings::
./check-usage-strings.sh

### Test suite coverage testing
#
.PHONY: coverage coverage-clean coverage-compile coverage-test coverage-report
Expand Down
2 changes: 1 addition & 1 deletion builtin/bisect--helper.c
Expand Up @@ -1209,7 +1209,7 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
OPT_CMDMODE(0, "bisect-visualize", &cmdmode,
N_("visualize the bisection"), BISECT_VISUALIZE),
OPT_CMDMODE(0, "bisect-run", &cmdmode,
N_("use <cmd>... to automatically bisect."), BISECT_RUN),
N_("use <cmd>... to automatically bisect"), BISECT_RUN),
OPT_BOOL(0, "no-log", &nolog,
N_("no log for BISECT_WRITE")),
OPT_END()
Expand Down
2 changes: 1 addition & 1 deletion builtin/submodule--helper.c
Expand Up @@ -1874,7 +1874,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
OPT_STRING(0, "depth", &clone_data.depth,
N_("string"),
N_("depth for shallow clones")),
OPT__QUIET(&quiet, "Suppress output for cloning a submodule"),
OPT__QUIET(&quiet, "suppress output for cloning a submodule"),
OPT_BOOL(0, "progress", &progress,
N_("force cloning progress")),
OPT_BOOL(0, "require-init", &require_init,
Expand Down
33 changes: 33 additions & 0 deletions check-usage-strings.sh
@@ -0,0 +1,33 @@
{
if test -d ".git"
then
rev=${1:-"HEAD"}
for entry in $(git grep -l 'struct option .* = {$' "$rev" -- \*.c);
do
git show "$entry" |
sed -n '/struct option .* = {/,/OPT_END/{=;p;}' |
sed "N;s/^\\([0-9]*\\)\\n/$(echo "$entry" | sed 's/\//\\&/g'):\\1/";
done
else
for entry in $(grep -rl --include="*.c" 'struct option .* = {$' . );
do
cat "$entry" |
sed -n '/struct option .* = {/,/OPT_END/{=;p;}' |
sed "N;s/^\\([0-9]*\\)\\n/$(echo "$entry" | sed -e 's/\//\\&/g' -e 's/^\.\\\///'):\\1/";
done
fi
} |
grep -Pe '((?<!OPT_GROUP\(N_\(|OPT_GROUP\()"(?!GPG|DEPRECATED|SHA1|HEAD)[A-Z]|(?<!"|\.\.)\.")' |
{
status=0
while read content;
do
if test -n "$content"
then
echo "$content";
status=1;
fi
done

exit $status
}
1 change: 1 addition & 0 deletions ci/test-documentation.sh
Expand Up @@ -15,6 +15,7 @@ filter_log () {
}

make check-builtins
make check-usage-strings
make check-docs

# Build docs with AsciiDoc
Expand Down
2 changes: 1 addition & 1 deletion diff.c
Expand Up @@ -5596,7 +5596,7 @@ static void prep_parse_options(struct diff_options *options)
N_("select files by diff type"),
PARSE_OPT_NONEG, diff_opt_diff_filter),
{ OPTION_CALLBACK, 0, "output", options, N_("<file>"),
N_("Output to a specific file"),
N_("output to a specific file"),
PARSE_OPT_NONEG, NULL, 0, diff_opt_output },

OPT_END()
Expand Down
6 changes: 3 additions & 3 deletions t/helper/test-run-command.c
Expand Up @@ -221,9 +221,9 @@ static int quote_stress_test(int argc, const char **argv)
struct strbuf out = STRBUF_INIT;
struct strvec args = STRVEC_INIT;
struct option options[] = {
OPT_INTEGER('n', "trials", &trials, "Number of trials"),
OPT_INTEGER('s', "skip", &skip, "Skip <n> trials"),
OPT_BOOL('m', "msys2", &msys2, "Test quoting for MSYS2's sh"),
OPT_INTEGER('n', "trials", &trials, "number of trials"),
OPT_INTEGER('s', "skip", &skip, "skip <n> trials"),
OPT_BOOL('m', "msys2", &msys2, "test quoting for MSYS2's sh"),
OPT_END()
};
const char * const usage[] = {
Expand Down

0 comments on commit 573d95e

Please sign in to comment.