builtin-symbolic-ref.con commit merge: loosen overcautious "working file will be lost" check. (ed93b44)
   1#include "builtin.h"
   2#include "cache.h"
   3
   4static const char git_symbolic_ref_usage[] =
   5"git-symbolic-ref name [ref]";
   6
   7static void check_symref(const char *HEAD)
   8{
   9        unsigned char sha1[20];
  10        const char *git_HEAD = xstrdup(git_path("%s", HEAD));
  11        const char *git_refs_heads_master = resolve_ref(git_HEAD, sha1, 0);
  12        if (git_refs_heads_master) {
  13                /* we want to strip the .git/ part */
  14                int pfxlen = strlen(git_HEAD) - strlen(HEAD);
  15                puts(git_refs_heads_master + pfxlen);
  16        }
  17        else
  18                die("No such ref: %s", HEAD);
  19}
  20
  21int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
  22{
  23        git_config(git_default_config);
  24        switch (argc) {
  25        case 2:
  26                check_symref(argv[1]);
  27                break;
  28        case 3:
  29                create_symref(xstrdup(git_path("%s", argv[1])), argv[2]);
  30                break;
  31        default:
  32                usage(git_symbolic_ref_usage);
  33        }
  34        return 0;
  35}