2007-07-15 07:14:45 +08:00
|
|
|
#include "builtin.h"
|
Add "git show-ref" builtin command
It's kind of like "git peek-remote", but works only locally (and thus
avoids the whole overhead of git_connect()) and has some extra
verification features.
For example, it allows you to filter the results, and to choose whether
you want the tag dereferencing or not. You can also use it to just test
whether a particular ref exists.
For example:
git show-ref master
will show all references called "master", whether tags or heads or
anything else, and regardless of how deep in the reference naming
hierarchy they are (so it would show "refs/heads/master" but also
"refs/remote/other-repo/master").
When using the "--verify" flag, the command requires an exact ref path:
git show-ref --verify refs/heads/master
will only match the exact branch called "master".
If nothing matches, show-ref 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.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-16 02:19:32 +08:00
|
|
|
#include "cache.h"
|
|
|
|
#include "refs.h"
|
|
|
|
#include "object.h"
|
|
|
|
#include "tag.h"
|
2008-07-22 02:03:49 +08:00
|
|
|
#include "string-list.h"
|
2009-06-21 12:40:46 +08:00
|
|
|
#include "parse-options.h"
|
Add "git show-ref" builtin command
It's kind of like "git peek-remote", but works only locally (and thus
avoids the whole overhead of git_connect()) and has some extra
verification features.
For example, it allows you to filter the results, and to choose whether
you want the tag dereferencing or not. You can also use it to just test
whether a particular ref exists.
For example:
git show-ref master
will show all references called "master", whether tags or heads or
anything else, and regardless of how deep in the reference naming
hierarchy they are (so it would show "refs/heads/master" but also
"refs/remote/other-repo/master").
When using the "--verify" flag, the command requires an exact ref path:
git show-ref --verify refs/heads/master
will only match the exact branch called "master".
If nothing matches, show-ref 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.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-16 02:19:32 +08:00
|
|
|
|
2009-06-21 12:40:46 +08:00
|
|
|
static const char * const show_ref_usage[] = {
|
2015-01-13 15:44:47 +08:00
|
|
|
N_("git show-ref [-q | --quiet] [--verify] [--head] [-d | --dereference] [-s | --hash[=<n>]] [--abbrev[=<n>]] [--tags] [--heads] [--] [<pattern>...]"),
|
usage: do not insist that standard input must come from a file
The synopsys text and the usage string of subcommands that read list
of things from the standard input are often shown like this:
git gostak [--distim] < <list-of-doshes>
This is problematic in a number of ways:
* The way to use these commands is more often to feed them the
output from another command, not feed them from a file.
* Manual pages outside Git, commands that operate on the data read
from the standard input, e.g "sort", "grep", "sed", etc., are not
described with such a "< redirection-from-file" in their synopsys
text. Our doing so introduces inconsistency.
* We do not insist on where the output should go, by saying
git gostak [--distim] < <list-of-doshes> > <output>
* As it is our convention to enclose placeholders inside <braket>,
the redirection operator followed by a placeholder filename
becomes very hard to read, both in the documentation and in the
help text.
Let's clean them all up, after making sure that the documentation
clearly describes the modes that take information from the standard
input and what kind of things are expected on the input.
[jc: stole example for fmt-merge-msg from Jonathan]
Helped-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-10-17 02:27:42 +08:00
|
|
|
N_("git show-ref --exclude-existing[=<pattern>]"),
|
2009-06-21 12:40:46 +08:00
|
|
|
NULL
|
|
|
|
};
|
Add "git show-ref" builtin command
It's kind of like "git peek-remote", but works only locally (and thus
avoids the whole overhead of git_connect()) and has some extra
verification features.
For example, it allows you to filter the results, and to choose whether
you want the tag dereferencing or not. You can also use it to just test
whether a particular ref exists.
For example:
git show-ref master
will show all references called "master", whether tags or heads or
anything else, and regardless of how deep in the reference naming
hierarchy they are (so it would show "refs/heads/master" but also
"refs/remote/other-repo/master").
When using the "--verify" flag, the command requires an exact ref path:
git show-ref --verify refs/heads/master
will only match the exact branch called "master".
If nothing matches, show-ref 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.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-16 02:19:32 +08:00
|
|
|
|
2009-06-21 12:40:46 +08:00
|
|
|
static int deref_tags, show_head, tags_only, heads_only, found_match, verify,
|
|
|
|
quiet, hash_only, abbrev, exclude_arg;
|
Add "git show-ref" builtin command
It's kind of like "git peek-remote", but works only locally (and thus
avoids the whole overhead of git_connect()) and has some extra
verification features.
For example, it allows you to filter the results, and to choose whether
you want the tag dereferencing or not. You can also use it to just test
whether a particular ref exists.
For example:
git show-ref master
will show all references called "master", whether tags or heads or
anything else, and regardless of how deep in the reference naming
hierarchy they are (so it would show "refs/heads/master" but also
"refs/remote/other-repo/master").
When using the "--verify" flag, the command requires an exact ref path:
git show-ref --verify refs/heads/master
will only match the exact branch called "master".
If nothing matches, show-ref 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.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-16 02:19:32 +08:00
|
|
|
static const char **pattern;
|
2009-06-21 12:40:46 +08:00
|
|
|
static const char *exclude_existing_arg;
|
Add "git show-ref" builtin command
It's kind of like "git peek-remote", but works only locally (and thus
avoids the whole overhead of git_connect()) and has some extra
verification features.
For example, it allows you to filter the results, and to choose whether
you want the tag dereferencing or not. You can also use it to just test
whether a particular ref exists.
For example:
git show-ref master
will show all references called "master", whether tags or heads or
anything else, and regardless of how deep in the reference naming
hierarchy they are (so it would show "refs/heads/master" but also
"refs/remote/other-repo/master").
When using the "--verify" flag, the command requires an exact ref path:
git show-ref --verify refs/heads/master
will only match the exact branch called "master".
If nothing matches, show-ref 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.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-16 02:19:32 +08:00
|
|
|
|
2015-05-26 02:38:51 +08:00
|
|
|
static void show_one(const char *refname, const struct object_id *oid)
|
2006-12-18 11:27:49 +08:00
|
|
|
{
|
2017-01-24 02:00:56 +08:00
|
|
|
const char *hex;
|
|
|
|
struct object_id peeled;
|
|
|
|
|
2017-01-24 02:00:58 +08:00
|
|
|
if (!has_sha1_file(oid->hash))
|
|
|
|
die("git show-ref: bad ref %s (%s)", refname,
|
|
|
|
oid_to_hex(oid));
|
|
|
|
|
2017-01-24 02:00:57 +08:00
|
|
|
if (quiet)
|
|
|
|
return;
|
|
|
|
|
2017-01-24 02:00:56 +08:00
|
|
|
hex = find_unique_abbrev(oid->hash, abbrev);
|
2006-12-18 11:27:49 +08:00
|
|
|
if (hash_only)
|
|
|
|
printf("%s\n", hex);
|
|
|
|
else
|
|
|
|
printf("%s %s\n", hex, refname);
|
2017-01-24 02:00:56 +08:00
|
|
|
|
|
|
|
if (!deref_tags)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!peel_ref(refname, peeled.hash)) {
|
|
|
|
hex = find_unique_abbrev(peeled.hash, abbrev);
|
|
|
|
printf("%s %s^{}\n", hex, refname);
|
|
|
|
}
|
2006-12-18 11:27:49 +08:00
|
|
|
}
|
|
|
|
|
2015-05-26 02:38:51 +08:00
|
|
|
static int show_ref(const char *refname, const struct object_id *oid,
|
|
|
|
int flag, void *cbdata)
|
Add "git show-ref" builtin command
It's kind of like "git peek-remote", but works only locally (and thus
avoids the whole overhead of git_connect()) and has some extra
verification features.
For example, it allows you to filter the results, and to choose whether
you want the tag dereferencing or not. You can also use it to just test
whether a particular ref exists.
For example:
git show-ref master
will show all references called "master", whether tags or heads or
anything else, and regardless of how deep in the reference naming
hierarchy they are (so it would show "refs/heads/master" but also
"refs/remote/other-repo/master").
When using the "--verify" flag, the command requires an exact ref path:
git show-ref --verify refs/heads/master
will only match the exact branch called "master".
If nothing matches, show-ref 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.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-16 02:19:32 +08:00
|
|
|
{
|
2013-07-17 08:05:14 +08:00
|
|
|
if (show_head && !strcmp(refname, "HEAD"))
|
|
|
|
goto match;
|
|
|
|
|
Add "git show-ref" builtin command
It's kind of like "git peek-remote", but works only locally (and thus
avoids the whole overhead of git_connect()) and has some extra
verification features.
For example, it allows you to filter the results, and to choose whether
you want the tag dereferencing or not. You can also use it to just test
whether a particular ref exists.
For example:
git show-ref master
will show all references called "master", whether tags or heads or
anything else, and regardless of how deep in the reference naming
hierarchy they are (so it would show "refs/heads/master" but also
"refs/remote/other-repo/master").
When using the "--verify" flag, the command requires an exact ref path:
git show-ref --verify refs/heads/master
will only match the exact branch called "master".
If nothing matches, show-ref 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.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-16 02:19:32 +08:00
|
|
|
if (tags_only || heads_only) {
|
|
|
|
int match;
|
|
|
|
|
2013-12-01 04:55:40 +08:00
|
|
|
match = heads_only && starts_with(refname, "refs/heads/");
|
|
|
|
match |= tags_only && starts_with(refname, "refs/tags/");
|
Add "git show-ref" builtin command
It's kind of like "git peek-remote", but works only locally (and thus
avoids the whole overhead of git_connect()) and has some extra
verification features.
For example, it allows you to filter the results, and to choose whether
you want the tag dereferencing or not. You can also use it to just test
whether a particular ref exists.
For example:
git show-ref master
will show all references called "master", whether tags or heads or
anything else, and regardless of how deep in the reference naming
hierarchy they are (so it would show "refs/heads/master" but also
"refs/remote/other-repo/master").
When using the "--verify" flag, the command requires an exact ref path:
git show-ref --verify refs/heads/master
will only match the exact branch called "master".
If nothing matches, show-ref 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.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-16 02:19:32 +08:00
|
|
|
if (!match)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (pattern) {
|
|
|
|
int reflen = strlen(refname);
|
|
|
|
const char **p = pattern, *m;
|
|
|
|
while ((m = *p++) != NULL) {
|
|
|
|
int len = strlen(m);
|
|
|
|
if (len > reflen)
|
|
|
|
continue;
|
|
|
|
if (memcmp(m, refname + reflen - len, len))
|
|
|
|
continue;
|
|
|
|
if (len == reflen)
|
|
|
|
goto match;
|
|
|
|
if (refname[reflen - len - 1] == '/')
|
|
|
|
goto match;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
match:
|
|
|
|
found_match++;
|
2006-11-20 05:22:44 +08:00
|
|
|
|
2015-05-26 02:38:51 +08:00
|
|
|
show_one(refname, oid);
|
2006-11-20 05:22:44 +08:00
|
|
|
|
Add "git show-ref" builtin command
It's kind of like "git peek-remote", but works only locally (and thus
avoids the whole overhead of git_connect()) and has some extra
verification features.
For example, it allows you to filter the results, and to choose whether
you want the tag dereferencing or not. You can also use it to just test
whether a particular ref exists.
For example:
git show-ref master
will show all references called "master", whether tags or heads or
anything else, and regardless of how deep in the reference naming
hierarchy they are (so it would show "refs/heads/master" but also
"refs/remote/other-repo/master").
When using the "--verify" flag, the command requires an exact ref path:
git show-ref --verify refs/heads/master
will only match the exact branch called "master".
If nothing matches, show-ref 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.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-16 02:19:32 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-26 02:38:51 +08:00
|
|
|
static int add_existing(const char *refname, const struct object_id *oid,
|
|
|
|
int flag, void *cbdata)
|
2006-12-18 09:57:19 +08:00
|
|
|
{
|
2008-07-22 02:03:49 +08:00
|
|
|
struct string_list *list = (struct string_list *)cbdata;
|
2010-06-26 07:41:35 +08:00
|
|
|
string_list_insert(list, refname);
|
2006-12-18 09:57:19 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* read "^(?:<anything>\s)?<refname>(?:\^\{\})?$" from the standard input,
|
|
|
|
* and
|
|
|
|
* (1) strip "^{}" at the end of line if any;
|
|
|
|
* (2) ignore if match is provided and does not head-match refname;
|
|
|
|
* (3) warn if refname is not a well-formed refname and skip;
|
|
|
|
* (4) ignore if refname is a ref that exists in the local repository;
|
|
|
|
* (5) otherwise output the line.
|
|
|
|
*/
|
|
|
|
static int exclude_existing(const char *match)
|
|
|
|
{
|
2013-05-25 17:08:22 +08:00
|
|
|
static struct string_list existing_refs = STRING_LIST_INIT_DUP;
|
2006-12-18 09:57:19 +08:00
|
|
|
char buf[1024];
|
|
|
|
int matchlen = match ? strlen(match) : 0;
|
|
|
|
|
2015-05-26 02:38:51 +08:00
|
|
|
for_each_ref(add_existing, &existing_refs);
|
2006-12-18 09:57:19 +08:00
|
|
|
while (fgets(buf, sizeof(buf), stdin)) {
|
|
|
|
char *ref;
|
2006-12-19 05:33:47 +08:00
|
|
|
int len = strlen(buf);
|
|
|
|
|
2006-12-18 09:57:19 +08:00
|
|
|
if (len > 0 && buf[len - 1] == '\n')
|
|
|
|
buf[--len] = '\0';
|
2006-12-19 05:33:47 +08:00
|
|
|
if (3 <= len && !strcmp(buf + len - 3, "^{}")) {
|
2006-12-18 09:57:19 +08:00
|
|
|
len -= 3;
|
|
|
|
buf[len] = '\0';
|
|
|
|
}
|
|
|
|
for (ref = buf + len; buf < ref; ref--)
|
|
|
|
if (isspace(ref[-1]))
|
|
|
|
break;
|
|
|
|
if (match) {
|
|
|
|
int reflen = buf + len - ref;
|
|
|
|
if (reflen < matchlen)
|
|
|
|
continue;
|
|
|
|
if (strncmp(ref, match, matchlen))
|
|
|
|
continue;
|
|
|
|
}
|
2011-09-16 05:10:25 +08:00
|
|
|
if (check_refname_format(ref, 0)) {
|
2009-03-24 09:09:16 +08:00
|
|
|
warning("ref '%s' ignored", ref);
|
2006-12-18 09:57:19 +08:00
|
|
|
continue;
|
|
|
|
}
|
2008-07-22 02:03:49 +08:00
|
|
|
if (!string_list_has_string(&existing_refs, ref)) {
|
2006-12-18 09:57:19 +08:00
|
|
|
printf("%s\n", buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-21 12:40:46 +08:00
|
|
|
static int hash_callback(const struct option *opt, const char *arg, int unset)
|
|
|
|
{
|
|
|
|
hash_only = 1;
|
|
|
|
/* Use full length SHA1 if no argument */
|
|
|
|
if (!arg)
|
|
|
|
return 0;
|
|
|
|
return parse_opt_abbrev_cb(opt, arg, unset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int exclude_existing_callback(const struct option *opt, const char *arg,
|
|
|
|
int unset)
|
|
|
|
{
|
|
|
|
exclude_arg = 1;
|
|
|
|
*(const char **)opt->value = arg;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct option show_ref_options[] = {
|
2013-08-03 19:51:19 +08:00
|
|
|
OPT_BOOL(0, "tags", &tags_only, N_("only show tags (can be combined with heads)")),
|
|
|
|
OPT_BOOL(0, "heads", &heads_only, N_("only show heads (can be combined with tags)")),
|
|
|
|
OPT_BOOL(0, "verify", &verify, N_("stricter reference checking, "
|
2012-08-20 20:32:45 +08:00
|
|
|
"requires exact ref path")),
|
2013-08-03 19:51:18 +08:00
|
|
|
OPT_HIDDEN_BOOL('h', NULL, &show_head,
|
|
|
|
N_("show the HEAD reference, even if it would be filtered out")),
|
2013-08-03 19:51:19 +08:00
|
|
|
OPT_BOOL(0, "head", &show_head,
|
2013-07-17 08:05:14 +08:00
|
|
|
N_("show the HEAD reference, even if it would be filtered out")),
|
2013-08-03 19:51:19 +08:00
|
|
|
OPT_BOOL('d', "dereference", &deref_tags,
|
2012-08-20 20:32:45 +08:00
|
|
|
N_("dereference tags into object IDs")),
|
|
|
|
{ OPTION_CALLBACK, 's', "hash", &abbrev, N_("n"),
|
|
|
|
N_("only show SHA1 hash using <n> digits"),
|
2009-06-21 12:40:46 +08:00
|
|
|
PARSE_OPT_OPTARG, &hash_callback },
|
|
|
|
OPT__ABBREV(&abbrev),
|
2010-11-09 03:54:48 +08:00
|
|
|
OPT__QUIET(&quiet,
|
2012-08-20 20:32:45 +08:00
|
|
|
N_("do not print results to stdout (useful with --verify)")),
|
2009-06-21 12:40:46 +08:00
|
|
|
{ OPTION_CALLBACK, 0, "exclude-existing", &exclude_existing_arg,
|
2012-08-20 20:32:45 +08:00
|
|
|
N_("pattern"), N_("show refs from stdin that aren't in local repository"),
|
2009-06-21 12:40:46 +08:00
|
|
|
PARSE_OPT_OPTARG | PARSE_OPT_NONEG, exclude_existing_callback },
|
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
Add "git show-ref" builtin command
It's kind of like "git peek-remote", but works only locally (and thus
avoids the whole overhead of git_connect()) and has some extra
verification features.
For example, it allows you to filter the results, and to choose whether
you want the tag dereferencing or not. You can also use it to just test
whether a particular ref exists.
For example:
git show-ref master
will show all references called "master", whether tags or heads or
anything else, and regardless of how deep in the reference naming
hierarchy they are (so it would show "refs/heads/master" but also
"refs/remote/other-repo/master").
When using the "--verify" flag, the command requires an exact ref path:
git show-ref --verify refs/heads/master
will only match the exact branch called "master".
If nothing matches, show-ref 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.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-16 02:19:32 +08:00
|
|
|
int cmd_show_ref(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
2009-06-21 12:40:46 +08:00
|
|
|
argc = parse_options(argc, argv, prefix, show_ref_options,
|
2015-11-17 18:26:05 +08:00
|
|
|
show_ref_usage, 0);
|
Add "git show-ref" builtin command
It's kind of like "git peek-remote", but works only locally (and thus
avoids the whole overhead of git_connect()) and has some extra
verification features.
For example, it allows you to filter the results, and to choose whether
you want the tag dereferencing or not. You can also use it to just test
whether a particular ref exists.
For example:
git show-ref master
will show all references called "master", whether tags or heads or
anything else, and regardless of how deep in the reference naming
hierarchy they are (so it would show "refs/heads/master" but also
"refs/remote/other-repo/master").
When using the "--verify" flag, the command requires an exact ref path:
git show-ref --verify refs/heads/master
will only match the exact branch called "master".
If nothing matches, show-ref 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.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-16 02:19:32 +08:00
|
|
|
|
2009-06-21 12:40:46 +08:00
|
|
|
if (exclude_arg)
|
|
|
|
return exclude_existing(exclude_existing_arg);
|
|
|
|
|
|
|
|
pattern = argv;
|
|
|
|
if (!*pattern)
|
|
|
|
pattern = NULL;
|
2006-12-18 10:08:52 +08:00
|
|
|
|
|
|
|
if (verify) {
|
2007-02-24 01:12:33 +08:00
|
|
|
if (!pattern)
|
|
|
|
die("--verify requires a reference");
|
2006-12-18 10:08:52 +08:00
|
|
|
while (*pattern) {
|
2015-05-26 02:38:51 +08:00
|
|
|
struct object_id oid;
|
2007-02-24 01:12:33 +08:00
|
|
|
|
2017-01-24 02:00:55 +08:00
|
|
|
if ((starts_with(*pattern, "refs/") || !strcmp(*pattern, "HEAD")) &&
|
2015-05-26 02:38:51 +08:00
|
|
|
!read_ref(*pattern, oid.hash)) {
|
2017-01-24 02:00:57 +08:00
|
|
|
show_one(*pattern, &oid);
|
2006-12-18 10:53:24 +08:00
|
|
|
}
|
2006-12-18 10:08:52 +08:00
|
|
|
else if (!quiet)
|
|
|
|
die("'%s' - not a valid ref", *pattern);
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
pattern++;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Add "git show-ref" builtin command
It's kind of like "git peek-remote", but works only locally (and thus
avoids the whole overhead of git_connect()) and has some extra
verification features.
For example, it allows you to filter the results, and to choose whether
you want the tag dereferencing or not. You can also use it to just test
whether a particular ref exists.
For example:
git show-ref master
will show all references called "master", whether tags or heads or
anything else, and regardless of how deep in the reference naming
hierarchy they are (so it would show "refs/heads/master" but also
"refs/remote/other-repo/master").
When using the "--verify" flag, the command requires an exact ref path:
git show-ref --verify refs/heads/master
will only match the exact branch called "master".
If nothing matches, show-ref 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.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-16 02:19:32 +08:00
|
|
|
if (show_head)
|
2015-05-26 02:38:51 +08:00
|
|
|
head_ref(show_ref, NULL);
|
|
|
|
for_each_ref(show_ref, NULL);
|
Add "git show-ref" builtin command
It's kind of like "git peek-remote", but works only locally (and thus
avoids the whole overhead of git_connect()) and has some extra
verification features.
For example, it allows you to filter the results, and to choose whether
you want the tag dereferencing or not. You can also use it to just test
whether a particular ref exists.
For example:
git show-ref master
will show all references called "master", whether tags or heads or
anything else, and regardless of how deep in the reference naming
hierarchy they are (so it would show "refs/heads/master" but also
"refs/remote/other-repo/master").
When using the "--verify" flag, the command requires an exact ref path:
git show-ref --verify refs/heads/master
will only match the exact branch called "master".
If nothing matches, show-ref 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.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-16 02:19:32 +08:00
|
|
|
if (!found_match) {
|
|
|
|
if (verify && !quiet)
|
|
|
|
die("No match");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|