branch: delete symref branch, not its target
If a branch that is to be deleted happens to be a symref to another branch, the current code removes the targeted branch instead of the one it was called for. Change this surprising behaviour and delete the symref branch instead. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Oct 18, 2012 at 14:05 UTC
566c7707db4eb18a116659b08d6ff7ad79fcfefd
2 files changed
+12
-1
builtin/branch.c
+1
-1
@@ -239,7 +239,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
239
continue;
240
}
241
242
- if (delete_ref(name, sha1, 0)) {
242
+ if (delete_ref(name, sha1, REF_NODEREF)) {
243
error(remote_branch
244
? _("Error deleting remote branch '%s'")
245
: _("Error deleting branch '%s'"),
t/t3200-branch.sh
+11
@@ -262,6 +262,17 @@ test_expect_success 'config information was renamed, too' \
262
"test $(git config branch.s.dummy) = Hello &&
263
test_must_fail git config branch.s/s/dummy"
264
265
+test_expect_success 'deleting a symref' '
266
+ git branch target &&
267
+ git symbolic-ref refs/heads/symref refs/heads/target &&
268
+ sha1=$(git rev-parse symref | cut -c 1-7) &&
269
+ echo "Deleted branch symref (was $sha1)." >expect &&
270
+ git branch -d symref >actual &&
271
+ test_path_is_file .git/refs/heads/target &&
272
+ test_path_is_missing .git/refs/heads/symref &&
273
+ test_i18ncmp expect actual
274
+'
275
+
276
test_expect_success 'renaming a symref is not allowed' \
277
'
278
git symbolic-ref refs/heads/master2 refs/heads/master &&