Search code examples
gitmakefilepermissions

Permission error running any git command in makefiles


I've been slowly going insane from a recurring permission error encountered when running any git command within any makefile:

for instance running make against:

a:
    git --version

will result in:

make: git: Permission denied
make: *** [makefile:<line number>: <target>] Error 127 

Observations:

  • occurs for even the most trivial of commands, e.g. git status
  • occurs when running as root
  • occurs regardless of directory and file permissions
  • the given command runs without issue if run directly
  • after reformatting and reinstalling my OS the problem went away but has resurfaced after a few months
  • BSD bmake seems to work okay

Environment:

  • Arch Linux x86-64
  • GNU Make v4.3
  • Git v2.26.2

I use makefiles extensively at work and this problem has slowly become more and more frustrating. If anyone has any insights or suggestions on how to fix this issue it would be greatly appreciated. Thank you.


Solution

  • It would be really, really helpful if you provided the recipe you're trying to run that's giving the above error, or even the make output of the command that was invoked. Without that we can only guess, which is kind of a waste of everyone's time :)

    My suspicion is this: you have a directory on your $PATH which has a directory named git in it, and this appears before /usr/bin in your $PATH.

    There's a bug in GNU make 4.3 (actually the bug was in gnulib, which GNU make uses) which didn't correctly ignore directories when searching PATH.

    However, this cannot be the problem if your recipe invokes git in a non-trivial way (as part of a shell script).

    The fastest way to check this is just to add a semicolon to your command line; you didn't show us the entire recipe so we can't be sure but if you have:

    foo:
            git --version
    

    try changing this to:

    foo:
            git --version;
    

    and see if it works.