My ubuntu's cron runs a PHP script as www-data to collect statistics by executing git diff --shortstat, it has been working for a month or so, however, starting 2 days ago, no results were returned.
After some investigation, I managed to replicated the problem in my CLI. If I run git diff --shortstat, the output is correct, however, running sudo -u www-data git diff --shortstat gives me an error:
warning: Not a git repository. Use --no-index to compare two paths outside a working tree
...I did strace for both commands and found the difference below. For whatever reason, the command that failed decided not to read into .git/commondir
## Not working, geteuid() = 33 due to running `www-data`
newfstatat(AT_FDCWD, "/media/sf_www/stage/package-repo/packages/bilogic/pmake/.git/commondir", 0x7fffe58445a0, AT_SYMLINK_NOFOLLOW) = -1 ENOENT (No such file or directory)
access("/media/sf_www/stage/package-repo/packages/bilogic/pmake/.git/objects", X_OK) = 0
access("/media/sf_www/stage/package-repo/packages/bilogic/pmake/.git/refs", X_OK) = 0
newfstatat(AT_FDCWD, "/media/sf_www/stage/package-repo/packages/bilogic/pmake", {st_mode=S_IFDIR|0770, st_size=4096, ...}, AT_SYMLINK_NOFOLLOW) = 0
geteuid() = 33
access("/etc/gitconfig", R_OK) = -1 ENOENT (No such file or directory)
access("/var/www/.config/git/config", R_OK) = -1 ENOENT (No such file or directory)
access("/var/www/.gitconfig", R_OK) = -1 ENOENT (No such file or directory)
access("/etc/gitconfig", R_OK) = -1 ENOENT (No such file or directory)
access("/var/www/.config/git/config", R_OK) = -1 ENOENT (No such file or directory)
access("/var/www/.gitconfig", R_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=2996, ...}, AT_EMPTY_PATH) = 0
read(3, "# Locale name alias data base.\n#"..., 4096) = 2996
read(3, "", 4096) = 0
close(3) = 0
## Working, geteuid() = 0 due to running as `root`
newfstatat(AT_FDCWD, "/media/sf_www/stage/package-repo/packages/bilogic/pmake/.git/commondir", 0x7ffde3edb890, AT_SYMLINK_NOFOLLOW) = -1 ENOENT (No such file or directory)
access("/media/sf_www/stage/package-repo/packages/bilogic/pmake/.git/objects", X_OK) = 0
access("/media/sf_www/stage/package-repo/packages/bilogic/pmake/.git/refs", X_OK) = 0
newfstatat(AT_FDCWD, "/media/sf_www/stage/package-repo/packages/bilogic/pmake", {st_mode=S_IFDIR|0770, st_size=4096, ...}, AT_SYMLINK_NOFOLLOW) = 0
geteuid() = 0
newfstatat(AT_FDCWD, ".git/commondir", 0x7ffde3edb9a0, AT_SYMLINK_NOFOLLOW) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, ".git/config", O_RDONLY) = 3
newfstatat(3, "", {st_mode=S_IFREG|0770, st_size=285, ...}, AT_EMPTY_PATH) = 0
newfstatat(3, "", {st_mode=S_IFREG|0770, st_size=285, ...}, AT_EMPTY_PATH) = 0
read(3, "[core]\n\trepositoryformatversion "..., 8192) = 285
read(3, "", 8192) = 0
close(3) = 0For further context, these git repos are located on a VirtualBox shared folder. Its owner and group are root:vboxsf, and www-data is a member of the vboxsf group. I do not recall touching any permissions on the system, so it is puzzling why it worked in the past.
I also did some googling which suggested modifying sudoers.d, but did not help, it was still Not a git repository. Any idea what might be the cause of this issue?