[PATCH v3 00/12] builtin/show-ref: introduce mode to check for ref existence
From: Patrick Steinhardt <hidden>
Date: 2023-10-31 08:16:16
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
Attachments
- signature.asc [application/pgp-signature] 833 bytes