Home > Net >  git command not returning any value in makefile
git command not returning any value in makefile

Time:01-06

I have a simple makefile that should print git log, which looks as below.

SHELL=/bin/bash

 get_log:
     echo $(git log)

However when I run make get_log nothing is returned, Although if I run git log directly in the CMD I get results. UPDATE: the file is formatted correctly, I am using spaces instead of tabs to post the question here. Do you know what might be the issue here? Thanks in advance.

CodePudding user response:

The error is on your makefile formatting, as per design you have to use tabs indentation so you must precede echo $(git log) by a tab indentation.

CodePudding user response:

The line

 echo $(git log)

has two flaws: it uses a single $ which tells make to look for the contents of the variable git but with an erroneous space and log as addition. I don't think that make would find anything under this ill formed access which means that it silently replaces the expression with ...nothing. Secondly, you don't need the echo as git log is writing to stdout anyway. So the correct form would simply be:

get_log:
   git log

If this is very helpful is another question. I prefer separation of concerns also within scripts - as long as you can't add any benefit like getting the log from the deployment branch or sg. similar, I would stay away from fiddling with git. The user has to learn its basics like log anyway.

PS: I recommend that you read the manual at https://www.gnu.org/software/make/manual/ as you are lacking even the most basic understanding of make (no offense) and it will frustrate you again and again at this point of (lack of) knowledge.

  • Related