Message ID | 6a4d6a56-ab6f-4557-a5a3-1713f57cbfc9@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | allow disabling the automatic hint in advise_if_enabled() | expand |
Rubén Justo <rjusto@gmail.com> writes: > Soon we're going to need to pass configuration values to a command in > test-tool. > > Let's teach test-tool to take config values via command line arguments. > > Signed-off-by: Rubén Justo <rjusto@gmail.com> > --- > t/helper/test-tool.c | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) Nice. > > diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c > index d9f57c20db..7eba4ec9ab 100644 > --- a/t/helper/test-tool.c > +++ b/t/helper/test-tool.c > @@ -3,9 +3,10 @@ > #include "test-tool-utils.h" > #include "trace2.h" > #include "parse-options.h" > +#include "config.h" > > static const char * const test_tool_usage[] = { > - "test-tool [-C <directory>] <command> [<arguments>...]]", > + "test-tool [-C <directory>] [-c <name>=<value>] <command> [<arguments>...]", > NULL > }; > > @@ -106,6 +107,13 @@ static NORETURN void die_usage(void) > exit(128); > } > > +static int parse_config_option(const struct option *opt, const char *arg, > + int unset) > +{ > + git_config_push_parameter(arg); > + return 0; > +} > + > int cmd_main(int argc, const char **argv) > { > int i; > @@ -113,6 +121,9 @@ int cmd_main(int argc, const char **argv) > struct option options[] = { > OPT_STRING('C', NULL, &working_directory, "directory", > "change the working directory"), > + OPT_CALLBACK('c', NULL, NULL, "<name>=<value>", > + "pass a configuration parameter to the command", > + parse_config_option), > OPT_END() > };
On Tue, Jan 09, 2024 at 04:29:57PM +0100, Rubén Justo wrote: > Soon we're going to need to pass configuration values to a command in > test-tool. > > Let's teach test-tool to take config values via command line arguments. I wasn't expecting a step like this to appear in this series. I don't have strong feelings about it, especially since test-tool helpers already understand $GIT_DIR/config when they rely on library code which implicitly reads configuration. But it does seem odd to have test-tool invocations that intimately depend on a particular set of configuration values. At the very least, this step seems to encourage passing finely tuned configuration values to test-tool helpers, which I am not sure is a good idea. Your patch message suggests that this will be useful in the following patch, which makes sense. But I wonder if it would be easier to avoid the test-tool entirely and call some Git command in a state that we expect to generate advice. Then we can test its output with various values of advice.adviceOff. > Signed-off-by: Rubén Justo <rjusto@gmail.com> > --- > t/helper/test-tool.c | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) The patch itself looks reasonable, though. Thanks, Taylor
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c index d9f57c20db..7eba4ec9ab 100644 --- a/t/helper/test-tool.c +++ b/t/helper/test-tool.c @@ -3,9 +3,10 @@ #include "test-tool-utils.h" #include "trace2.h" #include "parse-options.h" +#include "config.h" static const char * const test_tool_usage[] = { - "test-tool [-C <directory>] <command> [<arguments>...]]", + "test-tool [-C <directory>] [-c <name>=<value>] <command> [<arguments>...]", NULL }; @@ -106,6 +107,13 @@ static NORETURN void die_usage(void) exit(128); } +static int parse_config_option(const struct option *opt, const char *arg, + int unset) +{ + git_config_push_parameter(arg); + return 0; +} + int cmd_main(int argc, const char **argv) { int i; @@ -113,6 +121,9 @@ int cmd_main(int argc, const char **argv) struct option options[] = { OPT_STRING('C', NULL, &working_directory, "directory", "change the working directory"), + OPT_CALLBACK('c', NULL, NULL, "<name>=<value>", + "pass a configuration parameter to the command", + parse_config_option), OPT_END() };
Soon we're going to need to pass configuration values to a command in test-tool. Let's teach test-tool to take config values via command line arguments. Signed-off-by: Rubén Justo <rjusto@gmail.com> --- t/helper/test-tool.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)