builtin-symbolic-ref.con commit Remove unnecessary debugging from builtin-fetch (133296f)
   1#include "builtin.h"
   2#include "cache.h"
   3#include "refs.h"
   4
   5static const char git_symbolic_ref_usage[] =
   6"git-symbolic-ref [-q] [-m <reason>] name [ref]";
   7
   8static void check_symref(const char *HEAD, int quiet)
   9{
  10        unsigned char sha1[20];
  11        int flag;
  12        const char *refs_heads_master = resolve_ref(HEAD, sha1, 0, &flag);
  13
  14        if (!refs_heads_master)
  15                die("No such ref: %s", HEAD);
  16        else if (!(flag & REF_ISSYMREF)) {
  17                if (!quiet)
  18                        die("ref %s is not a symbolic ref", HEAD);
  19                else
  20                        exit(1);
  21        }
  22        puts(refs_heads_master);
  23}
  24
  25int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
  26{
  27        int quiet = 0;
  28        const char *msg = NULL;
  29
  30        git_config(git_default_config);
  31
  32        while (1 < argc) {
  33                const char *arg = argv[1];
  34                if (arg[0] != '-')
  35                        break;
  36                else if (!strcmp("-q", arg))
  37                        quiet = 1;
  38                else if (!strcmp("-m", arg)) {
  39                        argc--;
  40                        argv++;
  41                        if (argc <= 1)
  42                                break;
  43                        msg = argv[1];
  44                        if (!*msg)
  45                                die("Refusing to perform update with empty message");
  46                }
  47                else if (!strcmp("--", arg)) {
  48                        argc--;
  49                        argv++;
  50                        break;
  51                }
  52                else
  53                        die("unknown option %s", arg);
  54                argc--;
  55                argv++;
  56        }
  57
  58        switch (argc) {
  59        case 2:
  60                check_symref(argv[1], quiet);
  61                break;
  62        case 3:
  63                create_symref(argv[1], argv[2], msg);
  64                break;
  65        default:
  66                usage(git_symbolic_ref_usage);
  67        }
  68        return 0;
  69}