Fix git update-ref --no-deref -d.
Till now --no-deref was just ignored when deleting refs, fix this. Signed-off-by: Miklos Vajna <vmiklos@frugalware.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Miklos Vajna committed
Oct 26, 2008 at 03:33 UTC
569740bdd0533ef5cf032edd6233710161a35725
2 files changed
+12
-3
builtin-update-ref.c
+5
-3
@@ -13,7 +13,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
13
{
14
const char *refname, *oldval, *msg=NULL;
15
unsigned char sha1[20], oldsha1[20];
16
- int delete = 0, no_deref = 0;
16
+ int delete = 0, no_deref = 0, flags = 0;
17
struct option options[] = {
18
OPT_STRING( 'm', NULL, &msg, "reason", "reason of the update"),
19
OPT_BOOLEAN('d', NULL, &delete, "deletes the reference"),
@@ -47,9 +47,11 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
47
if (oldval && *oldval && get_sha1(oldval, oldsha1))
48
die("%s: not a valid old SHA1", oldval);
49
50
+ if (no_deref)
51
+ flags = REF_NODEREF;
52
if (delete)
51
- return delete_ref(refname, oldval ? oldsha1 : NULL, 0);
53
+ return delete_ref(refname, oldval ? oldsha1 : NULL, flags);
54
else
55
return update_ref(msg, refname, sha1, oldval ? oldsha1 : NULL,
54
- no_deref ? REF_NODEREF : 0, DIE_ON_ERR);
56
+ flags, DIE_ON_ERR);
57
}
t/t1400-update-ref.sh
+7
@@ -75,6 +75,13 @@ test_expect_success "delete $m (by HEAD)" '
75
'
76
rm -f .git/$m
77
78
+cp -f .git/HEAD .git/HEAD.orig
79
+test_expect_success "delete symref without dereference" '
80
+ git update-ref --no-deref -d HEAD &&
81
+ ! test -f .git/HEAD
82
+'
83
+cp -f .git/HEAD.orig .git/HEAD
84
+
85
test_expect_success '(not) create HEAD with old sha1' "
86
test_must_fail git update-ref HEAD $A $B
87
"