@@ -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 );
@@ -1271,10 +1273,11 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
1271
1273
strbuf_setlen (dir , offset );
1272
1274
if (gitdirenv ) {
1273
1275
enum discovery_result ret ;
1276
+ const char * gitdir_candidate =
1277
+ gitdir_path ? gitdir_path : gitdirenv ;
1274
1278
1275
- if (ensure_valid_ownership (gitfile ,
1276
- dir -> buf ,
1277
- (gitdir_path ? gitdir_path : gitdirenv ))) {
1279
+ if (ensure_valid_ownership (gitfile , dir -> buf ,
1280
+ gitdir_candidate , report )) {
1278
1281
strbuf_addstr (gitdir , gitdirenv );
1279
1282
ret = GIT_DIR_DISCOVERED ;
1280
1283
} else
@@ -1297,7 +1300,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
1297
1300
}
1298
1301
1299
1302
if (is_git_directory (dir -> buf )) {
1300
- if (!ensure_valid_ownership (NULL , NULL , dir -> buf ))
1303
+ if (!ensure_valid_ownership (NULL , NULL , dir -> buf , report ))
1301
1304
return GIT_DIR_INVALID_OWNERSHIP ;
1302
1305
strbuf_addstr (gitdir , "." );
1303
1306
return GIT_DIR_BARE ;
@@ -1330,7 +1333,7 @@ int discover_git_directory(struct strbuf *commondir,
1330
1333
return -1 ;
1331
1334
1332
1335
cwd_len = dir .len ;
1333
- if (setup_git_directory_gently_1 (& dir , gitdir , 0 ) <= 0 ) {
1336
+ if (setup_git_directory_gently_1 (& dir , gitdir , NULL , 0 ) <= 0 ) {
1334
1337
strbuf_release (& dir );
1335
1338
return -1 ;
1336
1339
}
@@ -1377,7 +1380,7 @@ int discover_git_directory(struct strbuf *commondir,
1377
1380
const char * setup_git_directory_gently (int * nongit_ok )
1378
1381
{
1379
1382
static struct strbuf cwd = STRBUF_INIT ;
1380
- struct strbuf dir = STRBUF_INIT , gitdir = STRBUF_INIT ;
1383
+ struct strbuf dir = STRBUF_INIT , gitdir = STRBUF_INIT , report = STRBUF_INIT ;
1381
1384
const char * prefix = NULL ;
1382
1385
struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT ;
1383
1386
@@ -1402,7 +1405,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
1402
1405
die_errno (_ ("Unable to read current working directory" ));
1403
1406
strbuf_addbuf (& dir , & cwd );
1404
1407
1405
- switch (setup_git_directory_gently_1 (& dir , & gitdir , 1 )) {
1408
+ switch (setup_git_directory_gently_1 (& dir , & gitdir , & report , 1 )) {
1406
1409
case GIT_DIR_EXPLICIT :
1407
1410
prefix = setup_explicit_git_dir (gitdir .buf , & cwd , & repo_fmt , nongit_ok );
1408
1411
break ;
@@ -1434,12 +1437,14 @@ const char *setup_git_directory_gently(int *nongit_ok)
1434
1437
if (!nongit_ok ) {
1435
1438
struct strbuf quoted = STRBUF_INIT ;
1436
1439
1440
+ strbuf_complete (& report , '\n' );
1437
1441
sq_quote_buf_pretty (& quoted , dir .buf );
1438
1442
die (_ ("detected dubious ownership in repository at '%s'\n"
1443
+ "%s"
1439
1444
"To add an exception for this directory, call:\n"
1440
1445
"\n"
1441
1446
"\tgit config --global --add safe.directory %s" ),
1442
- dir .buf , quoted .buf );
1447
+ dir .buf , report . buf , quoted .buf );
1443
1448
}
1444
1449
* nongit_ok = 1 ;
1445
1450
break ;
@@ -1518,6 +1523,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
1518
1523
1519
1524
strbuf_release (& dir );
1520
1525
strbuf_release (& gitdir );
1526
+ strbuf_release (& report );
1521
1527
clear_repository_format (& repo_fmt );
1522
1528
1523
1529
return prefix ;
0 commit comments