Junio C Hamano  committed fcee5a1

for-each-reflog: fix case for empty log directory

When we remove the last reflog in a directory, opendir() would
succeed and we would iterate over its dirents, expecting retval
to be initialized to zero and setting it to non-zero only upon
seeing an error. If the directory is empty, oops!, we do not
have anybody that touches retval.

The problem is because we initialize retval to errno even on
success from opendir(), which would leave the errno unmolested.

Signed-off-by: Junio C Hamano <>

  • Participants
  • Parent commits 302da67

Comments (0)

Files changed (1)

 static int do_for_each_reflog(const char *base, each_ref_fn fn, void *cb_data)
 	DIR *dir = opendir(git_path("logs/%s", base));
-	int retval = errno;
+	int retval = 0;
 	if (dir) {
 		struct dirent *de;
+	else
+		return errno;
 	return retval;