@@ -1138,16 +1138,17 @@ static int safe_directory_cb(const char *key, const char *value, void *d)
1138
1138
* added, for bare ones their git directory.
1139
1139
*/
1140
1140
static int ensure_valid_ownership (const char * gitfile ,
1141
- const char * worktree , const char * gitdir )
1141
+ const char * worktree , const char * gitdir ,
1142
+ struct strbuf * report )
1142
1143
{
1143
1144
struct safe_directory_data data = {
1144
1145
.path = worktree ? worktree : gitdir
1145
1146
};
1146
1147
1147
1148
if (!git_env_bool ("GIT_TEST_ASSUME_DIFFERENT_OWNER" , 0 ) &&
1148
- (!gitfile || is_path_owned_by_current_user (gitfile )) &&
1149
- (!worktree || is_path_owned_by_current_user (worktree )) &&
1150
- (!gitdir || is_path_owned_by_current_user (gitdir )))
1149
+ (!gitfile || is_path_owned_by_current_user (gitfile , report )) &&
1150
+ (!worktree || is_path_owned_by_current_user (worktree , report )) &&
1151
+ (!gitdir || is_path_owned_by_current_user (gitdir , report )))
1151
1152
return 1 ;
1152
1153
1153
1154
/*
@@ -1187,6 +1188,7 @@ enum discovery_result {
1187
1188
*/
1188
1189
static enum discovery_result setup_git_directory_gently_1 (struct strbuf * dir ,
1189
1190
struct strbuf * gitdir ,
1191
+ struct strbuf * report ,
1190
1192
int die_on_error )
1191
1193
{
1192
1194
const char * env_ceiling_dirs = getenv (CEILING_DIRECTORIES_ENVIRONMENT );
@@ -1275,7 +1277,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
1275
1277
gitdir_path ? gitdir_path : gitdirenv ;
1276
1278
1277
1279
if (ensure_valid_ownership (gitfile , dir -> buf ,
1278
- gitdir_candidate )) {
1280
+ gitdir_candidate , report )) {
1279
1281
strbuf_addstr (gitdir , gitdirenv );
1280
1282
ret = GIT_DIR_DISCOVERED ;
1281
1283
} else
@@ -1298,7 +1300,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
1298
1300
}
1299
1301
1300
1302
if (is_git_directory (dir -> buf )) {
1301
- if (!ensure_valid_ownership (NULL , NULL , dir -> buf ))
1303
+ if (!ensure_valid_ownership (NULL , NULL , dir -> buf , report ))
1302
1304
return GIT_DIR_INVALID_OWNERSHIP ;
1303
1305
strbuf_addstr (gitdir , "." );
1304
1306
return GIT_DIR_BARE ;
@@ -1331,7 +1333,7 @@ int discover_git_directory(struct strbuf *commondir,
1331
1333
return -1 ;
1332
1334
1333
1335
cwd_len = dir .len ;
1334
- if (setup_git_directory_gently_1 (& dir , gitdir , 0 ) <= 0 ) {
1336
+ if (setup_git_directory_gently_1 (& dir , gitdir , NULL , 0 ) <= 0 ) {
1335
1337
strbuf_release (& dir );
1336
1338
return -1 ;
1337
1339
}
@@ -1378,7 +1380,7 @@ int discover_git_directory(struct strbuf *commondir,
1378
1380
const char * setup_git_directory_gently (int * nongit_ok )
1379
1381
{
1380
1382
static struct strbuf cwd = STRBUF_INIT ;
1381
- struct strbuf dir = STRBUF_INIT , gitdir = STRBUF_INIT ;
1383
+ struct strbuf dir = STRBUF_INIT , gitdir = STRBUF_INIT , report = STRBUF_INIT ;
1382
1384
const char * prefix = NULL ;
1383
1385
struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT ;
1384
1386
@@ -1403,7 +1405,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
1403
1405
die_errno (_ ("Unable to read current working directory" ));
1404
1406
strbuf_addbuf (& dir , & cwd );
1405
1407
1406
- switch (setup_git_directory_gently_1 (& dir , & gitdir , 1 )) {
1408
+ switch (setup_git_directory_gently_1 (& dir , & gitdir , & report , 1 )) {
1407
1409
case GIT_DIR_EXPLICIT :
1408
1410
prefix = setup_explicit_git_dir (gitdir .buf , & cwd , & repo_fmt , nongit_ok );
1409
1411
break ;
@@ -1435,12 +1437,14 @@ const char *setup_git_directory_gently(int *nongit_ok)
1435
1437
if (!nongit_ok ) {
1436
1438
struct strbuf quoted = STRBUF_INIT ;
1437
1439
1440
+ strbuf_complete (& report , '\n' );
1438
1441
sq_quote_buf_pretty (& quoted , dir .buf );
1439
1442
die (_ ("detected dubious ownership in repository at '%s'\n"
1443
+ "%s"
1440
1444
"To add an exception for this directory, call:\n"
1441
1445
"\n"
1442
1446
"\tgit config --global --add safe.directory %s" ),
1443
- dir .buf , quoted .buf );
1447
+ dir .buf , report . buf , quoted .buf );
1444
1448
}
1445
1449
* nongit_ok = 1 ;
1446
1450
break ;
@@ -1519,6 +1523,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
1519
1523
1520
1524
strbuf_release (& dir );
1521
1525
strbuf_release (& gitdir );
1526
+ strbuf_release (& report );
1522
1527
clear_repository_format (& repo_fmt );
1523
1528
1524
1529
return prefix ;
0 commit comments