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

Re: [PATCH 2/2] advice: add "all" option to disable all hints

From
Patrick Steinhardt <ps@pks.im>
Date
Apr 24, 2024, 05:29 UTC
Message-ID
<ZiiYoOKJpqq4XWq-@tanuki>
In-Reply-To
<20240424035857.84583-3-james@jamesliu.io>

On Wed, Apr 24, 2024 at 01:58:57PM +1000, James Liu wrote: [snip]

Show 20 quoted lines
> --- a/advice.c
> +++ b/advice.c
> @@ -43,6 +43,7 @@ static struct {
>  	const char *key;
>  	enum advice_level level;
>  } advice_setting[] = {
> +	[ADVICE_ALL]					= { "all" },
>  	[ADVICE_ADD_EMBEDDED_REPO]			= { "addEmbeddedRepo" },
>  	[ADVICE_ADD_EMPTY_PATHSPEC]			= { "addEmptyPathspec" },
>  	[ADVICE_ADD_IGNORED_FILE]			= { "addIgnoredFile" },
> @@ -132,6 +133,13 @@ int advice_enabled(enum advice_type type)
>  		return enabled &&
>  		       advice_enabled(ADVICE_PUSH_UPDATE_REJECTED_ALIAS);
>  
> +	/*
> +	 * We still allow for specific advice hints to be enabled if
> +	 * advice.all == false.
> +	 */
> +	if (advice_setting[ADVICE_ALL].level == ADVICE_LEVEL_DISABLED)
> +		return advice_setting[type].level == ADVICE_LEVEL_ENABLED;

Makes sense. When the advice is unset we don't need to handle it at all, and if it is enabled we basically want to behave the same as before.

Show 56 quoted lines
>  	return enabled;
>  }
>  
> diff --git a/advice.h b/advice.h
> index c8d29f97f3..b5ac99a645 100644
> --- a/advice.h
> +++ b/advice.h
> @@ -11,6 +11,7 @@ struct string_list;
>   * Call advise_if_enabled to print your advice.
>   */
>  enum advice_type {
> +	ADVICE_ALL,
>  	ADVICE_ADD_EMBEDDED_REPO,
>  	ADVICE_ADD_EMPTY_PATHSPEC,
>  	ADVICE_ADD_IGNORED_FILE,
> diff --git a/t/t0018-advice.sh b/t/t0018-advice.sh
> index 8010796e1f..19318cc9bb 100755
> --- a/t/t0018-advice.sh
> +++ b/t/t0018-advice.sh
> @@ -53,4 +53,37 @@ test_expect_success 'advice should be printed when advice.pushUpdateRejected is
>  	test_cmp expect actual
>  '
>  
> +test_expect_success 'advice should not be printed when advice.all is set to false' '
> +	test_config advice.all false &&
> +	test-tool advise nestedTag "This is a piece of advice" 2>actual &&
> +	test_must_be_empty actual
> +'
> +
> +test_expect_success 'advice should not be printed for pushUpdateRejected when advice.all is set to false' '
> +	test_config advice.all false &&
> +	test-tool advise pushUpdateRejected "This is a piece of advice" 2>actual &&
> +	test_must_be_empty actual
> +'
> +
> +test_expect_success 'advice should be printed when advice.all is set to false, but specific advice is set to true' '
> +	cat >expect <<-\EOF &&
> +	hint: This is a piece of advice
> +	EOF
> +	test_config advice.all false &&
> +	test_config advice.nestedTag true &&
> +	test-tool advise nestedTag "This is a piece of advice" 2>actual &&
> +	test_cmp expect actual
> +'
> +
> +test_expect_success 'advice should be printed when advice.all is set to false, but advice.pushUpdateRejected and its alias are set to true' '
> +	cat >expect <<-\EOF &&
> +	hint: This is a piece of advice
> +	EOF
> +	test_config advice.all false &&
> +	test_config advice.pushUpdateRejected true &&
> +	test_config advice.pushNonFastForward true &&
> +	test-tool advise pushUpdateRejected "This is a piece of advice" 2>actual &&
> +	test_cmp expect actual
> +'
>  test_done

Do we actually have to enable both advices here? If not, then this should probably be two separate tests that check whether each of the keys does its thing.

Patrick
Previous: James LiuNext: Junio C Hamano
Message 5 of 67 in “advice: add "all" option to disable all hints”
  1. 0/2 advice: add "all" option to disable all hintsJames Liu, Apr 24, 2024
  2. 1/2 advice: allow advice type to be provided in testsJames Liu, Apr 24, 2024
  3. Patrick SteinhardtApr 24, 2024
  4. 2/2 advice: add "all" option to disable all hintsJames Liu, Apr 24, 2024
  5. Patrick SteinhardtApr 24, 2024
  6. Junio C HamanoApr 24, 2024
  7. Patrick SteinhardtApr 24, 2024
  8. Phillip WoodApr 24, 2024
  9. Patrick SteinhardtApr 24, 2024
  10. Junio C HamanoApr 24, 2024
  11. Patrick SteinhardtApr 25, 2024
  12. Junio C HamanoApr 25, 2024
  13. Dragan SimicApr 24, 2024
  14. Dragan SimicApr 24, 2024
  15. Junio C HamanoApr 24, 2024
  16. Patrick SteinhardtApr 25, 2024
  17. Dragan SimicApr 24, 2024
  18. 0/1 advice: add --no-advice global optionJames Liu, Apr 29, 2024
  19. 1/1 advice: add --no-advice global optionJames Liu, Apr 29, 2024
  20. Dragan SimicApr 29, 2024
  21. James LiuApr 29, 2024
  22. Dragan SimicApr 29, 2024
  23. Dragan SimicApr 29, 2024
  24. Eric SunshineApr 29, 2024
  25. Dragan SimicApr 29, 2024
  26. Jeff KingApr 29, 2024
  27. Dragan SimicApr 29, 2024
  28. Junio C HamanoApr 29, 2024
  29. James LiuApr 30, 2024
  30. Junio C HamanoApr 29, 2024
  31. Rubén JustoApr 29, 2024
  32. Dragan SimicApr 29, 2024
  33. 0/1 advice: add --no-advice global optionJames Liu, Apr 30, 2024
  34. 1/1 advice: add --no-advice global optionJames Liu, Apr 30, 2024
  35. Patrick SteinhardtApr 30, 2024
  36. Dragan SimicApr 30, 2024
  37. Junio C HamanoApr 30, 2024
  38. 0/3 advice: add "all" option to disable all hintsJames Liu, May 3, 2024
  39. 1/3 doc: clean up usage documentation for --no-* optsJames Liu, May 3, 2024
  40. Junio C HamanoMay 3, 2024
  41. James LiuMay 6, 2024
  42. 2/3 doc: add spacing around paginate optionsJames Liu, May 3, 2024
  43. Karthik NayakMay 3, 2024
  44. Junio C HamanoMay 3, 2024
  45. 3/3 advice: add --no-advice global optionJames Liu, May 3, 2024
  46. 4/3 t0018: two small fixesJunio C Hamano, May 8, 2024
  47. Dragan SimicMay 3, 2024
  48. Re* [PATCH v4 0/3] advice: add "all" option to disable all hintsJunio C Hamano, May 3, 2024
  49. Eric SunshineMay 3, 2024
  50. Junio C HamanoMay 3, 2024
  51. Junio C HamanoMay 3, 2024
  52. Eric SunshineMay 3, 2024
  53. Johannes SchindelinMay 5, 2024
  54. Re* Re* [PATCH v4 0/3] advice: add "all" option to disable all hintsJunio C Hamano, May 6, 2024
  55. Dragan SimicMay 7, 2024
  56. Junio C HamanoMay 7, 2024
  57. Dragan SimicMay 7, 2024
  58. Dragan SimicMay 7, 2024
  59. Karthik NayakMay 3, 2024
  60. James LiuMay 5, 2024
  61. Junio C HamanoMay 3, 2024
  62. James LiuMay 5, 2024
  63. James LiuMay 6, 2024
  64. Junio C HamanoMay 6, 2024
  65. James LiuMay 6, 2024
  66. Karthik NayakMay 7, 2024
  67. Junio C HamanoMay 6, 2024

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.