Skip to content

Commit c04c5d5

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 70b522e + 3cd95cb commit c04c5d5

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
@@ -3055,9 +3055,7 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report)
30553055
DACL_SECURITY_INFORMATION,
30563056
&sid, NULL, NULL, NULL, &descriptor);
30573057

3058-
if (err != ERROR_SUCCESS)
3059-
error(_("failed to get owner for '%s' (%ld)"), path, err);
3060-
else if (sid && IsValidSid(sid)) {
3058+
if (err == ERROR_SUCCESS && sid && IsValidSid(sid)) {
30613059
/* Now, verify that the SID matches the current user's */
30623060
static PSID current_user_sid;
30633061
BOOL is_member;

setup.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1494,10 +1494,19 @@ const char *setup_git_directory_gently(int *nongit_ok)
14941494
break;
14951495
case GIT_DIR_INVALID_OWNERSHIP:
14961496
if (!nongit_ok) {
1497+
struct strbuf prequoted = STRBUF_INIT;
14971498
struct strbuf quoted = STRBUF_INIT;
14981499

14991500
strbuf_complete(&report, '\n');
1500-
sq_quote_buf_pretty(&quoted, dir.buf);
1501+
1502+
#ifdef __MINGW32__
1503+
if (dir.buf[0] == '/')
1504+
strbuf_addstr(&prequoted, "%(prefix)/");
1505+
#endif
1506+
1507+
strbuf_add(&prequoted, dir.buf, dir.len);
1508+
sq_quote_buf_pretty(&quoted, prequoted.buf);
1509+
15011510
die(_("detected dubious ownership in repository at '%s'\n"
15021511
"%s"
15031512
"To add an exception for this directory, call:\n"

0 commit comments

Comments
 (0)