Skip to content

Commit 8acb700

Browse files
derrickstoleedscho
authored andcommitted
Merge pull request #3791: Various fixes around safe.directory
The first three commits are rebased versions of those in gitgitgadget#1215. These allow the following: 1. Fix `git config --global foo.bar <path>` from allowing the `<path>`. As a bonus, users with a config value starting with `/` will not get a warning about "old-style" paths needing a "`%(prefix)/`". 2. When in WSL, the path starts with `/` so it needs to be interpolated properly. Update the warning to include `%(prefix)/` to get the right value for WSL users. (This is specifically for using Git for Windows from Git Bash, but in a WSL directory.) 3. When using WSL, the ownership check fails and reports an error message. This is noisy, and happens even if the user has marked the path with `safe.directory`. Remove that error message.
2 parents 4481665 + b75400e commit 8acb700

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

compat/mingw.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -3509,9 +3509,7 @@ int is_path_owned_by_current_sid(const char *path)
35093509
DACL_SECURITY_INFORMATION,
35103510
&sid, NULL, NULL, NULL, &descriptor);
35113511

3512-
if (err != ERROR_SUCCESS)
3513-
error(_("failed to get owner for '%s' (%ld)"), path, err);
3514-
else if (sid && IsValidSid(sid)) {
3512+
if (err == ERROR_SUCCESS && sid && IsValidSid(sid)) {
35153513
/* Now, verify that the SID matches the current user's */
35163514
static PSID current_user_sid;
35173515
BOOL is_member;

setup.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -1374,9 +1374,17 @@ const char *setup_git_directory_gently(int *nongit_ok)
13741374
break;
13751375
case GIT_DIR_INVALID_OWNERSHIP:
13761376
if (!nongit_ok) {
1377+
struct strbuf prequoted = STRBUF_INIT;
13771378
struct strbuf quoted = STRBUF_INIT;
13781379

1379-
sq_quote_buf_pretty(&quoted, dir.buf);
1380+
#ifdef __MINGW32__
1381+
if (dir.buf[0] == '/')
1382+
strbuf_addstr(&prequoted, "%(prefix)/");
1383+
#endif
1384+
1385+
strbuf_add(&prequoted, dir.buf, dir.len);
1386+
sq_quote_buf_pretty(&quoted, prequoted.buf);
1387+
13801388
die(_("unsafe repository ('%s' is owned by someone else)\n"
13811389
"To add an exception for this directory, call:\n"
13821390
"\n"

0 commit comments

Comments
 (0)