Skip to content

Commit 9fd6b51

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 577930b + f90d070 commit 9fd6b51

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

compat/mingw.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3024,9 +3024,7 @@ int is_path_owned_by_current_sid(const char *path)
30243024
DACL_SECURITY_INFORMATION,
30253025
&sid, NULL, NULL, NULL, &descriptor);
30263026

3027-
if (err != ERROR_SUCCESS)
3028-
error(_("failed to get owner for '%s' (%ld)"), path, err);
3029-
else if (sid && IsValidSid(sid)) {
3027+
if (err == ERROR_SUCCESS && sid && IsValidSid(sid)) {
30303028
/* Now, verify that the SID matches the current user's */
30313029
static PSID current_user_sid;
30323030
BOOL is_member;

setup.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1383,9 +1383,17 @@ const char *setup_git_directory_gently(int *nongit_ok)
13831383
break;
13841384
case GIT_DIR_INVALID_OWNERSHIP:
13851385
if (!nongit_ok) {
1386+
struct strbuf prequoted = STRBUF_INIT;
13861387
struct strbuf quoted = STRBUF_INIT;
13871388

1388-
sq_quote_buf_pretty(&quoted, dir.buf);
1389+
#ifdef __MINGW32__
1390+
if (dir.buf[0] == '/')
1391+
strbuf_addstr(&prequoted, "%(prefix)/");
1392+
#endif
1393+
1394+
strbuf_add(&prequoted, dir.buf, dir.len);
1395+
sq_quote_buf_pretty(&quoted, prequoted.buf);
1396+
13891397
die(_("unsafe repository ('%s' is owned by someone else)\n"
13901398
"To add an exception for this directory, call:\n"
13911399
"\n"

0 commit comments

Comments
 (0)