@@ -1142,16 +1142,17 @@ static int safe_directory_cb(const char *key, const char *value, void *d)
1142
1142
* added, for bare ones their git directory.
1143
1143
*/
1144
1144
static int ensure_valid_ownership (const char * gitfile ,
1145
- const char * worktree , const char * gitdir )
1145
+ const char * worktree , const char * gitdir ,
1146
+ struct strbuf * report )
1146
1147
{
1147
1148
struct safe_directory_data data = {
1148
1149
.path = worktree ? worktree : gitdir
1149
1150
};
1150
1151
1151
1152
if (!git_env_bool ("GIT_TEST_ASSUME_DIFFERENT_OWNER" , 0 ) &&
1152
- (!gitfile || is_path_owned_by_current_user (gitfile )) &&
1153
- (!worktree || is_path_owned_by_current_user (worktree )) &&
1154
- (!gitdir || is_path_owned_by_current_user (gitdir )))
1153
+ (!gitfile || is_path_owned_by_current_user (gitfile , report )) &&
1154
+ (!worktree || is_path_owned_by_current_user (worktree , report )) &&
1155
+ (!gitdir || is_path_owned_by_current_user (gitdir , report )))
1155
1156
return 1 ;
1156
1157
1157
1158
/*
@@ -1232,6 +1233,7 @@ enum discovery_result {
1232
1233
*/
1233
1234
static enum discovery_result setup_git_directory_gently_1 (struct strbuf * dir ,
1234
1235
struct strbuf * gitdir ,
1236
+ struct strbuf * report ,
1235
1237
int die_on_error )
1236
1238
{
1237
1239
const char * env_ceiling_dirs = getenv (CEILING_DIRECTORIES_ENVIRONMENT );
@@ -1316,10 +1318,11 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
1316
1318
strbuf_setlen (dir , offset );
1317
1319
if (gitdirenv ) {
1318
1320
enum discovery_result ret ;
1321
+ const char * gitdir_candidate =
1322
+ gitdir_path ? gitdir_path : gitdirenv ;
1319
1323
1320
- if (ensure_valid_ownership (gitfile ,
1321
- dir -> buf ,
1322
- (gitdir_path ? gitdir_path : gitdirenv ))) {
1324
+ if (ensure_valid_ownership (gitfile , dir -> buf ,
1325
+ gitdir_candidate , report )) {
1323
1326
strbuf_addstr (gitdir , gitdirenv );
1324
1327
ret = GIT_DIR_DISCOVERED ;
1325
1328
} else
@@ -1344,7 +1347,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
1344
1347
if (is_git_directory (dir -> buf )) {
1345
1348
if (get_allowed_bare_repo () == ALLOWED_BARE_REPO_EXPLICIT )
1346
1349
return GIT_DIR_DISALLOWED_BARE ;
1347
- if (!ensure_valid_ownership (NULL , NULL , dir -> buf ))
1350
+ if (!ensure_valid_ownership (NULL , NULL , dir -> buf , report ))
1348
1351
return GIT_DIR_INVALID_OWNERSHIP ;
1349
1352
strbuf_addstr (gitdir , "." );
1350
1353
return GIT_DIR_BARE ;
@@ -1377,7 +1380,7 @@ int discover_git_directory(struct strbuf *commondir,
1377
1380
return -1 ;
1378
1381
1379
1382
cwd_len = dir .len ;
1380
- if (setup_git_directory_gently_1 (& dir , gitdir , 0 ) <= 0 ) {
1383
+ if (setup_git_directory_gently_1 (& dir , gitdir , NULL , 0 ) <= 0 ) {
1381
1384
strbuf_release (& dir );
1382
1385
return -1 ;
1383
1386
}
@@ -1424,7 +1427,7 @@ int discover_git_directory(struct strbuf *commondir,
1424
1427
const char * setup_git_directory_gently (int * nongit_ok )
1425
1428
{
1426
1429
static struct strbuf cwd = STRBUF_INIT ;
1427
- struct strbuf dir = STRBUF_INIT , gitdir = STRBUF_INIT ;
1430
+ struct strbuf dir = STRBUF_INIT , gitdir = STRBUF_INIT , report = STRBUF_INIT ;
1428
1431
const char * prefix = NULL ;
1429
1432
struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT ;
1430
1433
@@ -1449,7 +1452,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
1449
1452
die_errno (_ ("Unable to read current working directory" ));
1450
1453
strbuf_addbuf (& dir , & cwd );
1451
1454
1452
- switch (setup_git_directory_gently_1 (& dir , & gitdir , 1 )) {
1455
+ switch (setup_git_directory_gently_1 (& dir , & gitdir , & report , 1 )) {
1453
1456
case GIT_DIR_EXPLICIT :
1454
1457
prefix = setup_explicit_git_dir (gitdir .buf , & cwd , & repo_fmt , nongit_ok );
1455
1458
break ;
@@ -1481,12 +1484,14 @@ const char *setup_git_directory_gently(int *nongit_ok)
1481
1484
if (!nongit_ok ) {
1482
1485
struct strbuf quoted = STRBUF_INIT ;
1483
1486
1487
+ strbuf_complete (& report , '\n' );
1484
1488
sq_quote_buf_pretty (& quoted , dir .buf );
1485
1489
die (_ ("detected dubious ownership in repository at '%s'\n"
1490
+ "%s"
1486
1491
"To add an exception for this directory, call:\n"
1487
1492
"\n"
1488
1493
"\tgit config --global --add safe.directory %s" ),
1489
- dir .buf , quoted .buf );
1494
+ dir .buf , report . buf , quoted .buf );
1490
1495
}
1491
1496
* nongit_ok = 1 ;
1492
1497
break ;
@@ -1573,6 +1578,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
1573
1578
1574
1579
strbuf_release (& dir );
1575
1580
strbuf_release (& gitdir );
1581
+ strbuf_release (& report );
1576
1582
clear_repository_format (& repo_fmt );
1577
1583
1578
1584
return prefix ;
0 commit comments