Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 1 | git-check-ref-format(1) |
| 2 | ======================= |
| 3 | |
| 4 | NAME |
| 5 | ---- |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 6 | git-check-ref-format - Ensures that a reference name is well formed |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 7 | |
| 8 | SYNOPSIS |
| 9 | -------- |
Junio C Hamano | 5f9a6f0 | 2009-04-06 08:26:56 | [diff] [blame] | 10 | [verse] |
Junio C Hamano | 5870066 | 2011-10-10 23:42:27 | [diff] [blame] | 11 | 'git check-ref-format' [--normalize] |
| 12 | [--[no-]allow-onelevel] [--refspec-pattern] |
| 13 | <refname> |
Junio C Hamano | 3d23a0a | 2009-10-19 08:04:30 | [diff] [blame] | 14 | 'git check-ref-format' --branch <branchname-shorthand> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 15 | |
| 16 | DESCRIPTION |
| 17 | ----------- |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 18 | Checks if a given 'refname' is acceptable, and exits with a non-zero |
| 19 | status if it is not. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 20 | |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 21 | A reference is used in Git to specify branches and tags. A |
Junio C Hamano | 360e3a1 | 2011-07-13 23:51:56 | [diff] [blame] | 22 | branch head is stored in the `refs/heads` hierarchy, while |
| 23 | a tag is stored in the `refs/tags` hierarchy of the ref namespace |
| 24 | (typically in `$GIT_DIR/refs/heads` and `$GIT_DIR/refs/tags` |
| 25 | directories or, as entries in file `$GIT_DIR/packed-refs` |
| 26 | if refs are packed by `git gc`). |
| 27 | |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 28 | Git imposes the following rules on how references are named: |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 29 | |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 30 | . They can include slash `/` for hierarchical (directory) |
Junio C Hamano | 33db437 | 2006-06-07 19:51:45 | [diff] [blame] | 31 | grouping, but no slash-separated component can begin with a |
Junio C Hamano | 5870066 | 2011-10-10 23:42:27 | [diff] [blame] | 32 | dot `.` or end with the sequence `.lock`. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 33 | |
Junio C Hamano | 8679a79 | 2009-05-13 20:50:32 | [diff] [blame] | 34 | . They must contain at least one `/`. This enforces the presence of a |
| 35 | category like `heads/`, `tags/` etc. but the actual names are not |
Junio C Hamano | 5870066 | 2011-10-10 23:42:27 | [diff] [blame] | 36 | restricted. If the `--allow-onelevel` option is used, this rule |
| 37 | is waived. |
Junio C Hamano | 8679a79 | 2009-05-13 20:50:32 | [diff] [blame] | 38 | |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 39 | . They cannot have two consecutive dots `..` anywhere. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 40 | |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 41 | . They cannot have ASCII control characters (i.e. bytes whose |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 42 | values are lower than \040, or \177 `DEL`), space, tilde `~`, |
Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 43 | caret `^`, or colon `:` anywhere. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 44 | |
Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 45 | . They cannot have question-mark `?`, asterisk `*`, or open |
Junio C Hamano | 5870066 | 2011-10-10 23:42:27 | [diff] [blame] | 46 | bracket `[` anywhere. See the `--refspec-pattern` option below for |
| 47 | an exception to this rule. |
Junio C Hamano | 5f9a6f0 | 2009-04-06 08:26:56 | [diff] [blame] | 48 | |
Junio C Hamano | 5870066 | 2011-10-10 23:42:27 | [diff] [blame] | 49 | . They cannot begin or end with a slash `/` or contain multiple |
| 50 | consecutive slashes (see the `--normalize` option below for an |
| 51 | exception to this rule) |
| 52 | |
| 53 | . They cannot end with a dot `.`. |
Junio C Hamano | 5f9a6f0 | 2009-04-06 08:26:56 | [diff] [blame] | 54 | |
| 55 | . They cannot contain a sequence `@{`. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 56 | |
Junio C Hamano | dca3482 | 2010-02-13 01:02:52 | [diff] [blame] | 57 | . They cannot contain a `\`. |
Junio C Hamano | 7ae1825 | 2009-05-23 09:53:32 | [diff] [blame] | 58 | |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 59 | These rules make it easy for shell script based tools to parse |
| 60 | reference names, pathname expansion by the shell when a reference name is used |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 61 | unquoted (by mistake), and also avoids ambiguities in certain |
Junio C Hamano | c27b733 | 2010-10-14 04:37:28 | [diff] [blame] | 62 | reference name expressions (see linkgit:gitrevisions[7]): |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 63 | |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 64 | . A double-dot `..` is often used as in `ref1..ref2`, and in some |
Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 65 | contexts this notation means `^ref1 ref2` (i.e. not in |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 66 | `ref1` and in `ref2`). |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 67 | |
Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 68 | . A tilde `~` and caret `^` are used to introduce the postfix |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 69 | 'nth parent' and 'peel onion' operation. |
| 70 | |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 71 | . A colon `:` is used as in `srcref:dstref` to mean "use srcref\'s |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 72 | value and store it in dstref" in fetch and push operations. |
Junio C Hamano | b2f5edd | 2006-05-21 10:50:09 | [diff] [blame] | 73 | It may also be used to select a specific object such as with |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 74 | 'git cat-file': "git cat-file blob v1.3.3:refs.c". |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 75 | |
Junio C Hamano | 5f9a6f0 | 2009-04-06 08:26:56 | [diff] [blame] | 76 | . at-open-brace `@{` is used as a notation to access a reflog entry. |
| 77 | |
Junio C Hamano | 3d23a0a | 2009-10-19 08:04:30 | [diff] [blame] | 78 | With the `--branch` option, it expands the ``previous branch syntax'' |
| 79 | `@{-n}`. For example, `@{-1}` is a way to refer the last branch you |
| 80 | were on. This option should be used by porcelains to accept this |
| 81 | syntax anywhere a branch name is expected, so they can act as if you |
| 82 | typed the branch name. |
Junio C Hamano | 5f9a6f0 | 2009-04-06 08:26:56 | [diff] [blame] | 83 | |
Junio C Hamano | 5870066 | 2011-10-10 23:42:27 | [diff] [blame] | 84 | OPTIONS |
| 85 | ------- |
| 86 | --allow-onelevel:: |
| 87 | --no-allow-onelevel:: |
| 88 | Controls whether one-level refnames are accepted (i.e., |
| 89 | refnames that do not contain multiple `/`-separated |
| 90 | components). The default is `--no-allow-onelevel`. |
| 91 | |
| 92 | --refspec-pattern:: |
| 93 | Interpret <refname> as a reference name pattern for a refspec |
| 94 | (as used with remote repositories). If this option is |
Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 95 | enabled, <refname> is allowed to contain a single `*` |
Junio C Hamano | 5870066 | 2011-10-10 23:42:27 | [diff] [blame] | 96 | in place of a one full pathname component (e.g., |
Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 97 | `foo/*/bar` but not `foo/bar*`). |
Junio C Hamano | 5870066 | 2011-10-10 23:42:27 | [diff] [blame] | 98 | |
| 99 | --normalize:: |
| 100 | Normalize 'refname' by removing any leading slash (`/`) |
| 101 | characters and collapsing runs of adjacent slashes between |
| 102 | name components into a single slash. Iff the normalized |
| 103 | refname is valid then print it to standard output and exit |
| 104 | with a status of 0. (`--print` is a deprecated way to spell |
| 105 | `--normalize`.) |
| 106 | |
| 107 | |
Junio C Hamano | c21ab05 | 2009-10-31 04:03:55 | [diff] [blame] | 108 | EXAMPLES |
| 109 | -------- |
Junio C Hamano | 5f9a6f0 | 2009-04-06 08:26:56 | [diff] [blame] | 110 | |
Junio C Hamano | c21ab05 | 2009-10-31 04:03:55 | [diff] [blame] | 111 | * Print the name of the previous branch: |
| 112 | + |
| 113 | ------------ |
| 114 | $ git check-ref-format --branch @{-1} |
| 115 | ------------ |
Junio C Hamano | 5f9a6f0 | 2009-04-06 08:26:56 | [diff] [blame] | 116 | |
Junio C Hamano | c21ab05 | 2009-10-31 04:03:55 | [diff] [blame] | 117 | * Determine the reference name to use for a new branch: |
| 118 | + |
| 119 | ------------ |
Junio C Hamano | 5870066 | 2011-10-10 23:42:27 | [diff] [blame] | 120 | $ ref=$(git check-ref-format --normalize "refs/heads/$newbranch") || |
Junio C Hamano | c21ab05 | 2009-10-31 04:03:55 | [diff] [blame] | 121 | die "we do not like '$newbranch' as a branch name." |
| 122 | ------------ |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 123 | |
| 124 | GIT |
| 125 | --- |
Junio C Hamano | f7c042d | 2008-06-06 22:50:53 | [diff] [blame] | 126 | Part of the linkgit:git[1] suite |