2006-08-03 17:24:38 +02:00
|
|
|
#include "builtin.h"
|
2005-09-30 23:26:57 +02:00
|
|
|
#include "cache.h"
|
2006-09-21 07:02:01 +02:00
|
|
|
#include "refs.h"
|
2005-09-30 23:26:57 +02:00
|
|
|
|
|
|
|
static const char git_symbolic_ref_usage[] =
|
2007-01-26 23:26:10 +01:00
|
|
|
"git-symbolic-ref [-q] [-m <reason>] name [ref]";
|
2005-09-30 23:26:57 +02:00
|
|
|
|
2007-01-15 22:56:05 +01:00
|
|
|
static void check_symref(const char *HEAD, int quiet)
|
2005-09-30 23:26:57 +02:00
|
|
|
{
|
|
|
|
unsigned char sha1[20];
|
2006-09-21 07:02:01 +02:00
|
|
|
int flag;
|
|
|
|
const char *refs_heads_master = resolve_ref(HEAD, sha1, 0, &flag);
|
2006-09-12 05:17:35 +02:00
|
|
|
|
|
|
|
if (!refs_heads_master)
|
2005-09-30 23:26:57 +02:00
|
|
|
die("No such ref: %s", HEAD);
|
2007-01-15 22:56:05 +01:00
|
|
|
else if (!(flag & REF_ISSYMREF)) {
|
|
|
|
if (!quiet)
|
|
|
|
die("ref %s is not a symbolic ref", HEAD);
|
|
|
|
else
|
|
|
|
exit(1);
|
|
|
|
}
|
2006-09-12 05:17:35 +02:00
|
|
|
puts(refs_heads_master);
|
2005-09-30 23:26:57 +02:00
|
|
|
}
|
|
|
|
|
2006-08-03 17:24:38 +02:00
|
|
|
int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
|
2005-09-30 23:26:57 +02:00
|
|
|
{
|
2007-01-15 22:56:05 +01:00
|
|
|
int quiet = 0;
|
2007-01-26 23:26:10 +01:00
|
|
|
const char *msg = NULL;
|
2007-01-15 22:56:05 +01:00
|
|
|
|
2005-11-17 06:32:44 +01:00
|
|
|
git_config(git_default_config);
|
2007-01-15 22:56:05 +01:00
|
|
|
|
|
|
|
while (1 < argc) {
|
|
|
|
const char *arg = argv[1];
|
|
|
|
if (arg[0] != '-')
|
|
|
|
break;
|
|
|
|
else if (!strcmp("-q", arg))
|
|
|
|
quiet = 1;
|
2007-01-26 23:26:10 +01:00
|
|
|
else if (!strcmp("-m", arg)) {
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
if (argc <= 1)
|
|
|
|
break;
|
|
|
|
msg = argv[1];
|
|
|
|
if (!*msg)
|
|
|
|
die("Refusing to perform update with empty message");
|
|
|
|
if (strchr(msg, '\n'))
|
|
|
|
die("Refusing to perform update with \\n in message");
|
|
|
|
}
|
2007-01-15 22:56:05 +01:00
|
|
|
else if (!strcmp("--", arg)) {
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
die("unknown option %s", arg);
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
|
2005-09-30 23:26:57 +02:00
|
|
|
switch (argc) {
|
|
|
|
case 2:
|
2007-01-15 22:56:05 +01:00
|
|
|
check_symref(argv[1], quiet);
|
2005-09-30 23:26:57 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
2007-01-26 23:26:10 +01:00
|
|
|
create_symref(argv[1], argv[2], msg);
|
2005-09-30 23:26:57 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage(git_symbolic_ref_usage);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|