Skip to content

builtin/show-ref: introduce mode to check for ref existence

Patrick Steinhardt git 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest12 patches 1 replyIn review
  2. v212 patches 11 repliesSuperseded
  3. v112 patches 15 repliesSuperseded

Changes in v3 from the cover letter

- 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).

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/12builtin/show-ref: convert pattern to a local variablebuiltin/show-ref.c+28 -180 replies
2/12builtin/show-ref: split up different subcommandsbuiltin/show-ref.c+54 -470 replies
3/12builtin/show-ref: fix leaking string bufferbuiltin/show-ref.c+3 -10 replies
4/12builtin/show-ref: fix dead code when passing patternsbuiltin/show-ref.c+1 -40 replies
5/12builtin/show-ref: refactor `--exclude-existing` optionsbuiltin/show-ref.c+44 -340 replies
6/12builtin/show-ref: stop using global variable to count matchesbuiltin/show-ref.c+4 -30 replies
7/12builtin/show-ref: stop using global vars for `show_one()`builtin/show-ref.c+40 -220 replies
8/12builtin/show-ref: refactor options for patterns subcommandbuiltin/show-ref.c+22 -130 replies
9/12builtin/show-ref: ensure mutual exclusiveness of subcommandsbuiltin/show-ref.c t/t1403-show-ref.sh+13 -00 replies
10/12builtin/show-ref: explicitly spell out different modes in synopsisDocumentation/git-show-ref.txt builtin/show-ref.c+10 -40 replies
11/12builtin/show-ref: add new mode to check for reference existenceDocumentation/git-show-ref.txt builtin/show-ref.c t/t1403-show-ref.sh+117 -60 replies
12/12t: use git-show-ref(1) to check for ref existencet/t1430-bad-ref-name.sh t/t3200-branch.sh t/t5521-pull-options.sh +2 more+94 -270 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

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

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

Signature · 1 line
2.42.0