Skip to content

Commit

Permalink
Merge branch 'lj/refs'
Browse files Browse the repository at this point in the history
* lj/refs: (63 commits)
  Fix show-ref usagestring
  t3200: git-branch testsuite update
  sha1_name.c: avoid compilation warnings.
  Make git-branch a builtin
  ref-log: fix D/F conflict coming from deleted refs.
  git-revert with conflicts to behave as git-merge with conflicts
  core.logallrefupdates thinko-fix
  git-pack-refs --all
  core.logallrefupdates create new log file only for branch heads.
  Remove bashism from t3210-pack-refs.sh
  ref-log: allow ref@{count} syntax.
  pack-refs: call fflush before fsync.
  pack-refs: use lockfile as everybody else does.
  git-fetch: do not look into $GIT_DIR/refs to see if a tag exists.
  lock_ref_sha1_basic does not remove empty directories on BSD
  Do not create tag leading directories since git update-ref does it.
  Check that a tag exists using show-ref instead of looking for the ref file.
  Use git-update-ref to delete a tag instead of rm()ing the ref file.
  Fix refs.c;:repack_without_ref() clean-up path
  Clean up "git-branch.sh" and add remove recursive dir test cases.
  ...
  • Loading branch information
Junio C Hamano committed Nov 1, 2006
2 parents ec1e468 + 2e6d8f1 commit 58a1e0e
Show file tree
Hide file tree
Showing 45 changed files with 1,475 additions and 536 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -75,6 +75,7 @@ git-name-rev
git-mv
git-pack-redundant
git-pack-objects
git-pack-refs
git-parse-remote
git-patch-id
git-peek-remote
Expand Down Expand Up @@ -106,6 +107,7 @@ git-shortlog
git-show
git-show-branch
git-show-index
git-show-ref
git-ssh-fetch
git-ssh-pull
git-ssh-push
Expand Down
16 changes: 10 additions & 6 deletions Documentation/config.txt
Expand Up @@ -71,12 +71,16 @@ core.preferSymlinkRefs::
expect HEAD to be a symbolic link.

core.logAllRefUpdates::
If true, `git-update-ref` will append a line to
"$GIT_DIR/logs/<ref>" listing the new SHA1 and the date/time
of the update. If the file does not exist it will be
created automatically. This information can be used to
determine what commit was the tip of a branch "2 days ago".
This value is false by default (no logging).
Updates to a ref <ref> is logged to the file
"$GIT_DIR/logs/<ref>", by appending the new and old
SHA1, the date/time and the reason of the update, but
only when the file exists. If this configuration
variable is set to true, missing "$GIT_DIR/logs/<ref>"
file is automatically created for branch heads.

This information can be used to determine what commit
was the tip of a branch "2 days ago". This value is
false by default (no automated creation of log files).

core.repositoryFormatVersion::
Internal variable identifying the repository format and layout
Expand Down
156 changes: 156 additions & 0 deletions Documentation/git-show-ref.txt
@@ -0,0 +1,156 @@
git-show-ref(1)
===============

NAME
----
git-show-ref - List references in a local repository

SYNOPSIS
--------
[verse]
'git-show-ref' [-q|--quiet] [--verify] [-h|--head] [-d|--dereference]
[-s|--hash] [--abbrev] [--tags] [--heads] [--] <pattern>...

DESCRIPTION
-----------

Displays references available in a local repository along with the associated
commit IDs. Results can be filtered using a pattern and tags can be
dereferenced into object IDs. Additionally, it can be used to test whether a
particular ref exists.

Use of this utility is encouraged in favor of directly accessing files under
in the `.git` directory.

OPTIONS
-------

-h, --head::

Show the HEAD reference.

--tags, --heads::

Limit to only "refs/heads" and "refs/tags", respectively. These
options are not mutually exclusive; when given both, references stored
in "refs/heads" and "refs/tags" are displayed.

-d, --dereference::

Dereference tags into object IDs as well. They will be shown with "^{}"
appended.

-s, --hash::

Only show the SHA1 hash, not the reference name. When also using
--dereference the dereferenced tag will still be shown after the SHA1.

--verify::

Enable stricter reference checking by requiring an exact ref path.
Aside from returning an error code of 1, it will also print an error
message if '--quiet' was not specified.

--abbrev, --abbrev=len::

Abbreviate the object name. When using `--hash`, you do
not have to say `--hash --abbrev`; `--hash=len` would do.

-q, --quiet::

Do not print any results to stdout. When combined with '--verify' this
can be used to silently check if a reference exists.

<pattern>::

Show references matching one or more patterns.

OUTPUT
------

The output is in the format: '<SHA-1 ID>' '<space>' '<reference name>'.

-----------------------------------------------------------------------------
$ git show-ref --head --dereference
832e76a9899f560a90ffd62ae2ce83bbeff58f54 HEAD
832e76a9899f560a90ffd62ae2ce83bbeff58f54 refs/heads/master
832e76a9899f560a90ffd62ae2ce83bbeff58f54 refs/heads/origin
3521017556c5de4159da4615a39fa4d5d2c279b5 refs/tags/v0.99.9c
6ddc0964034342519a87fe013781abf31c6db6ad refs/tags/v0.99.9c^{}
055e4ae3ae6eb344cbabf2a5256a49ea66040131 refs/tags/v1.0rc4
423325a2d24638ddcc82ce47be5e40be550f4507 refs/tags/v1.0rc4^{}
...
-----------------------------------------------------------------------------

