Wednesday, May 22, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 10205  / 3 Years ago, wed, august 25, 2021, 1:06:30
Description:    Ubuntu 22.04.1 LTS
Release: 22.04

I'm trying to cron some git commands under the user www-data and it doesn't work.


To troubleshoot, I tried to run sudo -u www-data git show but it returns fatal: detected dubious ownership in repository


If I run sudo -u www-data git diff --shortstat it returns warning: Not a git repository. Use --no-index to compare two paths outside a working tree


I also tried adding into sudoers


www-data ALL=(ALL) NOPASSWD: /usr/bin/git show

# and also

www-data ALL=(ALL) NOPASSWD: /usr/bin/git

Still getting the same errors. Any ideas why? Thank you.


More From » cron

 Answers
7

Git requires the current user to be the owner of the files, it does not work if current user is a "member" of the group


For .git files belonging to user1:group1



  • Git will not throw error if you are user1

  • Git will throw error if you are user2:group1


Solution 1 (Best)


Since this is automated/cron, it is easier to just prefix the user to run as. Specify the user before the git command


sudo -u <user> git ...


Solution 2


Slighting more cumbersome as you need to add every repository to the user's .gitconfig and there is a very detailed answer here https://stackoverflow.com/a/73100228/3872647


[safe]
directory = <real path of git repository, symlink won't work here>


I hope this is clear enough, otherwise please ask or comment and I will modify this answer.


[#216] Thursday, August 26, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alliulet

Total Points: 46
Total Questions: 109
Total Answers: 97

Location: Svalbard and Jan Mayen
Member since Sat, Oct 10, 2020
4 Years ago
;