Skip to content

Commit 4f2a326

Browse files
derrickstoleemjcheetham
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 7d906d0 + 16151ee commit 4f2a326

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

compat/mingw.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3100,9 +3100,7 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report)
31003100
DACL_SECURITY_INFORMATION,
31013101
&sid, NULL, NULL, NULL, &descriptor);
31023102

3103-
if (err != ERROR_SUCCESS)
3104-
error(_("failed to get owner for '%s' (%ld)"), path, err);
3105-
else if (sid && IsValidSid(sid)) {
3103+
if (err == ERROR_SUCCESS && sid && IsValidSid(sid)) {
31063104
/* Now, verify that the SID matches the current user's */
31073105
static PSID current_user_sid;
31083106
BOOL is_member;

setup.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1635,10 +1635,19 @@ const char *setup_git_directory_gently(int *nongit_ok)
16351635
break;
16361636
case GIT_DIR_INVALID_OWNERSHIP:
16371637
if (!nongit_ok) {
1638+
struct strbuf prequoted = STRBUF_INIT;
16381639
struct strbuf quoted = STRBUF_INIT;
16391640

16401641
strbuf_complete(&report, '\n');
1641-
sq_quote_buf_pretty(&quoted, dir.buf);
1642+
1643+
#ifdef __MINGW32__
1644+
if (dir.buf[0] == '/')
1645+
strbuf_addstr(&prequoted, "%(prefix)/");
1646+
#endif
1647+
1648+
strbuf_add(&prequoted, dir.buf, dir.len);
1649+
sq_quote_buf_pretty(&quoted, prequoted.buf);
1650+
16421651
die(_("detected dubious ownership in repository at '%s'\n"
16431652
"%s"
16441653
"To add an exception for this directory, call:\n"

0 commit comments

Comments
 (0)