When using --hash (and not --dereference) the output format is: '<SHA-1 ID>'

-----------------------------------------------------------------------------
$ git show-ref --heads --hash
2e3ba0114a1f52b47df29743d6915d056be13278
185008ae97960c8d551adcd9e23565194651b5d1
03adf42c988195b50e1a1935ba5fcbc39b2b029b
...
-----------------------------------------------------------------------------

EXAMPLE
-------

To show all references called "master", whether tags or heads or anything
else, and regardless of how deep in the reference naming hierarchy they are,
use:

-----------------------------------------------------------------------------
git show-ref master
-----------------------------------------------------------------------------

This will show "refs/heads/master" but also "refs/remote/other-repo/master",
if such references exists.

When using the '--verify' flag, the command requires an exact path:

-----------------------------------------------------------------------------
git show-ref --verify refs/heads/master
-----------------------------------------------------------------------------

will only match the exact branch called "master".

If nothing matches, gitlink:git-show-ref[1] will return an error code of 1,
and in the case of verification, it will show an error message.

For scripting, you can ask it to be quiet with the "--quiet" flag, which
allows you to do things like

-----------------------------------------------------------------------------
git-show-ref --quiet --verify -- "refs/heads/$headname" ||
echo "$headname is not a valid branch"
-----------------------------------------------------------------------------

to check whether a particular branch exists or not (notice how we don't
actually want to show any results, and we want to use the full refname for it
in order to not trigger the problem with ambiguous partial matches).

To show only tags, or only proper branch heads, use "--tags" and/or "--heads"
respectively (using both means that it shows tags and heads, but not other
random references under the refs/ subdirectory).

To do automatic tag object dereferencing, use the "-d" or "--dereference"
flag, so you can do

-----------------------------------------------------------------------------
git show-ref --tags --dereference
-----------------------------------------------------------------------------

to get a listing of all tags together with what they dereference.

SEE ALSO
--------
gitlink:git-ls-remote[1], gitlink:git-peek-remote[1]

AUTHORS
-------
Written by Linus Torvalds <torvalds@osdl.org>.
Man page by Jonas Fonseca <fonseca@diku.dk>.

GIT
---
Part of the gitlink:git[7] suite
10 changes: 8 additions & 2 deletions Documentation/git-update-ref.txt
Expand Up @@ -7,7 +7,7 @@ git-update-ref - update the object name stored in a ref safely

SYNOPSIS
--------
'git-update-ref' [-m <reason>] <ref> <newvalue> [<oldvalue>]
'git-update-ref' [-m <reason>] (-d <ref> <oldvalue> | <ref> <newvalue> [<oldvalue>])

DESCRIPTION
-----------
Expand All @@ -20,7 +20,9 @@ possibly dereferencing the symbolic refs, after verifying that
the current value of the <ref> matches <oldvalue>.
E.g. `git-update-ref refs/heads/master <newvalue> <oldvalue>`
updates the master branch head to <newvalue> only if its current
value is <oldvalue>.
value is <oldvalue>. You can specify 40 "0" or an empty string
as <oldvalue> to make sure that the ref you are creating does
not exist.

It also allows a "ref" file to be a symbolic pointer to another
ref file by starting with the four-byte header sequence of
Expand Down Expand Up @@ -49,6 +51,10 @@ for reading but not for writing (so we'll never write through a
ref symlink to some other tree, if you have copied a whole
archive by creating a symlink tree).

With `-d` flag, it deletes the named <ref> after verifying it
still contains <oldvalue>.


Logging Updates
---------------
If config parameter "core.logAllRefUpdates" is true or the file
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Expand Up @@ -158,7 +158,7 @@ BASIC_CFLAGS =
BASIC_LDFLAGS =

SCRIPT_SH = \
git-bisect.sh git-branch.sh git-checkout.sh \
git-bisect.sh git-checkout.sh \
git-cherry.sh git-clean.sh git-clone.sh git-commit.sh \
git-fetch.sh \
git-ls-remote.sh \
Expand Down Expand Up @@ -270,6 +270,7 @@ BUILTIN_OBJS = \
builtin-annotate.o \
builtin-apply.o \
builtin-archive.o \
builtin-branch.o \
builtin-cat-file.o \
builtin-checkout-index.o \
builtin-check-ref-format.o \
Expand Down Expand Up @@ -310,7 +311,9 @@ BUILTIN_OBJS = \
builtin-update-ref.o \
builtin-upload-archive.o \
builtin-verify-pack.o \
builtin-write-tree.o
builtin-write-tree.o \
builtin-show-ref.o \
builtin-pack-refs.o

GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
EXTLIBS = -lz
Expand Down

0 comments on commit 58a1e0e

Please sign in to comment.