4 static const char git_update_ref_usage[] =
5 "git-update-ref <refname> <value> [<oldval>] [-m <reason>]";
7 int main(int argc, char **argv)
9 const char *refname=NULL, *value=NULL, *oldval=NULL, *msg=NULL;
10 struct ref_lock *lock;
11 unsigned char sha1[20], oldsha1[20];
14 setup_git_directory();
15 git_config(git_default_config);
17 for (i = 1; i < argc; i++) {
18 if (!strcmp("-m", argv[i])) {
20 usage(git_update_ref_usage);
23 die("Refusing to perform update with empty message.");
24 if (strchr(msg, '\n'))
25 die("Refusing to perform update with \\n in message.");
41 if (!refname || !value)
42 usage(git_update_ref_usage);
44 if (get_sha1(value, sha1))
45 die("%s: not a valid SHA1", value);
46 memset(oldsha1, 0, 20);
47 if (oldval && get_sha1(oldval, oldsha1))
48 die("%s: not a valid old SHA1", oldval);
50 lock = lock_any_ref_for_update(refname, oldval ? oldsha1 : NULL, 0);
53 if (write_ref_sha1(lock, sha1, msg) < 0)