summaryrefslogtreecommitdiff
path: root/builtin/symbolic-ref.c
diff options
context:
space:
mode:
authorJan Krüger <jk@jk.gs>2012-02-27 22:10:38 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-02-27 23:58:36 (GMT)
commit42b00599be684e20462c431a718f86c2b6fce575 (patch)
tree81d9579d42fbc12ea8dd3013f24319b6bce17531 /builtin/symbolic-ref.c
parent3724cc7c58df709cffbf6cc0701d1ca6fa5a5ba2 (diff)
downloadgit-42b00599be684e20462c431a718f86c2b6fce575.zip
git-42b00599be684e20462c431a718f86c2b6fce575.tar.gz
git-42b00599be684e20462c431a718f86c2b6fce575.tar.bz2
symbolic-ref --short: abbreviate the output unambiguously
It can be helpful to resolve a symbolic ref and output the result in a shortened form, such as for use in shell prompts. Add a "--short" option to do so. Signed-off-by: Jan Krüger <jk@jk.gs> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/symbolic-ref.c')
-rw-r--r--builtin/symbolic-ref.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c
index 2ef5962..801d62e 100644
--- a/builtin/symbolic-ref.c
+++ b/builtin/symbolic-ref.c
@@ -8,13 +8,15 @@ static const char * const git_symbolic_ref_usage[] = {
NULL
};
+static int shorten;
+
static void check_symref(const char *HEAD, int quiet)
{
unsigned char sha1[20];
int flag;
- const char *refs_heads_master = resolve_ref_unsafe(HEAD, sha1, 0, &flag);
+ const char *refname = resolve_ref_unsafe(HEAD, sha1, 0, &flag);
- if (!refs_heads_master)
+ if (!refname)
die("No such ref: %s", HEAD);
else if (!(flag & REF_ISSYMREF)) {
if (!quiet)
@@ -22,7 +24,9 @@ static void check_symref(const char *HEAD, int quiet)
else
exit(1);
}
- puts(refs_heads_master);
+ if (shorten)
+ refname = shorten_unambiguous_ref(refname, 0);
+ puts(refname);
}
int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
@@ -32,6 +36,7 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
struct option options[] = {
OPT__QUIET(&quiet,
"suppress error message for non-symbolic (detached) refs"),
+ OPT_BOOL(0, "short", &shorten, "shorten ref output"),
OPT_STRING('m', NULL, &msg, "reason", "reason of the update"),
OPT_END(),
};