1 From f22917e0bd9347ed547e124738083d5b6889da0a Mon Sep 17 00:00:00 2001
2 From: Ian Jackson <ijackson@chiark.greenend.org.uk>
3 Date: Fri, 4 Nov 2016 17:41:15 +0000
4 Subject: [PATCH 5/5] check-ref-format: New --stdin option
6 Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
8 Documentation/git-check-ref-format.txt | 10 ++++++++--
9 builtin/check-ref-format.c | 34 +++++++++++++++++++++++++++++++---
10 2 files changed, 39 insertions(+), 5 deletions(-)
12 diff --git a/Documentation/git-check-ref-format.txt b/Documentation/git-check-ref-format.txt
13 index e9a2657..5a213ce 100644
14 --- a/Documentation/git-check-ref-format.txt
15 +++ b/Documentation/git-check-ref-format.txt
16 @@ -10,8 +10,9 @@ SYNOPSIS
18 'git check-ref-format' [--report-errors] [--normalize]
19 [--[no-]allow-onelevel] [--refspec-pattern]
21 -'git check-ref-format' [--report-errors] --branch <branchname-shorthand>
23 +'git check-ref-format' [--report-errors] --branch
24 + <branchname-shorthand> | --stdin
28 @@ -109,6 +110,11 @@ OPTIONS
29 If any ref does not check OK, print a message to stderr.
30 (By default, git check-ref-format is silent.)
33 + Instead of checking on ref supplied on the command line,
34 + read refs, one per line, from stdin. The exit status is
35 + 0 if all the refs were OK.
40 diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c
41 index 559d5c2..87f52fa 100644
42 --- a/builtin/check-ref-format.c
43 +++ b/builtin/check-ref-format.c
44 @@ -76,6 +76,7 @@ static int check_one_ref_format(const char *refname)
45 int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
50 if (argc == 2 && !strcmp(argv[1], "-h"))
51 usage(builtin_check_ref_format_usage);
52 @@ -93,6 +94,8 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
54 else if (!strcmp(argv[i], "--report-errors"))
56 + else if (!strcmp(argv[i], "--stdin"))
59 usage(builtin_check_ref_format_usage);
61 @@ -100,8 +103,33 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
62 if (check_branch && (flags || normalize))
63 usage(builtin_check_ref_format_usage);
65 - if (! (i == argc - 1))
66 - usage(builtin_check_ref_format_usage);
68 + if (! (i == argc - 1))
69 + usage(builtin_check_ref_format_usage);
71 + return check_one_ref_format(argv[i]);
76 - return check_one_ref_format(argv[i]);
78 + usage(builtin_check_ref_format_usage);
80 + while (fgets(buffer, sizeof(buffer), stdin)) {
81 + char *newline = strchr(buffer, '\n');
83 + fprintf(stderr, "%s --stdin: missing final newline or line too long\n", *argv);
87 + int got = check_one_ref_format(buffer);
92 + perror("reading from stdin");