diff options
author | Josh Bleecher Snyder <josharian@gmail.com> | 2020-01-15 13:31:21 -0800 |
---|---|---|
committer | Josh Bleecher Snyder <josharian@gmail.com> | 2020-01-15 13:55:58 -0800 |
commit | 852c83ee44d6d53137f12443c9f82f70bbabbadc (patch) | |
tree | a17c19b32b4252160e885020d1a67b0f604d25ed /src/refs.c | |
parent | dea5ce3df6f62a490b3307edd06958eddc5e90f4 (diff) | |
download | libgit2-852c83ee44d6d53137f12443c9f82f70bbabbadc.tar.gz |
refs: refuse to delete HEAD
This requires adding a new symbolic ref to the testrepo fixture.
Some of the existing tests attempt to delete HEAD, expecting a different failure. Introduce and use a non-HEAD symbolic ref instead.
Adjust a few other tests as needed.
Fixes #5357
Diffstat (limited to 'src/refs.c')
-rw-r--r-- | src/refs.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/refs.c b/src/refs.c index 29dd1bdeb..633d83abd 100644 --- a/src/refs.c +++ b/src/refs.c @@ -145,6 +145,11 @@ int git_reference_delete(git_reference *ref) const git_oid *old_id = NULL; const char *old_target = NULL; + if (!strcmp(ref->name, "HEAD")) { + git_error_set(GIT_ERROR_REFERENCE, "cannot delete HEAD"); + return GIT_ERROR; + } + if (ref->type == GIT_REFERENCE_DIRECT) old_id = &ref->target.oid; else |