Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2015-03-03 14:43:17 +0300
committerJunio C Hamano <gitster@pobox.com>2015-03-05 23:35:37 +0300
commit423c688b855c328ecda0b6a79c4b1af78d09a10c (patch)
tree3f39a7af751a345b76e4494c8c95d5fa796e9e6c /refs.c
parent5e6f003ca8aed546d50a4f3fbf1e011186047bc0 (diff)
reflog_expire(): never update a reference to null_sha1
Currently, if --updateref is specified and the very last reflog entry is expired or deleted, the reference's value is set to 0{40}. This is an invalid state of the repository, and breaks, for example, "git fsck" and "git for-each-ref". The only place we use --updateref in our own code is when dropping stash entries. In that code, the very next step is to check if the reflog has been made empty, and if so, delete the "refs/stash" reference entirely. Thus that code path ultimately leaves the repository in a valid state. But we don't want to the repository in an invalid state even temporarily, and we don't want to leave an invalid state if other callers of "git reflog expire|delete --updateref" don't think to do the extra cleanup step. So, if "git reflog expire|delete" leaves no more entries in the reflog, just leave the reference unchanged. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/refs.c b/refs.c
index 4684ffe2a6..05a4be0c06 100644
--- a/refs.c
+++ b/refs.c
@@ -4081,10 +4081,13 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
/*
* It doesn't make sense to adjust a reference pointed
* to by a symbolic ref based on expiring entries in
- * the symbolic reference's reflog.
+ * the symbolic reference's reflog. Nor can we update
+ * a reference if there are no remaining reflog
+ * entries.
*/
int update = (flags & EXPIRE_REFLOGS_UPDATE_REF) &&
- !(type & REF_ISSYMREF);
+ !(type & REF_ISSYMREF) &&
+ !is_null_sha1(cb.last_kept_sha1);
if (close_lock_file(&reflog_lock)) {
status |= error("couldn't write %s: %s", log_file,