@@ -302,6 +302,58 @@ static int add_directory_to_archiver(struct strvec *archiver_args,
302
302
return res ;
303
303
}
304
304
305
+ #ifndef WIN32
306
+ #include <sys/statvfs.h>
307
+ #endif
308
+
309
+ static int get_disk_info (struct strbuf * out )
310
+ {
311
+ #ifdef WIN32
312
+ struct strbuf buf = STRBUF_INIT ;
313
+ char volume_name [MAX_PATH ], fs_name [MAX_PATH ];
314
+ DWORD serial_number , component_length , flags ;
315
+ ULARGE_INTEGER avail2caller , total , avail ;
316
+
317
+ strbuf_realpath (& buf , "." , 1 );
318
+ if (!GetDiskFreeSpaceExA (buf .buf , & avail2caller , & total , & avail )) {
319
+ error (_ ("could not determine free disk size for '%s'" ),
320
+ buf .buf );
321
+ strbuf_release (& buf );
322
+ return -1 ;
323
+ }
324
+
325
+ strbuf_setlen (& buf , offset_1st_component (buf .buf ));
326
+ if (!GetVolumeInformationA (buf .buf , volume_name , sizeof (volume_name ),
327
+ & serial_number , & component_length , & flags ,
328
+ fs_name , sizeof (fs_name ))) {
329
+ error (_ ("could not get info for '%s'" ), buf .buf );
330
+ strbuf_release (& buf );
331
+ return -1 ;
332
+ }
333
+ strbuf_addf (out , "Available space on '%s': " , buf .buf );
334
+ strbuf_humanise_bytes (out , avail2caller .QuadPart );
335
+ strbuf_addch (out , '\n' );
336
+ strbuf_release (& buf );
337
+ #else
338
+ struct strbuf buf = STRBUF_INIT ;
339
+ struct statvfs stat ;
340
+
341
+ strbuf_realpath (& buf , "." , 1 );
342
+ if (statvfs (buf .buf , & stat ) < 0 ) {
343
+ error_errno (_ ("could not determine free disk size for '%s'" ),
344
+ buf .buf );
345
+ strbuf_release (& buf );
346
+ return -1 ;
347
+ }
348
+
349
+ strbuf_addf (out , "Available space on '%s': " , buf .buf );
350
+ strbuf_humanise_bytes (out , st_mult (stat .f_bsize , stat .f_bavail ));
351
+ strbuf_addf (out , " (mount flags 0x%lx)\n" , stat .f_flag );
352
+ strbuf_release (& buf );
353
+ #endif
354
+ return 0 ;
355
+ }
356
+
305
357
/* printf-style interface, expects `<key>=<value>` argument */
306
358
static int set_config (const char * fmt , ...)
307
359
{
@@ -598,6 +650,7 @@ static int cmd_diagnose(int argc, const char **argv)
598
650
get_version_info (& buf , 1 );
599
651
600
652
strbuf_addf (& buf , "Enlistment root: %s\n" , the_repository -> worktree );
653
+ get_disk_info (& buf );
601
654
write_or_die (stdout_fd , buf .buf , buf .len );
602
655
strvec_pushf (& archiver_args ,
603
656
"--add-virtual-file=diagnostics.log:%.*s" ,
0 commit comments