branch -d: avoid repeated symref resolution
commitf79a6d09c3878364c8f09430d51396bcff200bc8
authorJonathan Nieder <jrnieder@gmail.com>
Thu, 11 Sep 2014 01:22:48 +0000 (10 18:22 -0700)
committerJonathan Nieder <jrnieder@gmail.com>
Tue, 14 Oct 2014 23:37:06 +0000 (14 16:37 -0700)
tree609d4997c69205497bbd6103c0d76f49e22b91e8
parent715a377d93bec2cdb46e9f761d52c532c8982ea8
branch -d: avoid repeated symref resolution

If a repository gets in a broken state with too much symref nesting,
it cannot be repaired with "git branch -d":

 $ git symbolic-ref refs/heads/nonsense refs/heads/nonsense
 $ git branch -d nonsense
 error: branch 'nonsense' not found.

Worse, "git update-ref --no-deref -d" doesn't work for such repairs
either:

 $ git update-ref -d refs/heads/nonsense
 error: unable to resolve reference refs/heads/nonsense: Too many levels of symbolic links

Fix both by teaching resolve_ref_unsafe a new RESOLVE_REF_NO_RECURSE
flag and passing it when appropriate.

Callers can still read the value of a symref (for example to print a
message about it) with that flag set --- resolve_ref_unsafe will
resolve one level of symrefs and stop there.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Reviewed-by: Ronnie Sahlberg <sahlberg@google.com>
builtin/branch.c
cache.h
refs.c
refs.h
t/t1400-update-ref.sh
t/t3200-branch.sh