@@ -569,13 +569,15 @@ static const char *setup_nongit(const char *cwd, int *nongit_ok)
569
569
return NULL ;
570
570
}
571
571
572
- static dev_t get_device_or_die (const char * path , const char * prefix )
572
+ static dev_t get_device_or_die (const char * path , const char * prefix , int prefix_len )
573
573
{
574
574
struct stat buf ;
575
- if (stat (path , & buf ))
576
- die_errno ("failed to stat '%s%s%s'" ,
575
+ if (stat (path , & buf )) {
576
+ die_errno ("failed to stat '%*s%s%s'" ,
577
+ prefix_len ,
577
578
prefix ? prefix : "" ,
578
579
prefix ? "/" : "" , path );
580
+ }
579
581
return buf .st_dev ;
580
582
}
581
583
@@ -589,7 +591,7 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)
589
591
static char cwd [PATH_MAX + 1 ];
590
592
const char * gitdirenv , * ret ;
591
593
char * gitfile ;
592
- int len , offset , ceil_offset ;
594
+ int len , offset , offset_parent , ceil_offset ;
593
595
dev_t current_device = 0 ;
594
596
int one_filesystem = 1 ;
595
597
@@ -631,7 +633,7 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)
631
633
*/
632
634
one_filesystem = !git_env_bool ("GIT_DISCOVERY_ACROSS_FILESYSTEM" , 0 );
633
635
if (one_filesystem )
634
- current_device = get_device_or_die ("." , NULL );
636
+ current_device = get_device_or_die ("." , NULL , 0 );
635
637
for (;;) {
636
638
gitfile = (char * )read_gitfile (DEFAULT_GIT_DIR_ENVIRONMENT );
637
639
if (gitfile )
@@ -653,11 +655,12 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)
653
655
if (is_git_directory ("." ))
654
656
return setup_bare_git_dir (cwd , offset , len , nongit_ok );
655
657
656
- while (-- offset > ceil_offset && cwd [offset ] != '/' );
657
- if (offset <= ceil_offset )
658
+ offset_parent = offset ;
659
+ while (-- offset_parent > ceil_offset && cwd [offset_parent ] != '/' );
660
+ if (offset_parent <= ceil_offset )
658
661
return setup_nongit (cwd , nongit_ok );
659
662
if (one_filesystem ) {
660
- dev_t parent_device = get_device_or_die (".." , cwd );
663
+ dev_t parent_device = get_device_or_die (".." , cwd , offset );
661
664
if (parent_device != current_device ) {
662
665
if (nongit_ok ) {
663
666
if (chdir (cwd ))
@@ -666,14 +669,15 @@ static const char *setup_git_directory_gently_1(int *nongit_ok)
666
669
return NULL ;
667
670
}
668
671
cwd [offset ] = '\0' ;
669
- die ("Not a git repository (or any parent up to mount parent %s)\n"
672
+ die ("Not a git repository (or any parent up to mount point %s)\n"
670
673
"Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set)." , cwd );
671
674
}
672
675
}
673
676
if (chdir (".." )) {
674
677
cwd [offset ] = '\0' ;
675
678
die_errno ("Cannot change to '%s/..'" , cwd );
676
679
}
680
+ offset = offset_parent ;
677
681
}
678
682
}
679
683
0 commit comments