Skip to content

Commit 93e8cd8

Browse files
committed
Merge branch 'kn/ref-filter-branch-list'
The code to list branches in "git branch" has been consolidated with the more generic ref-filter API. * kn/ref-filter-branch-list: (21 commits) ref-filter: resurrect "strip" as a synonym to "lstrip" branch: implement '--format' option branch: use ref-filter printing APIs branch, tag: use porcelain output ref-filter: allow porcelain to translate messages in the output ref-filter: add an 'rstrip=<N>' option to atoms which deal with refnames ref-filter: modify the 'lstrip=<N>' option to work with negative '<N>' ref-filter: Do not abruptly die when using the 'lstrip=<N>' option ref-filter: rename the 'strip' option to 'lstrip' ref-filter: make remote_ref_atom_parser() use refname_atom_parser_internal() ref-filter: introduce refname_atom_parser() ref-filter: introduce refname_atom_parser_internal() ref-filter: make "%(symref)" atom work with the ':short' modifier ref-filter: add support for %(upstream:track,nobracket) ref-filter: make %(upstream:track) prints "[gone]" for invalid upstreams ref-filter: introduce format_ref_array_item() ref-filter: move get_head_description() from branch.c ref-filter: modify "%(objectname:short)" to take length ref-filter: implement %(if:equals=<string>) and %(if:notequals=<string>) ref-filter: include reference to 'used_atom' within 'atom_value' ...
2 parents a411726 + 44a6b6c commit 93e8cd8

File tree

10 files changed

+798
-303
lines changed

10 files changed

+798
-303
lines changed

