Skip to content

Commit 976ee99

Browse files
derrickstoleeGit for Windows Build Agent
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 8587d9a + fa5c1b9 commit 976ee99

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
@@ -3040,9 +3040,7 @@ int is_path_owned_by_current_sid(const char *path)
30403040
DACL_SECURITY_INFORMATION,
30413041
&sid, NULL, NULL, NULL, &descriptor);
30423042

3043-
if (err != ERROR_SUCCESS)
3044-
error(_("failed to get owner for '%s' (%ld)"), path, err);
3045-
else if (sid && IsValidSid(sid)) {
3043+
if (err == ERROR_SUCCESS && sid && IsValidSid(sid)) {
30463044
/* Now, verify that the SID matches the current user's */
30473045
static PSID current_user_sid;
30483046
BOOL is_member;

setup.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
14321432
break;
14331433
case GIT_DIR_INVALID_OWNERSHIP:
14341434
if (!nongit_ok) {
1435+
struct strbuf prequoted = STRBUF_INIT;
14351436
struct strbuf quoted = STRBUF_INIT;
14361437
struct strbuf hint = STRBUF_INIT;
14371438

@@ -1444,7 +1445,14 @@ const char *setup_git_directory_gently(int *nongit_ok)
14441445
"again for more information."));
14451446
#endif
14461447

1447-
sq_quote_buf_pretty(&quoted, dir.buf);
1448+
#ifdef __MINGW32__
1449+
if (dir.buf[0] == '/')
1450+
strbuf_addstr(&prequoted, "%(prefix)/");
1451+
#endif
1452+
1453+
strbuf_add(&prequoted, dir.buf, dir.len);
1454+
sq_quote_buf_pretty(&quoted, prequoted.buf);
1455+
14481456
die(_("detected dubious ownership in repository at '%s'\n"
14491457
"To add an exception for this directory, call:\n"
14501458
"\n"

0 commit comments

Comments
 (0)