chiark / gitweb /
README with final notes
[version-charset-test.git] / 0004-check-ref-format-New-report-errors-option.patch
1 From 5f0a31143d8e1c3740e81ad948c8ae670a322dcc Mon Sep 17 00:00:00 2001
2 From: Ian Jackson <ijackson@chiark.greenend.org.uk>
3 Date: Fri, 4 Nov 2016 17:40:49 +0000
4 Subject: [PATCH 4/5] check-ref-format: New --report-errors option
5
6 Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
7 ---
8  Documentation/git-check-ref-format.txt |  8 ++++++--
9  builtin/check-ref-format.c             | 10 ++++++++--
10  2 files changed, 14 insertions(+), 4 deletions(-)
11
12 diff --git a/Documentation/git-check-ref-format.txt b/Documentation/git-check-ref-format.txt
13 index 8611a99..e9a2657 100644
14 --- a/Documentation/git-check-ref-format.txt
15 +++ b/Documentation/git-check-ref-format.txt
16 @@ -8,10 +8,10 @@ git-check-ref-format - Ensures that a reference name is well formed
17  SYNOPSIS
18  --------
19  [verse]
20 -'git check-ref-format' [--normalize]
21 +'git check-ref-format' [--report-errors] [--normalize]
22         [--[no-]allow-onelevel] [--refspec-pattern]
23         <refname>
24 -'git check-ref-format' --branch <branchname-shorthand>
25 +'git check-ref-format' [--report-errors] --branch <branchname-shorthand>
26  
27  DESCRIPTION
28  -----------
29 @@ -105,6 +105,10 @@ OPTIONS
30         with a status of 0.  (`--print` is a deprecated way to spell
31         `--normalize`.)
32  
33 +--report-errors::
34 +       If any ref does not check OK, print a message to stderr.
35 +        (By default, git check-ref-format is silent.)
36 +
37  
38  EXAMPLES
39  --------
40 diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c
41 index 020ebe8..559d5c2 100644
42 --- a/builtin/check-ref-format.c
43 +++ b/builtin/check-ref-format.c
44 @@ -9,7 +9,7 @@
45  
46  static const char builtin_check_ref_format_usage[] =
47  "git check-ref-format [--normalize] [<options>] <refname>\n"
48 -"   or: git check-ref-format --branch <branchname-shorthand>";
49 +"   or: git check-ref-format [<options>] --branch <branchname-shorthand>";
50  
51  /*
52   * Return a copy of refname but with leading slashes removed and runs
53 @@ -51,6 +51,7 @@ static int check_ref_format_branch(const char *arg)
54  static int normalize = 0;
55  static int check_branch = 0;
56  static int flags = 0;
57 +static int report_errors = 0;
58  
59  static int check_one_ref_format(const char *refname)
60  {
61 @@ -61,8 +62,11 @@ static int check_one_ref_format(const char *refname)
62         got = check_branch
63                 ? check_ref_format_branch(refname)
64                 : check_refname_format(refname, flags);
65 -       if (got)
66 +       if (got) {
67 +               if (report_errors)
68 +                       fprintf(stderr, "bad ref format: %s\n", refname);
69                 return 1;
70 +       }
71         if (normalize) {
72                 printf("%s\n", refname);
73                 free((void*)refname);
74 @@ -87,6 +91,8 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
75                         flags |= REFNAME_REFSPEC_PATTERN;
76                 else if (!strcmp(argv[i], "--branch"))
77                         check_branch = 1;
78 +               else if (!strcmp(argv[i], "--report-errors"))
79 +                       report_errors = 1;
80                 else
81                         usage(builtin_check_ref_format_usage);
82         }
83 -- 
84 2.10.1
85