4 #include "parse-options.h"
6 static const char * const git_update_ref_usage[] = {
7 N_("git update-ref [options] -d <refname> [<oldval>]"),
8 N_("git update-ref [options] <refname> <newval> [<oldval>]"),
12 int cmd_update_ref(int argc, const char **argv, const char *prefix)
14 const char *refname, *oldval, *msg = NULL;
15 unsigned char sha1[20], oldsha1[20];
16 int delete = 0, no_deref = 0, flags = 0;
17 struct option options[] = {
18 OPT_STRING( 'm', NULL, &msg, N_("reason"), N_("reason of the update")),
19 OPT_BOOLEAN('d', NULL, &delete, N_("delete the reference")),
20 OPT_BOOLEAN( 0 , "no-deref", &no_deref,
21 N_("update <refname> not the one it points to")),
25 git_config(git_default_config, NULL);
26 argc = parse_options(argc, argv, prefix, options, git_update_ref_usage,
29 die("Refusing to perform update with empty message.");
32 if (argc < 1 || argc > 2)
33 usage_with_options(git_update_ref_usage, options);
38 if (argc < 2 || argc > 3)
39 usage_with_options(git_update_ref_usage, options);
43 if (get_sha1(value, sha1))
44 die("%s: not a valid SHA1", value);
47 hashclr(oldsha1); /* all-zero hash in case oldval is the empty string */
48 if (oldval && *oldval && get_sha1(oldval, oldsha1))
49 die("%s: not a valid old SHA1", oldval);
54 return delete_ref(refname, oldval ? oldsha1 : NULL, flags);
56 return update_ref(msg, refname, sha1, oldval ? oldsha1 : NULL,