summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3724cc7)
raw | patch | inline | side by side (parent: 3724cc7)
author | Jan Krüger <jk@jk.gs> | |
Mon, 27 Feb 2012 22:10:38 +0000 (23:10 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 27 Feb 2012 23:58:36 +0000 (15:58 -0800) |
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>
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>
Documentation/git-symbolic-ref.txt | patch | blob | history | |
builtin/symbolic-ref.c | patch | blob | history |
index a45d4c4f29635a4fdcdeb2d15950925313920741..981d3a8fc12cde403cd2d29c86a63b56ca3028b3 100644 (file)
SYNOPSIS
--------
[verse]
-'git symbolic-ref' [-q] [-m <reason>] <name> [<ref>]
+'git symbolic-ref' [-m <reason>] <name> <ref>
+'git symbolic-ref' [-q] [--short] <name>
DESCRIPTION
-----------
symbolic ref but a detached HEAD; instead exit with
non-zero status silently.
+--short::
+ When showing the value of <name> as a symbolic ref, try to shorten the
+ value, e.g. from `refs/heads/master` to `master`.
+
-m::
Update the reflog for <name> with <reason>. This is valid only
when creating or updating a symbolic ref.
diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c
index 2ef5962386dcc21af94c680be5fd75fc96d4962f..801d62ece5d2ec84d027089c29fc58e279126ebb 100644 (file)
--- a/builtin/symbolic-ref.c
+++ b/builtin/symbolic-ref.c
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)
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)
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(),
};