diff options
author | Junio C Hamano <gitster@pobox.com> | 2011-11-23 13:28:53 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-11-23 13:28:53 -0800 |
commit | 3686aa1caf907d22fe318c28efe93f0e7870ba50 (patch) | |
tree | f99a303bd14c7343be7ccc5b9df5382f1bf79246 /builtin/update-ref.c | |
parent | imap-send: Remove unused 'use_namespace' variable (diff) | |
parent | documentation fix: git difftool uses diff tools, not merge tools. (diff) | |
download | tgif-3686aa1caf907d22fe318c28efe93f0e7870ba50.tar.xz |
Merge branch 'maint' into tj/imap-send-remove-unused
* maint: (18123 commits)
documentation fix: git difftool uses diff tools, not merge tools.
Git 1.7.7.4
Makefile: add missing header file dependencies
notes merge: eliminate OUTPUT macro
mailmap: xcalloc mailmap_info
name-rev --all: do not even attempt to describe non-commit object
Git 1.7.7.3
docs: Update install-doc-quick
docs: don't mention --quiet or --exit-code in git-log(1)
Git 1.7.7.2
t7511: avoid use of reserved filename on Windows.
clone: Quote user supplied path in a single quote pair
read-cache.c: fix index memory allocation
make the sample pre-commit hook script reject names with newlines, too
Reindent closing bracket using tab instead of spaces
Git 1.7.7.1
RelNotes/1.7.7.1: setgid bit patch is about fixing "git init" via Makefile setting
gitweb: fix regression when filtering out forks
Almost ready for 1.7.7.1
pack-objects: don't traverse objects unnecessarily
...
Conflicts:
imap-send.c
Diffstat (limited to 'builtin/update-ref.c')
-rw-r--r-- | builtin/update-ref.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/builtin/update-ref.c b/builtin/update-ref.c new file mode 100644 index 0000000000..835c62ab15 --- /dev/null +++ b/builtin/update-ref.c @@ -0,0 +1,58 @@ +#include "cache.h" +#include "refs.h" +#include "builtin.h" +#include "parse-options.h" + +static const char * const git_update_ref_usage[] = { + "git update-ref [options] -d <refname> [<oldval>]", + "git update-ref [options] <refname> <newval> [<oldval>]", + NULL +}; + +int cmd_update_ref(int argc, const char **argv, const char *prefix) +{ + const char *refname, *oldval, *msg = NULL; + unsigned char sha1[20], oldsha1[20]; + int delete = 0, no_deref = 0, flags = 0; + 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(), + }; + + git_config(git_default_config, NULL); + argc = parse_options(argc, argv, prefix, options, git_update_ref_usage, + 0); + if (msg && !*msg) + die("Refusing to perform update with empty message."); + + if (delete) { + if (argc < 1 || argc > 2) + usage_with_options(git_update_ref_usage, options); + refname = argv[0]; + oldval = argv[1]; + } else { + const char *value; + if (argc < 2 || argc > 3) + usage_with_options(git_update_ref_usage, options); + refname = argv[0]; + value = argv[1]; + oldval = argv[2]; + if (get_sha1(value, sha1)) + die("%s: not a valid SHA1", value); + } + + hashclr(oldsha1); /* all-zero hash in case oldval is the empty string */ + if (oldval && *oldval && get_sha1(oldval, oldsha1)) + die("%s: not a valid old SHA1", oldval); + + if (no_deref) + flags = REF_NODEREF; + if (delete) + return delete_ref(refname, oldval ? oldsha1 : NULL, flags); + else + return update_ref(msg, refname, sha1, oldval ? oldsha1 : NULL, + flags, DIE_ON_ERR); +} |