summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a552de7)
raw | patch | inline | side by side (parent: a552de7)
author | Junio C Hamano <gitster@pobox.com> | |
Sat, 21 Mar 2009 21:19:53 +0000 (14:19 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 23 Mar 2009 06:52:06 +0000 (23:52 -0700) |
The command may not be the best place to add this new feature, but
$ git check-ref-format --branch "@{-1}"
allows Porcelains to figure out what branch you were on before the last
branch switching.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
$ git check-ref-format --branch "@{-1}"
allows Porcelains to figure out what branch you were on before the last
branch switching.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-check-ref-format.txt | patch | blob | history | |
builtin-check-ref-format.c | patch | blob | history |
index 034223cc5ace81dd0b63da44d79db5e83a1d492a..51579f677602c34053f04a1d793e5df3dedd69fa 100644 (file)
SYNOPSIS
--------
+[verse]
'git check-ref-format' <refname>
+'git check-ref-format' [--branch] <branchname-shorthand>
DESCRIPTION
-----------
It may also be used to select a specific object such as with
'git-cat-file': "git cat-file blob v1.3.3:refs.c".
+With the `--branch` option, it expands a branch name shorthand and
+prints the name of the branch the shorthand refers to.
+
+EXAMPLE
+-------
+
+git check-ref-format --branch @{-1}::
+
+Print the name of the previous branch.
+
GIT
---
index 701de439ae0f508f3a8ab41559230357be60637e..39db6cbe47d77f84bd2d1d8d98942be89aaa1bf7 100644 (file)
#include "cache.h"
#include "refs.h"
#include "builtin.h"
+#include "strbuf.h"
int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
{
+ if (argc == 3 && !strcmp(argv[1], "--branch")) {
+ struct strbuf sb = STRBUF_INIT;
+ strbuf_branchname(&sb, argv[2]);
+ strbuf_splice(&sb, 0, 0, "refs/heads/", 11);
+ if (check_ref_format(sb.buf))
+ die("'%s' is not a valid branch name", argv[2]);
+ printf("%s\n", sb.buf + 11);
+ exit(0);
+ }
if (argc != 2)
usage("git check-ref-format refname");
return !!check_ref_format(argv[1]);