@matheusbsbs / matheus-bagliano / commits / 3fe8dce6fc
Fork 0

Make old sha1 optional with git update-ref -d

Giving the old sha1 is already optional when changing a ref, and it's quite handy when running update-ref manually. So make it optional for deleting a ref too. Signed-off-by: Karl Hasselström <kha@treskal.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Karl Hasselström committed Jun 3, 2008 at 01:34 UTC 3fe8dce6fc5b1d0bffba8fdb4e075fcd16cf5619
3 files changed +12 -4
Documentation/git-update-ref.txt
+1 -1
@@ -7,7 +7,7 @@ git-update-ref - Update the object name stored in a ref safely
7
8 SYNOPSIS
9 --------
10 -'git-update-ref' [-m <reason>] (-d <ref> <oldvalue> | [--no-deref] <ref> <newvalue> [<oldvalue>])
10 +'git-update-ref' [-m <reason>] (-d <ref> [<oldvalue>] | [--no-deref] <ref> <newvalue> [<oldvalue>])
11
12 DESCRIPTION
13 -----------
builtin-update-ref.c
+3 -3
@@ -4,7 +4,7 @@
4 #include "parse-options.h"
5
6 static const char * const git_update_ref_usage[] = {
7 - "git-update-ref [options] -d <refname> <oldval>",
7 + "git-update-ref [options] -d <refname> [<oldval>]",
8 "git-update-ref [options] <refname> <newval> [<oldval>]",
9 NULL
10 };
@@ -28,7 +28,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
28 die("Refusing to perform update with empty message.");
29
30 if (delete) {
31 - if (argc != 2)
31 + if (argc < 1 || argc > 2)
32 usage_with_options(git_update_ref_usage, options);
33 refname = argv[0];
34 oldval = argv[1];
@@ -48,7 +48,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
48 die("%s: not a valid old SHA1", oldval);
49
50 if (delete)
51 - return delete_ref(refname, oldsha1);
51 + return delete_ref(refname, oldval ? oldsha1 : NULL);
52 else
53 return update_ref(msg, refname, sha1, oldval ? oldsha1 : NULL,
54 no_deref ? REF_NODEREF : 0, DIE_ON_ERR);
t/t1400-update-ref.sh
+8
@@ -42,6 +42,14 @@ test_expect_success "delete $m" '
42 '
43 rm -f .git/$m
44
45 +test_expect_success "delete $m without oldvalue verification" "
46 + git update-ref $m $A &&
47 + test $A = \$(cat .git/$m) &&
48 + git update-ref -d $m &&
49 + ! test -f .git/$m
50 +"
51 +rm -f .git/$m
52 +
53 test_expect_success \
54 "fail to create $n" \
55 "touch .git/$n_dir