~ubuntu-branches/ubuntu/intrepid/git-core/intrepid-updates

« back to all changes in this revision

Viewing changes to builtin-symbolic-ref.c

  • Committer: Package Import Robot
  • Author(s): Gerrit Pape
  • Date: 2007-04-22 13:31:05 UTC
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: package-import@ubuntu.com-20070422133105-xg8fnm18r2cxcbg1
Tags: upstream-1.5.1.2
ImportĀ upstreamĀ versionĀ 1.5.1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
#include "refs.h"
4
4
 
5
5
static const char git_symbolic_ref_usage[] =
6
 
"git-symbolic-ref name [ref]";
 
6
"git-symbolic-ref [-q] [-m <reason>] name [ref]";
7
7
 
8
 
static void check_symref(const char *HEAD)
 
8
static void check_symref(const char *HEAD, int quiet)
9
9
{
10
10
        unsigned char sha1[20];
11
11
        int flag;
13
13
 
14
14
        if (!refs_heads_master)
15
15
                die("No such ref: %s", HEAD);
16
 
        else if (!(flag & REF_ISSYMREF))
17
 
                die("ref %s is not a symbolic ref", 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
        }
18
22
        puts(refs_heads_master);
19
23
}
20
24
 
21
25
int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
22
26
{
 
27
        int quiet = 0;
 
28
        const char *msg = NULL;
 
29
 
23
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
                        if (strchr(msg, '\n'))
 
47
                                die("Refusing to perform update with \\n in message");
 
48
                }
 
49
                else if (!strcmp("--", arg)) {
 
50
                        argc--;
 
51
                        argv++;
 
52
                        break;
 
53
                }
 
54
                else
 
55
                        die("unknown option %s", arg);
 
56
                argc--;
 
57
                argv++;
 
58
        }
 
59
 
24
60
        switch (argc) {
25
61
        case 2:
26
 
                check_symref(argv[1]);
 
62
                check_symref(argv[1], quiet);
27
63
                break;
28
64
        case 3:
29
 
                create_symref(argv[1], argv[2]);
 
65
                create_symref(argv[1], argv[2], msg);
30
66
                break;
31
67
        default:
32
68
                usage(git_symbolic_ref_usage);