Change check_ref_format() to take a flags argument
[alt-git.git] / Documentation / git-check-ref-format.txt
blobdcb8cc38a3a6856b51ad2c217e81271bcdf2535d
1 git-check-ref-format(1)
2 =======================
4 NAME
5 ----
6 git-check-ref-format - Ensures that a reference name is well formed
8 SYNOPSIS
9 --------
10 [verse]
11 'git check-ref-format' [--print]
12        [--[no-]allow-onelevel] [--refspec-pattern] <refname>
13 'git check-ref-format' --branch <branchname-shorthand>
15 DESCRIPTION
16 -----------
17 Checks if a given 'refname' is acceptable, and exits with a non-zero
18 status if it is not.
20 A reference is used in git to specify branches and tags.  A
21 branch head is stored in the `refs/heads` hierarchy, while
22 a tag is stored in the `refs/tags` hierarchy of the ref namespace
23 (typically in `$GIT_DIR/refs/heads` and `$GIT_DIR/refs/tags`
24 directories or, as entries in file `$GIT_DIR/packed-refs`
25 if refs are packed by `git gc`).
27 git imposes the following rules on how references are named:
29 . They can include slash `/` for hierarchical (directory)
30   grouping, but no slash-separated component can begin with a
31   dot `.`.
33 . They must contain at least one `/`. This enforces the presence of a
34   category like `heads/`, `tags/` etc. but the actual names are not
35   restricted.  If the `--allow-onelevel` option is used, this rule
36   is waived.
38 . They cannot have two consecutive dots `..` anywhere.
40 . They cannot have ASCII control characters (i.e. bytes whose
41   values are lower than \040, or \177 `DEL`), space, tilde `~`,
42   caret `{caret}`, or colon `:` anywhere.
44 . They cannot have question-mark `?`, asterisk `{asterisk}`, or open
45   bracket `[` anywhere.  See the `--refspec-pattern` option below for
46   an exception to this rule.
48 . They cannot end with a slash `/` nor a dot `.`.
50 . They cannot end with the sequence `.lock`.
52 . They cannot contain a sequence `@{`.
54 . They cannot contain a `\`.
56 These rules make it easy for shell script based tools to parse
57 reference names, pathname expansion by the shell when a reference name is used
58 unquoted (by mistake), and also avoids ambiguities in certain
59 reference name expressions (see linkgit:gitrevisions[7]):
61 . A double-dot `..` is often used as in `ref1..ref2`, and in some
62   contexts this notation means `{caret}ref1 ref2` (i.e. not in
63   `ref1` and in `ref2`).
65 . A tilde `~` and caret `{caret}` are used to introduce the postfix
66   'nth parent' and 'peel onion' operation.
68 . A colon `:` is used as in `srcref:dstref` to mean "use srcref\'s
69   value and store it in dstref" in fetch and push operations.
70   It may also be used to select a specific object such as with
71   'git cat-file': "git cat-file blob v1.3.3:refs.c".
73 . at-open-brace `@{` is used as a notation to access a reflog entry.
75 With the `--print` option, if 'refname' is acceptable, it prints the
76 canonicalized name of a hypothetical reference with that name.  That is,
77 it prints 'refname' with any extra `/` characters removed.
79 With the `--branch` option, it expands the ``previous branch syntax''
80 `@{-n}`.  For example, `@{-1}` is a way to refer the last branch you
81 were on.  This option should be used by porcelains to accept this
82 syntax anywhere a branch name is expected, so they can act as if you
83 typed the branch name.
85 OPTIONS
86 -------
87 --allow-onelevel::
88 --no-allow-onelevel::
89         Controls whether one-level refnames are accepted (i.e.,
90         refnames that do not contain multiple `/`-separated
91         components).  The default is `--no-allow-onelevel`.
93 --refspec-pattern::
94         Interpret <refname> as a reference name pattern for a refspec
95         (as used with remote repositories).  If this option is
96         enabled, <refname> is allowed to contain a single `{asterisk}`
97         in place of a one full pathname component (e.g.,
98         `foo/{asterisk}/bar` but not `foo/bar{asterisk}`).
100 EXAMPLES
101 --------
103 * Print the name of the previous branch:
105 ------------
106 $ git check-ref-format --branch @{-1}
107 ------------
109 * Determine the reference name to use for a new branch:
111 ------------
112 $ ref=$(git check-ref-format --print "refs/heads/$newbranch") ||
113 die "we do not like '$newbranch' as a branch name."
114 ------------
118 Part of the linkgit:git[1] suite