A make all clones the git repo. I want to know what the commit hash is and assign the git commit hash to a variable which can be used later in the Makefile
e.g.
all: download
echo '$(GIT_COMMIT)'
download:
cd buildarea && git clone [email protected]:proj/project.git
$(eval GIT_COMMIT = $(shell cd buildarea/project && git log -l --pretty=format:"%H"))
echo '$(GIT_COMMIT)'
The long string following the word commit is called the commit hash.
The commit hash by hashing the data you see with cat-file . This includes the tree object hash and commit information like author, time, commit message, and the parent commit hash if it's not the first commit.
How about use shell function and 2 targets for it?
all: download getver
getver: VER=$(shell cd buildarea/project && git log -1 --pretty=format:"%H")
getver:
@echo GIT_COMMIT=$(VER)
download:
mkdir -p buildarea && cd buildarea && [email protected]:proj/project.git
Because of the way that make evaluates the target the git clone
executes after $(shell)
, so cd
tries to move to a directory that doesn't exist yet. What you can do is simply perform the whole act in a single $(shell)
call.
all: download
echo '$(GIT_COMMIT)'
download:
$(eval GIT_COMMIT = $(shell git clone [email protected]:proj/project.git buildarea/project && cd buildarea/project && git rev-parse HEAD))
echo '$(GIT_COMMIT)'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With