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

[PATCH v3 00/12] builtin/show-ref: introduce mode to check for ref existence

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 31, 2023, 08:16 UTC
Message-ID
<cover.1698739941.git.ps@pks.im>
In-Reply-To
<cover.1698152926.git.ps@pks.im>
Hi,

this is the third version of my patch series that introduces a new `git show-ref --exists` mode to check for reference existence.

Changes compared to v2:
    - Patch 5: Document why we need `exclude_existing_options.enabled`,
      which isn't exactly obvious.
    - Patch 6: Fix a grammar issue in the commit message.
    - Patch 9: Switch to `test_cmp` instead of grep(1).
Thanks!
Patrick
Patrick Steinhardt (12):
  builtin/show-ref: convert pattern to a local variable
  builtin/show-ref: split up different subcommands
  builtin/show-ref: fix leaking string buffer
  builtin/show-ref: fix dead code when passing patterns
  builtin/show-ref: refactor `--exclude-existing` options
  builtin/show-ref: stop using global variable to count matches
  builtin/show-ref: stop using global vars for `show_one()`
  builtin/show-ref: refactor options for patterns subcommand
  builtin/show-ref: ensure mutual exclusiveness of subcommands
  builtin/show-ref: explicitly spell out different modes in synopsis
  builtin/show-ref: add new mode to check for reference existence
  t: use git-show-ref(1) to check for ref existence
 Documentation/git-show-ref.txt |  20 ++-
 builtin/show-ref.c             | 284 ++++++++++++++++++++++-----------
 t/t1403-show-ref.sh            |  70 ++++++++
 t/t1430-bad-ref-name.sh        |  27 ++--
 t/t3200-branch.sh              |  33 ++--
 t/t5521-pull-options.sh        |   4 +-
 t/t5605-clone-local.sh         |   2 +-
 t/test-lib-functions.sh        |  55 +++++++
 8 files changed, 373 insertions(+), 122 deletions(-)
Range-diff against v2:
 1:  78163accbd2 =  1:  9570ad63924 builtin/show-ref: convert pattern to a local variable
 2:  9a234622d99 =  2:  773c6119750 builtin/show-ref: split up different subcommands
 3:  bb0d656a0b4 =  3:  b6f4c0325bf builtin/show-ref: fix leaking string buffer
 4:  87afcee830c =  4:  4605c6f0ac9 builtin/show-ref: fix dead code when passing patterns
 5:  bed2a8a0769 !  5:  b47440089b6 builtin/show-ref: refactor `--exclude-existing` options
    @@ builtin/show-ref.c: static int add_existing(const char *refname,
      }
      
     +struct exclude_existing_options {
    ++	/*
    ++	 * We need an explicit `enabled` field because it is perfectly valid
    ++	 * for `pattern` to be `NULL` even if `--exclude-existing` was given.
    ++	 */
     +	int enabled;
     +	const char *pattern;
     +};
 6:  d52a5e8ced2 !  6:  6172888e465 builtin/show-ref: stop using global variable to count matches
    @@ Commit message
         builtin/show-ref: stop using global variable to count matches
     
         When passing patterns to git-show-ref(1) we're checking whether any
    -    reference matches -- if none does, we indicate this condition via an
    +    reference matches -- if none do, we indicate this condition via an
         unsuccessful exit code.
     
         We're using a global variable to count these matches, which is required
 7:  63f1dadf4c2 =  7:  bc528db7667 builtin/show-ref: stop using global vars for `show_one()`
 8:  88dfeaa4871 =  8:  e3882c07dfc builtin/show-ref: refactor options for patterns subcommand
 9:  5ba566723e8 !  9:  a095decd778 builtin/show-ref: ensure mutual exclusiveness of subcommands
    @@ t/t1403-show-ref.sh: test_expect_success 'show-ref --verify with dangling ref' '
      '
      
     +test_expect_success 'show-ref sub-modes are mutually exclusive' '
    ++	cat >expect <<-EOF &&
    ++	fatal: only one of ${SQ}--exclude-existing${SQ} or ${SQ}--verify${SQ} can be given
    ++	EOF
    ++
     +	test_must_fail git show-ref --verify --exclude-existing 2>err &&
    -+	grep "only one of ${SQ}--exclude-existing${SQ} or ${SQ}--verify${SQ} can be given" err
    ++	test_cmp expect err
     +'
     +
      test_done
