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.
59 lines
1.6 KiB
59 lines
1.6 KiB
20 years ago
|
#include "cache.h"
|
||
|
#include "refs.h"
|
||
19 years ago
|
#include "builtin.h"
|
||
17 years ago
|
#include "parse-options.h"
|
||
20 years ago
|
|
||
17 years ago
|
static const char * const git_update_ref_usage[] = {
|
||
17 years ago
|
"git update-ref [options] -d <refname> [<oldval>]",
|
||
|
"git update-ref [options] <refname> <newval> [<oldval>]",
|
||
17 years ago
|
NULL
|
||
|
};
|
||
20 years ago
|
|
||
19 years ago
|
int cmd_update_ref(int argc, const char **argv, const char *prefix)
|
||
20 years ago
|
{
|
||
17 years ago
|
const char *refname, *oldval, *msg=NULL;
|
||
19 years ago
|
unsigned char sha1[20], oldsha1[20];
|
||
16 years ago
|
int delete = 0, no_deref = 0, flags = 0;
|
||
17 years ago
|
struct option options[] = {
|
||
|
OPT_STRING( 'm', NULL, &msg, "reason", "reason of the update"),
|
||
|
OPT_BOOLEAN('d', NULL, &delete, "deletes the reference"),
|
||
|
OPT_BOOLEAN( 0 , "no-deref", &no_deref,
|
||
|
"update <refname> not the one it points to"),
|
||
|
OPT_END(),
|
||
|
};
|
||
20 years ago
|
|
||
17 years ago
|
git_config(git_default_config, NULL);
|
||
16 years ago
|
argc = parse_options(argc, argv, prefix, options, git_update_ref_usage,
|
||
|
0);
|
||
17 years ago
|
if (msg && !*msg)
|
||
|
die("Refusing to perform update with empty message.");
|
||
19 years ago
|
|
||
19 years ago
|
if (delete) {
|
||
17 years ago
|
if (argc < 1 || argc > 2)
|
||
17 years ago
|
usage_with_options(git_update_ref_usage, options);
|
||
|
refname = argv[0];
|
||
|
oldval = argv[1];
|
||
|
} else {
|
||
|
const char *value;
|
||
|
if (argc < 2 || argc > 3)
|
||
17 years ago
|
usage_with_options(git_update_ref_usage, options);
|
||
17 years ago
|
refname = argv[0];
|
||
|
value = argv[1];
|
||
|
oldval = argv[2];
|
||
|
if (get_sha1(value, sha1))
|
||
|
die("%s: not a valid SHA1", value);
|
||
19 years ago
|
}
|
||
|
|
||
17 years ago
|
hashclr(oldsha1); /* all-zero hash in case oldval is the empty string */
|
||
19 years ago
|
if (oldval && *oldval && get_sha1(oldval, oldsha1))
|
||
20 years ago
|
die("%s: not a valid old SHA1", oldval);
|
||
|
|
||
16 years ago
|
if (no_deref)
|
||
|
flags = REF_NODEREF;
|
||
17 years ago
|
if (delete)
|
||
16 years ago
|
return delete_ref(refname, oldval ? oldsha1 : NULL, flags);
|
||
17 years ago
|
else
|
||
|
return update_ref(msg, refname, sha1, oldval ? oldsha1 : NULL,
|
||
16 years ago
|
flags, DIE_ON_ERR);
|
||
20 years ago
|
}
|