Skip to content

Commit 6c07169

Browse files
committed
Allow debugging unsafe directories' ownership
When Git refuses to use an existing repository because it is owned by someone else than the current user, it can be a bit tricky on Windows to figure out what is going on. Let's help with that by offering some more information via the environment variable `GIT_TEST_DEBUG_UNSAFE_DIRECTORIES`. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 7068801 commit 6c07169

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Documentation/config/safe.txt

+6
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ line option `-c safe.directory=<path>`.
1919
The value of this setting is interpolated, i.e. `~/<path>` expands to a
2020
path relative to the home directory and `%(prefix)/<path>` expands to a
2121
path relative to Git's (runtime) prefix.
22+
+
23+
Due to the permission model on Windows where ACLs are used instead of
24+
Unix' simpler permission model, it can be a bit tricky to figure out why
25+
a directory is considered unsafe. To help with this, Git will provide
26+
more detailed information when the environment variable
27+
`GIT_TEST_DEBUG_UNSAFE_DIRECTORIES` is set to `true`.

compat/mingw.c

+21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "../git-compat-util.h"
22
#include "win32.h"
33
#include <aclapi.h>
4+
#include <sddl.h>
45
#include <conio.h>
56
#include <wchar.h>
67
#include <winioctl.h>
@@ -3506,6 +3507,26 @@ int is_path_owned_by_current_sid(const char *path)
35063507
IsValidSid(current_user_sid) &&
35073508
EqualSid(sid, current_user_sid))
35083509
result = 1;
3510+
else if (git_env_bool("GIT_TEST_DEBUG_UNSAFE_DIRECTORIES", 0)) {
3511+
LPSTR str1, str2, to_free1 = NULL, to_free2 = NULL;
3512+
3513+
if (ConvertSidToStringSidA(sid, &str1))
3514+
to_free1 = str1;
3515+
else
3516+
str1 = "(inconvertible)";
3517+
3518+
if (!current_user_sid)
3519+
str2 = "(none)";
3520+
else if (!IsValidSid(current_user_sid))
3521+
str2 = "(invalid)";
3522+
else if (ConvertSidToStringSidA(current_user_sid, &str2))
3523+
to_free2 = str2;
3524+
else
3525+
str2 = "(inconvertible)";
3526+
warning("'%s' is owned by:\n\t'%s'\nbut the current user is:\n\t'%s'", path, str1, str2);
3527+
LocalFree(to_free1);
3528+
LocalFree(to_free2);
3529+
}
35093530
}
35103531

35113532
/*

0 commit comments

Comments
 (0)