Skip to content

Commit 569740b

Browse files
Miklos Vajnagitster
authored andcommitted
Fix git update-ref --no-deref -d.
Till now --no-deref was just ignored when deleting refs, fix this. Signed-off-by: Miklos Vajna <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 450d4c0 commit 569740b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

builtin-update-ref.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
1313
{
1414
const char *refname, *oldval, *msg=NULL;
1515
unsigned char sha1[20], oldsha1[20];
16-
int delete = 0, no_deref = 0;
16+
int delete = 0, no_deref = 0, flags = 0;
1717
struct option options[] = {
1818
OPT_STRING( 'm', NULL, &msg, "reason", "reason of the update"),
1919
OPT_BOOLEAN('d', NULL, &delete, "deletes the reference"),
@@ -47,9 +47,11 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
4747
if (oldval && *oldval && get_sha1(oldval, oldsha1))
4848
die("%s: not a valid old SHA1", oldval);
4949

50+
if (no_deref)
51+
flags = REF_NODEREF;
5052
if (delete)
51-
return delete_ref(refname, oldval ? oldsha1 : NULL, 0);
53+
return delete_ref(refname, oldval ? oldsha1 : NULL, flags);
5254
else
5355
return update_ref(msg, refname, sha1, oldval ? oldsha1 : NULL,
54-
no_deref ? REF_NODEREF : 0, DIE_ON_ERR);
56+
flags, DIE_ON_ERR);
5557
}

t/t1400-update-ref.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ test_expect_success "delete $m (by HEAD)" '
7575
'
7676
rm -f .git/$m
7777

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+
7885
test_expect_success '(not) create HEAD with old sha1' "
7986
test_must_fail git update-ref HEAD $A $B
8087
"

0 commit comments

Comments
 (0)