10:  b78ccc5f692 = 10:  087384fd2fd builtin/show-ref: explicitly spell out different modes in synopsis
11:  327942b1162 ! 11:  ca5187bb18a builtin/show-ref: add new mode to check for reference existence
    @@ builtin/show-ref.c: int cmd_show_ref(int argc, const char **argv, const char *pr
     
      ## t/t1403-show-ref.sh ##
     @@ t/t1403-show-ref.sh: test_expect_success 'show-ref --verify with dangling ref' '
    - '
      
      test_expect_success 'show-ref sub-modes are mutually exclusive' '
    -+	cat >expect <<-EOF &&
    + 	cat >expect <<-EOF &&
    +-	fatal: only one of ${SQ}--exclude-existing${SQ} or ${SQ}--verify${SQ} can be given
     +	fatal: only one of ${SQ}--exclude-existing${SQ}, ${SQ}--verify${SQ} or ${SQ}--exists${SQ} can be given
    -+	EOF
    -+
    + 	EOF
    + 
      	test_must_fail git show-ref --verify --exclude-existing 2>err &&
    --	grep "only one of ${SQ}--exclude-existing${SQ} or ${SQ}--verify${SQ} can be given" err
     +	test_cmp expect err &&
     +
     +	test_must_fail git show-ref --verify --exists 2>err &&
    @@ t/t1403-show-ref.sh: test_expect_success 'show-ref --verify with dangling ref' '
     +	error: failed to look up reference: Is a directory
     +	EOF
     +	test_expect_code 1 git show-ref --exists refs/heads 2>err &&
    -+	test_cmp expect err
    + 	test_cmp expect err
      '
      
    - test_done
12:  226731c5f18 = 12:  ea9919fe899 t: use git-show-ref(1) to check for ref existence
base-commit: a9ecda2788e229afc9b611acaa26d0d9d4da53ed
-- 
2.42.0
Previous: Junio C HamanoNext: Patrick Steinhardt
Message 53 of 66 in “show-ref: introduce mode to check for ref existence”
  1. 00/12 show-ref: introduce mode to check for ref existencePatrick Steinhardt, Oct 24, 2023
  2. 01/12 builtin/show-ref: convert pattern to a local variablePatrick Steinhardt, Oct 24, 2023
  3. 02/12 builtin/show-ref: split up different subcommandsPatrick Steinhardt, Oct 24, 2023
  4. Eric SunshineOct 24, 2023
  5. 03/12 builtin/show-ref: fix leaking string bufferPatrick Steinhardt, Oct 24, 2023
  6. 04/12 builtin/show-ref: fix dead code when passing patternsPatrick Steinhardt, Oct 24, 2023
  7. Eric SunshineOct 24, 2023
  8. 05/12 builtin/show-ref: refactor `--exclude-existing` optionsPatrick Steinhardt, Oct 24, 2023
  9. Eric SunshineOct 24, 2023
  10. Patrick SteinhardtOct 25, 2023
  11. 06/12 builtin/show-ref: stop using global variable to count matchesPatrick Steinhardt, Oct 24, 2023
  12. 07/12 builtin/show-ref: stop using global vars for `show_one()`Patrick Steinhardt, Oct 24, 2023
  13. 08/12 builtin/show-ref: refactor options for patterns subcommandPatrick Steinhardt, Oct 24, 2023
  14. 09/12 builtin/show-ref: ensure mutual exclusiveness of subcommandsPatrick Steinhardt, Oct 24, 2023
  15. Eric SunshineOct 24, 2023
  16. 10/12 builtin/show-ref: explicitly spell out different modes in synopsisPatrick Steinhardt, Oct 24, 2023
  17. Eric SunshineOct 24, 2023
  18. Patrick SteinhardtOct 25, 2023
  19. 11/12 builtin/show-ref: add new mode to check for reference existencePatrick Steinhardt, Oct 24, 2023
  20. Eric SunshineOct 24, 2023
  21. Patrick SteinhardtOct 25, 2023
  22. 12/12 t: use git-show-ref(1) to check for ref existencePatrick Steinhardt, Oct 24, 2023
  23. Junio C HamanoOct 24, 2023
  24. Han-Wen NienhuysOct 25, 2023
  25. Phillip WoodOct 25, 2023
  26. Patrick SteinhardtOct 26, 2023
  27. Phillip WoodOct 27, 2023
  28. Patrick SteinhardtOct 26, 2023
  29. 00/12 show-ref: introduce mode to check for ref existencePatrick Steinhardt, Oct 26, 2023
  30. 01/12 builtin/show-ref: convert pattern to a local variablePatrick Steinhardt, Oct 26, 2023
  31. 02/12 builtin/show-ref: split up different subcommandsPatrick Steinhardt, Oct 26, 2023
  32. 03/12 builtin/show-ref: fix leaking string bufferPatrick Steinhardt, Oct 26, 2023
  33. Taylor BlauOct 30, 2023
  34. 04/12 builtin/show-ref: fix dead code when passing patternsPatrick Steinhardt, Oct 26, 2023
  35. Taylor BlauOct 30, 2023
  36. 05/12 builtin/show-ref: refactor `--exclude-existing` optionsPatrick Steinhardt, Oct 26, 2023
  37. Taylor BlauOct 30, 2023
  38. Patrick SteinhardtOct 31, 2023
  39. Taylor BlauOct 30, 2023
  40. Patrick SteinhardtOct 31, 2023
  41. 06/12 builtin/show-ref: stop using global variable to count matchesPatrick Steinhardt, Oct 26, 2023
  42. Taylor BlauOct 30, 2023
  43. 07/12 builtin/show-ref: stop using global vars for `show_one()`Patrick Steinhardt, Oct 26, 2023
  44. 08/12 builtin/show-ref: refactor options for patterns subcommandPatrick Steinhardt, Oct 26, 2023
  45. 09/12 builtin/show-ref: ensure mutual exclusiveness of subcommandsPatrick Steinhardt, Oct 26, 2023
  46. Taylor BlauOct 30, 2023
  47. Patrick SteinhardtOct 31, 2023
  48. 10/12 builtin/show-ref: explicitly spell out different modes in synopsisPatrick Steinhardt, Oct 26, 2023
  49. 11/12 builtin/show-ref: add new mode to check for reference existencePatrick Steinhardt, Oct 26, 2023
  50. 12/12 t: use git-show-ref(1) to check for ref existencePatrick Steinhardt, Oct 26, 2023
  51. Taylor BlauOct 30, 2023
  52. Junio C HamanoOct 31, 2023
  53. 00/12 builtin/show-ref: introduce mode to check for ref existencePatrick Steinhardt, Oct 31, 2023
  54. 01/12 builtin/show-ref: convert pattern to a local variablePatrick Steinhardt, Oct 31, 2023
  55. 02/12 builtin/show-ref: split up different subcommandsPatrick Steinhardt, Oct 31, 2023
  56. 03/12 builtin/show-ref: fix leaking string bufferPatrick Steinhardt, Oct 31, 2023
  57. 04/12 builtin/show-ref: fix dead code when passing patternsPatrick Steinhardt, Oct 31, 2023
  58. 05/12 builtin/show-ref: refactor `--exclude-existing` optionsPatrick Steinhardt, Oct 31, 2023
  59. 06/12 builtin/show-ref: stop using global variable to count matchesPatrick Steinhardt, Oct 31, 2023
  60. 07/12 builtin/show-ref: stop using global vars for `show_one()`Patrick Steinhardt, Oct 31, 2023
  61. 08/12 builtin/show-ref: refactor options for patterns subcommandPatrick Steinhardt, Oct 31, 2023
  62. 09/12 builtin/show-ref: ensure mutual exclusiveness of subcommandsPatrick Steinhardt, Oct 31, 2023
  63. 10/12 builtin/show-ref: explicitly spell out different modes in synopsisPatrick Steinhardt, Oct 31, 2023
  64. 11/12 builtin/show-ref: add new mode to check for reference existencePatrick Steinhardt, Oct 31, 2023
  65. 12/12 t: use git-show-ref(1) to check for ref existencePatrick Steinhardt, Oct 31, 2023
  66. Taylor BlauOct 31, 2023

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.