Skip to content

Commit

Permalink
Merge branch 'jk/symbolic-ref-short'
Browse files Browse the repository at this point in the history
* jk/symbolic-ref-short:
  symbolic-ref --short: abbreviate the output unambiguously
  • Loading branch information
Junio C Hamano committed Mar 5, 2012
2 parents 6759f95 + 42b0059 commit b8b5290
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 6 additions & 1 deletion Documentation/git-symbolic-ref.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ git-symbolic-ref - Read and modify symbolic refs
SYNOPSIS
--------
[verse]
'git symbolic-ref' [-q] [-m <reason>] <name> [<ref>]
'git symbolic-ref' [-m <reason>] <name> <ref>
'git symbolic-ref' [-q] [--short] <name>

DESCRIPTION
-----------
Expand All @@ -33,6 +34,10 @@ OPTIONS
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.
Expand Down
11 changes: 8 additions & 3 deletions builtin/symbolic-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,25 @@ 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)
die("ref %s is not a symbolic ref", HEAD);
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)
Expand All @@ -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(),
};
Expand Down

0 comments on commit b8b5290

Please sign in to comment.