Documentation/git-branch.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ SYNOPSIS
1212
[--list] [-v [--abbrev=<length> | --no-abbrev]]
1313
[--column[=<options>] | --no-column]
1414
[(--merged | --no-merged | --contains) [<commit>]] [--sort=<key>]
15-
[--points-at <object>] [<pattern>...]
15+
[--points-at <object>] [--format=<format>] [<pattern>...]
1616
'git branch' [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>]
1717
'git branch' (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
1818
'git branch' --unset-upstream [<branchname>]
@@ -253,6 +253,11 @@ start-point is either a local or remote-tracking branch.
253253
--points-at <object>::
254254
Only list branches of the given object.
255255

256+
--format <format>::
257+
A string that interpolates `%(fieldname)` from the object
258+
pointed at by a ref being shown. The format is the same as
259+
that of linkgit:git-for-each-ref[1].
260+
256261
Examples
257262
--------
258263

Documentation/git-for-each-ref.txt

Lines changed: 77 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,20 @@ refname::
9595
The name of the ref (the part after $GIT_DIR/).
9696
For a non-ambiguous short name of the ref append `:short`.
9797
The option core.warnAmbiguousRefs is used to select the strict
98-
abbreviation mode. If `strip=<N>` is appended, strips `<N>`
99-
slash-separated path components from the front of the refname
100-
(e.g., `%(refname:strip=2)` turns `refs/tags/foo` into `foo`.
101-
`<N>` must be a positive integer. If a displayed ref has fewer
102-
components than `<N>`, the command aborts with an error.
98+
abbreviation mode. If `lstrip=<N>` (`rstrip=<N>`) is appended, strips `<N>`
99+
slash-separated path components from the front (back) of the refname
100+
(e.g. `%(refname:lstrip=2)` turns `refs/tags/foo` into `foo` and
101+
`%(refname:rstrip=2)` turns `refs/tags/foo` into `refs`).
102+
If `<N>` is a negative number, strip as many path components as
103+
necessary from the specified end to leave `-<N>` path components
104+
(e.g. `%(refname:lstrip=-2)` turns
105+
`refs/tags/foo` into `tags/foo` and `%(refname:rstrip=-1)`
106+
turns `refs/tags/foo` into `refs`). When the ref does not have
107+
enough components, the result becomes an empty string if
108+
stripping with positive <N>, or it becomes the full refname if
109+
stripping with negative <N>. Neither is an error.
110+
+
111+
`strip` can be used as a synomym to `lstrip`.
103112

104113
objecttype::
105114
The type of the object (`blob`, `tree`, `commit`, `tag`).
@@ -110,21 +119,31 @@ objectsize::
110119
objectname::
111120
The object name (aka SHA-1).
112121
For a non-ambiguous abbreviation of the object name append `:short`.
122+
For an abbreviation of the object name with desired length append
123+
`:short=<length>`, where the minimum length is MINIMUM_ABBREV. The
124+
length may be exceeded to ensure unique object names.
113125

114126
upstream::
115127
The name of a local ref which can be considered ``upstream''
116-
from the displayed ref. Respects `:short` in the same way as
117-
`refname` above. Additionally respects `:track` to show
118-
"[ahead N, behind M]" and `:trackshort` to show the terse
119-
version: ">" (ahead), "<" (behind), "<>" (ahead and behind),
120-
or "=" (in sync). Has no effect if the ref does not have
121-
tracking information associated with it.
128+
from the displayed ref. Respects `:short`, `:lstrip` and
129+
`:rstrip` in the same way as `refname` above. Additionally
130+
respects `:track` to show "[ahead N, behind M]" and
131+
`:trackshort` to show the terse version: ">" (ahead), "<"
132+
(behind), "<>" (ahead and behind), or "=" (in sync). `:track`
133+
also prints "[gone]" whenever unknown upstream ref is
134+
encountered. Append `:track,nobracket` to show tracking
135+
information without brackets (i.e "ahead N, behind M"). Has
136+
no effect if the ref does not have tracking information
137+
associated with it. All the options apart from `nobracket`
138+
are mutually exclusive, but if used together the last option
139+
is selected.
122140

123141
push::
124-
The name of a local ref which represents the `@{push}` location
125-
for the displayed ref. Respects `:short`, `:track`, and
126-
`:trackshort` options as `upstream` does. Produces an empty
127-
string if no `@{push}` ref is configured.
142+
The name of a local ref which represents the `@{push}`
143+
location for the displayed ref. Respects `:short`, `:lstrip`,
144+
`:rstrip`, `:track`, and `:trackshort` options as `upstream`
145+
does. Produces an empty string if no `@{push}` ref is
146+
configured.
128147

129148
HEAD::
130149
'*' if HEAD matches current ref (the checked out branch), ' '
@@ -149,6 +168,25 @@ align::
149168
quoted, but if nested then only the topmost level performs
150169
quoting.
151170

171+
if::
172+
Used as %(if)...%(then)...%(end) or
173+
%(if)...%(then)...%(else)...%(end). If there is an atom with
174+
value or string literal after the %(if) then everything after
175+
the %(then) is printed, else if the %(else) atom is used, then
176+
everything after %(else) is printed. We ignore space when
177+
evaluating the string before %(then), this is useful when we
178+
use the %(HEAD) atom which prints either "*" or " " and we
179+
want to apply the 'if' condition only on the 'HEAD' ref.
180+
Append ":equals=<string>" or ":notequals=<string>" to compare
181+
the value between the %(if:...) and %(then) atoms with the
182+
given string.
183+
184+
symref::
185+
The ref which the given symbolic ref refers to. If not a
186+
symbolic ref, nothing is printed. Respects the `:short`,
187+
`:lstrip` and `:rstrip` options in the same way as `refname`
188+
above.
189+
152190
In addition to the above, for commit and tag objects, the header
153191
field names (`tree`, `parent`, `object`, `type`, and `tag`) can
154192
be used to specify the value in the header field.
@@ -186,6 +224,14 @@ As a special case for the date-type fields, you may specify a format for
186224
the date by adding `:` followed by date format name (see the
187225
values the `--date` option to linkgit:git-rev-list[1] takes).
188226

227+
Some atoms like %(align) and %(if) always require a matching %(end).
228+
We call them "opening atoms" and sometimes denote them as %($open).
229+
230+
When a scripting language specific quoting is in effect, everything
231+
between a top-level opening atom and its matching %(end) is evaluated
232+
according to the semantics of the opening atom and only its result
233+
from the top-level is quoted.
234+
189235

190236
EXAMPLES
191237
--------
@@ -273,6 +319,22 @@ eval=`git for-each-ref --shell --format="$fmt" \
273319
eval "$eval"
274320
------------
275321

322+
323+
An example to show the usage of %(if)...%(then)...%(else)...%(end).
324+
This prefixes the current branch with a star.
325+
326+
------------
327+
git for-each-ref --format="%(if)%(HEAD)%(then)* %(else) %(end)%(refname:short)" refs/heads/
328+
------------
329+
330+
331+
An example to show the usage of %(if)...%(then)...%(end).
332+
This prints the authorname, if present.
333+
334+
------------
335+
git for-each-ref --format="%(refname)%(if)%(authorname)%(then) Authored by: %(authorname)%(end)"
336+
------------
337+
276338
SEE ALSO
277339
--------
278340
linkgit:git-show-ref[1]

0 commit comments

Comments
 (0)