You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.3 KiB
58 lines
1.3 KiB
19 years ago
|
#include "builtin.h"
|
||
20 years ago
|
#include "cache.h"
|
||
19 years ago
|
#include "refs.h"
|
||
17 years ago
|
#include "parse-options.h"
|
||
20 years ago
|
|
||
17 years ago
|
static const char * const git_symbolic_ref_usage[] = {
|
||
17 years ago
|
"git symbolic-ref [options] name [ref]",
|
||
17 years ago
|
NULL
|
||
|
};
|
||
20 years ago
|
|
||
18 years ago
|
static void check_symref(const char *HEAD, int quiet)
|
||
20 years ago
|
{
|
||
|
unsigned char sha1[20];
|
||
19 years ago
|
int flag;
|
||
|
const char *refs_heads_master = resolve_ref(HEAD, sha1, 0, &flag);
|
||
19 years ago
|
|
||
|
if (!refs_heads_master)
|
||
20 years ago
|
die("No such ref: %s", HEAD);
|
||
18 years ago
|
else if (!(flag & REF_ISSYMREF)) {
|
||
|
if (!quiet)
|
||
|
die("ref %s is not a symbolic ref", HEAD);
|
||
|
else
|
||
|
exit(1);
|
||
|
}
|
||
19 years ago
|
puts(refs_heads_master);
|
||
20 years ago
|
}
|
||
|
|
||
19 years ago
|
int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
|
||
20 years ago
|
{
|
||
18 years ago
|
int quiet = 0;
|
||
18 years ago
|
const char *msg = NULL;
|
||
17 years ago
|
struct option options[] = {
|
||
|
OPT__QUIET(&quiet),
|
||
|
OPT_STRING('m', NULL, &msg, "reason", "reason of the update"),
|
||
|
OPT_END(),
|
||
|
};
|
||
18 years ago
|
|
||
17 years ago
|
git_config(git_default_config, NULL);
|
||
16 years ago
|
argc = parse_options(argc, argv, prefix, options,
|
||
|
git_symbolic_ref_usage, 0);
|
||
17 years ago
|
if (msg &&!*msg)
|
||
|
die("Refusing to perform update with empty message");
|
||
20 years ago
|
switch (argc) {
|
||
17 years ago
|
case 1:
|
||
|
check_symref(argv[0], quiet);
|
||
20 years ago
|
break;
|
||
17 years ago
|
case 2:
|
||
16 years ago
|
if (!strcmp(argv[0], "HEAD") &&
|
||
16 years ago
|
prefixcmp(argv[1], "refs/"))
|
||
|
die("Refusing to point HEAD outside of refs/");
|
||
17 years ago
|
create_symref(argv[0], argv[1], msg);
|
||
20 years ago
|
break;
|
||
|
default:
|
||
17 years ago
|
usage_with_options(git_symbolic_ref_usage, options);
|
||
20 years ago
|
}
|
||
|
return 0;
|
||
|
}
|