Skip to content

Commit 423c688

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]> Reviewed-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5e6f003 commit 423c688

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

refs.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4081,10 +4081,13 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
40814081
/*
40824082
* It doesn't make sense to adjust a reference pointed
40834083
* to by a symbolic ref based on expiring entries in
4084-
* the symbolic reference's reflog.
4084+
* the symbolic reference's reflog. Nor can we update
4085+
* a reference if there are no remaining reflog
4086+
* entries.
40854087
*/
40864088
int update = (flags & EXPIRE_REFLOGS_UPDATE_REF) &&
4087-
!(type & REF_ISSYMREF);
4089+
!(type & REF_ISSYMREF) &&
4090+
!is_null_sha1(cb.last_kept_sha1);
40884091

40894092
if (close_lock_file(&reflog_lock)) {
40904093
status |= error("couldn't write %s: %s", log_file,

0 commit comments

Comments
 (0)